Hello everyone,

I'm writing a system which uses a Bollinger Band as an entry signal (in particular, the entry signal is when the price crosses the upper band of the BB with average=100 days and 2 standard deviations. I have read (enough!) carefully the documentation and I have embedded the logic of the entry signal in a SymbolData class, where I have also created two small Rolling Windows to store previous values of price and BB so to check if the cross has occurred and then to update the crossed variable. The update method of SymbolData is called from inside of CoarseSelectionFunction function passing cf.EndTime and cf.AdjustedPrice to it, as explained in the documentation.

class SymbolData():
def __init__(self, symbol):
self.symbol = symbol
self.bb_band = BollingerBands(100, 2, MovingAverageType.Simple)
self.priceWin = RollingWindow[float](2)
self.bbWin = RollingWindow[float](2)
self.crossed = False

def update(self, time, price):
self.bb_band.Update(time, price)
if self.bb_band.IsReady:
upper_band_value = self.bb_band.UpperBand.Current.Value
if self.bb_band.IsReady and self.bbWin.IsReady and self.priceWin.IsReady:
self.crossed = self.priceWin[1] < self.bbWin[1] and self.priceWin[0] > self.bbWin[1]

Unfortunately, I have checked the values produced by my Bollinger Band indicator and I've observed that my code fragment does not produce correct numbers, and the Bollinger Band value is almost always very similar to the price value but never enough far from it (as sometimes it should be), a symptom that my code is wrong in computing it. Also drawing the indicator on a chart shows that it is not correct. Is it necessary to use somehow an event handler for updating it (i.e.   self.bb_band Updated += self.OnBBUpdated )? Could you kindly help me to understand where my code is wrong?

Thank you in advance,