Indicator; rolling window to get indicator values n days back.

So I want the value of the Bollinger band and Keltner channel,python, from the current day and the previous day using rolling windows. I tried using the sample code and forum posts but have been unable to apply it to bollinger bands and keltner channel. I am still confused on how to use the rolling windwos.. Can someone point me in the right direction?

Thanks :)

Update Backtest

just post the algo how far you got,..


Oops sorry here it is. I apologize if it looks really bad I was trying to follow the github example.


### <summary>
### Basic template algorithm simply initializes the date range and cash. This is a skeleton
### framework you can use for designing an algorithm.
### </summary>
class BasicTemplateAlgorithm(QCAlgorithm):
'''Basic template algorithm simply initializes the date range and cash'''

def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

self.SetStartDate(2000,10, 7) #Set Start Date
self.SetEndDate(2018,3,11) #Set End Date
self.SetCash(100000) #Set Strategy Cash
# Find more symbols here:
self.AddEquity("NVDA", Resolution.Daily)
self.Debug("numpy test >>> print numpy.pi: " + str(np.pi))
self.window = RollingWindow[TradeBar](2) # For other security types, use QuoteBar

# Creates an indicator and adds to a rolling window when it is updated"NVDA", 20,1.5).Updated += self.BBUpdated
self.BBWindow = RollingWindow[IndicatorDataPoint](2)
def SmaUpdated(self, sender, updated):
'''Adds updated values to rolling window'''

def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.

data: Slice object keyed by symbol containing the stock data

# Add SPY TradeBar in rollling window

# Wait for windows to be ready.
if not (self.window.IsReady and self.BBWindow.IsReady): return

currBar = self.window[0] # Current bar had index zero.
pastBar = self.window[1]
'' Different attempt //OnData
'' _BBWindow.Add(_bb);
'' if(!_BBWindow.IsReady) return;

'' //value
'' BB_2_days_ago = BBWindow[2];''

hi, i played a little with python. i am not a pro but when you take a look at some algos on github you get the idea how it is done. I stored the values of the bands in rolling windows because i dont know how to deepcopy the whole keltner channel class to store only one copy in one window.

the indicators update automatically at the daily resolution.

checkout one day the following example to work with more stock data

Thanks for the help! The github link was also very helpful.  Appreciate the help


Update Backtest


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


This discussion is closed