I was sent here after communicating with the support team over email to seek advice on how to solve this strange bug. I implemented a history lookback into an already working algorithm using the code from the Documentation as you can see in the snippet below.
def OnSecuritiesChanged(self, changes):
for security in changes.AddedSecurities:
self.Small = self.EMA(security.Symbol, 50, Resolution.Hour)
history = self.History([security.Symbol], 50, Resolution.Hour)
for time, row in history.loc[security.Symbol].iterrows():
self.Small.Update(time, row["close"])
In a backtest of the last five years, the algorithm works perfectly and is correctly using the historical data and making trades for the first four years. However, on the July 1st bar in 2019, I get an error message saying, "Object is not callable at OnSecuritiesChanged" and the algorithm stops running (it also says the error is on line 94 even though my entire code has only 83 lines, but that's likely unrelated to the issue). I am sure this error comes from the time and row loop because this algorithm was backtesting just fine before I added these lines in.
What is the problem and how do I solve it?
Shile Wen
Hi Ethan,
Please attach an algorithm that can be used to reproduce the issue so it is easier for us to help you.
For now, one idea is that it's probably due to if the history DataFrame being empty, so we should check if history.empty before proceeding to update the indicator.
Furthermore, I suggest using the SelectionData/SymbolData pattern as shown in this BootCamp, as the current code constantly initializes a new indicator for the same field and updates it with data from all of the added securities.
Best,
Shile Wen
Ethan Wertlieb
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!