Hello all,

I am currently trying to use the output from the keltner channels built-in indicator in a RollingWingow, however this is appearing to be very difficult. Trying to use the direct value of the UpperBand from the indicator does not work as it is of type IBaseDataBar. Do try and circumvent this issue I tried passing the value into an IndicatorDataPoint class and then adding that to the rolling window:

class KeltnerVortexStandardAlgo(QCAlgorithm): def Initialize(self): self.TradedSymbol = "AAPL" self.AddEquity(self.TradedSymbol, Resolution.Minute) self.SetStartDate(2020, 6, 1) # Set Start Date self.SetCash(100000) # Set Strategy Cash # self.AddEquity("SPY", Resolution.Minute) self.KCH(self.TradedSymbol, 20, 1.5, MovingAverageType.Simple, Resolution.Minute).Updated += self.OnKCHUpdated self.UpperBandWin = RollingWindow[IndicatorDataPoint](2) self.SetWarmUp(21, Resolution.Minute) def OnKCHUpdated(self, sender, updated): self.UpperBandWin.Add(IndicatorDataPoint(updated.Time, sender.UpperBand)) def OnData(self, data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Arguments: data: Slice object keyed by symbol containing the stock data ''' if not self.UpperBandWin.IsReady: return self.Debug(self.UpperBandWin[0]) # if not self.Portfolio.Invested: # self.SetHoldings("SPY", 1)

This however causes the RollingWindow to just be filled with IndicatorDataPoint classes with the correct Time attribute but a Value of 0.0 as shown in the attached backtest: 

Looking into the source code of the Keltner Channles indicator, it looks like this is happens when the MiddleBand's IsReady attribute is false: 

/// <summary> /// Initializes a new instance of the KeltnerChannels class /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The period of the average true range and moving average (middle band)</param> /// <param name="k">The number of multiples specifying the distance between the middle band and upper or lower bands</param> /// <param name="movingAverageType">The type of moving average to be used</param> public KeltnerChannels(string name, int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple) : base(name) { WarmUpPeriod = period; //Initialise ATR and SMA AverageTrueRange = new AverageTrueRange(name + "_AverageTrueRange", period, MovingAverageType.Simple); MiddleBand = movingAverageType.AsIndicator(name + "_MiddleBand", period); //Compute Lower Band LowerBand = new FunctionalIndicator<IBaseDataBar>(name + "_LowerBand", input => MiddleBand.IsReady ? MiddleBand.Current.Value - AverageTrueRange.Current.Value * k : decimal.Zero, lowerBand => MiddleBand.IsReady, () => MiddleBand.Reset() ); //Compute Upper Band UpperBand = new FunctionalIndicator<IBaseDataBar>(name + "_UpperBand", input => MiddleBand.IsReady ? MiddleBand.Current.Value + AverageTrueRange.Current.Value * k : decimal.Zero, upperBand => MiddleBand.IsReady, () => MiddleBand.Reset() ); }

Is there any way to utilise the UpperBand attribute of the indicator in a rolling window?

Thanks.

Author