Hi every one
I would appreciate help in this, currently, i am working on a frame algorithm using the stochastic indicator, and when I call the indicator in
def OnSecuritiesChanged(self, algorithm, changes):
# clean up data for removed securities
symbols = [ x.Symbol for x in changes.RemovedSecurities ]
if len(symbols) > 0:
for subscription in algorithm.SubscriptionManager.Subscriptions:
if subscription.Symbol in symbols:
self.symbolDataBySymbol.pop(subscription.Symbol, None)
subscription.Consolidators.Clear()
# initialize data for added securities
addedSymbols = [ x.Symbol for x in changes.AddedSecurities if x.Symbol not in self.symbolDataBySymbol]
if len(addedSymbols) == 0: return
history = algorithm.History(addedSymbols, self.period, self.resolution)
for symbol in addedSymbols:
self.sto = algorithm.STO(symbol, self.period, self.resolution)
self.sto.Updated += self.STO_Updated
self.STO_Window = RollingWindow[IndicatorDataPoint](6)
if not history.empty:
ticker = SymbolCache.GetTicker(symbol)
"""
if ticker not in history.index.levels[0]:
algorithm.Log.Trace(f'RsiAlphaModel.OnSecuritiesChanged: {ticker} not found in history data frame.')
continue
"""
for tuple in history.loc[ticker].itertuples():
self.sto.Update(tuple.Index, tuple.close)
self.symbolDataBySymbol[symbol] = SymbolData(symbol, self.STO_Window)