2

I'm trying to create a Matplotlib graph that shows Bollinger Bands and price graph of cryptocurrency pairs on the Poloniex Exchange. The bands seem to work when I fetch data for the BTC/ETH pair but not for less active pairs such as BTC/BURST.

Here is a graph of the 30 minute candles for BTC/ETH BTC/ETH

And here is a graph of 30 minute candles for BTC/BURST BTC/BURST

It appears that the standard deviation for the BTC/ETH pair is calculated correctly and the bands are shown but the standard deviation of the BTC/BURST pair is always zero so the bands are drawn on top of the 10 day SMA.

Here is my code

import API
import numpy as np
from talib.abstract import *
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick2_ohlc
import time
from pprint import pprint

key = 'keyHere'
secret = 'secretHere'
api = API.poloniex(key, secret)

pair = "BTC_BURST"
interval = 1800  # 30 mins
steps = 336      # 1 week
startTime = int(time.time()) - steps * interval
stopTime = int(time.time())

print 'fetching', steps, 'candles from server'
fetchStart = time.time()
data = api.api_query('returnChartData', {"currencyPair": pair, "period": interval,
                                         "start": startTime, "end": stopTime})
print 'fetched', len(data['candleStick']), 'candles in', time.time() - fetchStart, 'seconds'
pprint(data)

inputs = {
    'open': np.empty(steps),
    'high': np.empty(steps),
    'low': np.empty(steps),
    'close': np.empty(steps),
    'volume': np.empty(steps)
}
for x in range(0, steps):
    candle = data['candleStick'][x]
    inputs['open'][x] = candle['open']
    inputs['high'][x] = candle['high']
    inputs['low'][x] = candle['low']
    inputs['close'][x] = candle['close']
    inputs['volume'][x] = candle['volume']
pprint(STDDEV(inputs, timeperiod=10, nbdev=2))

upper, middle, lower = BBANDS(inputs, timeperiod=10, nbdevup=2, nbdevdn=2)
# pprint(upper)
# pprint(middle)
# pprint(lower)

candlestick2_ohlc(plt.gca(), inputs['open'], inputs['high'],
                  inputs['low'], inputs['close'], width=0.8)
plt.plot(upper)
plt.plot(middle)
plt.plot(lower)
plt.show()

IS this issue due to there being a higher volume on the BTC/ETH pair? Any help is greatly appreciated.

Matt Mohandiss
  • 145
  • 2
  • 10
  • I don't know python and worked with c++ ta-lib API. Both STDDEV and BBANDS are expecting an array of double as input data. For example, array of prices or close prices or open prices. Not a matrix of ohlcv encoded candles. I believe the same in python API wrapper. So I wonder what you are passing to these functions as input data? – truf Jul 05 '17 at 18:14
  • The documentation for the Python wrapper said to use a dictionary that contained numpy arrays of double values so I don't think that's the problem. What I discovered is that the Bollinger Bands work if I multiply my data values by a few orders of magnitude. My guess is that the values of the BTC/BURST pair are too small which causes the standard deviation to be rounded to zero. I'll keep digging and see if I can find a solution. – Matt Mohandiss Jul 06 '17 at 21:42
  • hey @MatthewMohandiss have you found any solution for this? – born to hula Dec 30 '17 at 21:14
  • @borntohula I never found a solution for this. I decided it would be more practical for my application if I used a conversion factor (mBTC) when displaying the charts like I tried in my original post. – Matt Mohandiss Jan 09 '18 at 01:29

0 Answers0