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)
Shile Wen
Hi Essam,
This is because the Stochastic indicator requires OHLC information, which means it needs to have TradeBars for the Update method. Please see this thread on how to create TradeBars from History calls.
Best,
Shile Wen
Essam Saed
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!