BBANDS
upperband, middleband, lowerband = BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)
Plot
Working Example
from cloudquant.interfaces import Strategy
from collections import OrderedDict
import ktgfunc
import talib
class WE_BBANDS(Strategy):
def on_start(self, md, order, service, account):
# symbol and timestamp
print(self.symbol + ": " + service.time_to_string(service.system_time))
daily_bars = md.bar.daily(start=-100)
close = daily_bars.close
upperband, middleband, lowerband = talib.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)
# get the date values
dates = service._context.market._storage.market_hours.keys()
dateList = []
for date in dates:
dateList.append(str(date.strftime('%Y-%m-%d')))
dates = sorted(dateList, reverse=True)[1:101]
dates.sort()
dict = OrderedDict()
dict['date'] = dates
dict['close'] = close
dict['upperband'] = upperband
dict['middleband'] = middleband
dict['lowerband'] = lowerband
symbol = 'BBANDS: ' + self.symbol
print ktgfunc.talib_table(symbol, 3, dict)
Console
MSFT: 2017-02-09 09:30:00.000000
BBANDS: MSFT | ||||
---|---|---|---|---|
Input | Output | |||
date | close | upperband | middleband | lowerband |
2016-09-16 | 56.87 | nan | nan | nan |
2016-09-19 | 56.55 | nan | nan | nan |
2016-09-20 | 56.43 | nan | nan | nan |
2016-09-21 | 57.37 | nan | nan | nan |
2016-09-22 | 57.43 | 57.75 | 56.93 | 56.11 |
2016-09-23 | 57.04 | 57.79 | 56.97 | 56.14 |
2016-09-26 | 56.52 | 57.80 | 56.96 | 56.12 |
2016-09-27 | 57.56 | 57.94 | 57.19 | 56.44 |
2016-09-28 | 57.64 | 58.07 | 57.24 | 56.41 |
2016-09-29 | 57.01 | 57.97 | 57.16 | 56.34 |
2016-09-30 | 57.21 | 58.00 | 57.19 | 56.38 |
2016-10-03 | 57.03 | 57.82 | 57.29 | 56.77 |
2016-10-04 | 56.86 | 57.69 | 57.15 | 56.61 |
2016-10-05 | 57.25 | 57.36 | 57.07 | 56.79 |
2016-10-06 | 57.35 | 57.49 | 57.14 | 56.79 |
2016-10-07 | 57.41 | 57.60 | 57.18 | 56.77 |
2016-10-10 | 57.65 | 57.82 | 57.30 | 56.79 |
2016-10-11 | 56.81 | 57.85 | 57.29 | 56.74 |
2016-10-12 | 56.73 | 57.91 | 57.19 | 56.47 |
2016-10-13 | 56.54 | 57.88 | 57.03 | 56.17 |
2016-10-14 | 57.03 | 57.72 | 56.95 | 56.18 |
2016-10-17 | 56.84 | 57.11 | 56.79 | 56.47 |
2016-10-18 | 57.27 | 57.39 | 56.88 | 56.38 |
2016-10-19 | 57.14 | 57.48 | 56.97 | 56.45 |
2016-10-20 | 56.87 | 57.36 | 57.03 | 56.70 |
2016-10-21 | 59.26 | 59.29 | 57.48 | 55.66 |
2016-10-24 | 60.59 | 61.14 | 58.23 | 55.32 |
2016-10-25 | 60.58 | 62.12 | 58.89 | 55.66 |
2016-10-26 | 60.22 | 62.32 | 59.50 | 56.69 |
2016-10-27 | 59.70 | 61.11 | 60.07 | 59.03 |
2016-10-28 | 59.47 | 61.03 | 60.11 | 59.20 |
2016-10-31 | 59.52 | 60.77 | 59.90 | 59.03 |
2016-11-01 | 59.40 | 60.26 | 59.66 | 59.07 |
2016-11-02 | 59.03 | 59.86 | 59.42 | 58.98 |
2016-11-03 | 58.81 | 59.80 | 59.25 | 58.69 |
2016-11-04 | 58.32 | 59.88 | 59.02 | 58.15 |
2016-11-07 | 60.01 | 60.26 | 59.11 | 57.97 |
2016-11-08 | 60.06 | 60.62 | 59.25 | 57.87 |
2016-11-09 | 59.77 | 60.80 | 59.39 | 57.99 |
2016-11-10 | 58.31 | 60.91 | 59.29 | 57.68 |
2016-11-11 | 58.62 | 60.84 | 59.36 | 57.87 |
2016-11-14 | 57.73 | 60.67 | 58.90 | 57.13 |
2016-11-15 | 58.87 | 60.00 | 58.66 | 57.31 |
2016-11-16 | 59.65 | 59.90 | 58.64 | 57.37 |
2016-11-17 | 60.64 | 61.07 | 59.10 | 57.14 |
2016-11-18 | 60.35 | 61.56 | 59.45 | 57.34 |
2016-11-21 | 60.86 | 61.53 | 60.07 | 58.62 |
2016-11-22 | 61.12 | 61.53 | 60.52 | 59.51 |
2016-11-23 | 60.40 | 61.25 | 60.67 | 60.10 |
2016-11-25 | 60.53 | 61.24 | 60.65 | 60.06 |
2016-11-28 | 60.61 | 61.22 | 60.70 | 60.19 |
2016-11-29 | 61.09 | 61.35 | 60.75 | 60.15 |
2016-11-30 | 60.26 | 61.14 | 60.58 | 60.01 |
2016-12-01 | 59.20 | 61.60 | 60.34 | 59.08 |
2016-12-02 | 59.25 | 61.58 | 60.08 | 58.59 |
2016-12-05 | 60.22 | 61.42 | 60.00 | 58.59 |
2016-12-06 | 59.95 | 60.70 | 59.78 | 58.85 |
2016-12-07 | 61.37 | 61.58 | 60.00 | 58.42 |
2016-12-08 | 61.01 | 61.87 | 60.36 | 58.85 |
2016-12-09 | 61.97 | 62.39 | 60.90 | 59.42 |
2016-12-12 | 62.17 | 62.87 | 61.29 | 59.71 |
2016-12-13 | 62.98 | 63.26 | 61.90 | 60.54 |
2016-12-14 | 62.68 | 63.52 | 62.16 | 60.81 |
2016-12-15 | 62.58 | 63.20 | 62.48 | 61.75 |
2016-12-16 | 62.30 | 63.11 | 62.54 | 61.97 |
2016-12-19 | 63.62 | 63.73 | 62.83 | 61.93 |
2016-12-20 | 63.54 | 64.01 | 62.94 | 61.87 |
2016-12-21 | 63.54 | 64.24 | 63.12 | 62.00 |
2016-12-22 | 63.55 | 64.32 | 63.31 | 62.30 |
2016-12-23 | 63.24 | 63.76 | 63.50 | 63.23 |
2016-12-27 | 63.28 | 63.71 | 63.43 | 63.15 |
2016-12-28 | 62.99 | 63.74 | 63.32 | 62.90 |
2016-12-29 | 62.90 | 63.65 | 63.19 | 62.73 |
2016-12-30 | 62.14 | 63.73 | 62.91 | 62.09 |
2017-01-03 | 62.58 | 63.56 | 62.78 | 62.00 |
2017-01-04 | 62.30 | 63.24 | 62.58 | 61.92 |
2017-01-05 | 62.30 | 62.98 | 62.44 | 61.91 |
2017-01-06 | 62.84 | 62.93 | 62.43 | 61.94 |
2017-01-09 | 62.64 | 62.95 | 62.53 | 62.12 |
2017-01-10 | 62.62 | 62.96 | 62.54 | 62.12 |
2017-01-11 | 63.19 | 63.30 | 62.72 | 62.13 |
2017-01-12 | 62.61 | 63.22 | 62.78 | 62.34 |
2017-01-13 | 62.70 | 63.19 | 62.75 | 62.31 |
2017-01-17 | 62.53 | 63.20 | 62.73 | 62.26 |
2017-01-18 | 62.50 | 63.21 | 62.71 | 62.20 |
2017-01-19 | 62.30 | 62.79 | 62.53 | 62.26 |
2017-01-20 | 62.74 | 62.87 | 62.55 | 62.24 |
2017-01-23 | 62.96 | 63.06 | 62.61 | 62.16 |
2017-01-24 | 63.52 | 63.65 | 62.80 | 61.96 |
2017-01-25 | 63.68 | 64.05 | 63.04 | 62.03 |
2017-01-26 | 64.27 | 64.52 | 63.43 | 62.35 |
2017-01-27 | 65.78 | 65.97 | 64.04 | 62.11 |
2017-01-30 | 65.13 | 66.20 | 64.48 | 62.75 |
2017-01-31 | 64.65 | 66.14 | 64.70 | 63.27 |
2017-02-01 | 63.58 | 66.18 | 64.68 | 63.19 |
2017-02-02 | 63.17 | 66.39 | 64.46 | 62.53 |
2017-02-03 | 63.68 | 65.50 | 64.04 | 62.58 |
2017-02-06 | 63.64 | 64.72 | 63.74 | 62.77 |
2017-02-07 | 63.43 | 63.87 | 63.50 | 63.13 |
2017-02-08 | 63.34 | 63.83 | 63.45 | 63.07 |