The following backtest trades the price crossover of the 252 EMA for SPY. This moving average clearly does not cross the 252 EMA on Feb 9th, yet it still triggered buy + sell orders. Please let me know what keeps going wrong. Thanks in advance for the help!
Jing Wu
Hi James, often indicators need some historical data to initialize in order to get the correct value. You could set a warm-up period in Initialize() and check if warm-up finished before further steps in OnData().
def Initialize(self): self.SetWarmup(TimeSpan.FromDays(252)) def OnData(self,data): if self.IsWarmingUp: return
James Parrish
This definitely solved the issue. However, I would like a better way (if possible) for when I live trade the algorithm. If I need to redeploy an algo, I have to wait say 21 days for the algo to warm up just to trade a 21 dma crossover. Are you sure there isn't any quicker solution?
Jared Broad
The set warm up method pulls down the data needed for the algorithm. You can also use the History API to manually pull down bars you need if you want to manually prepare your state.
Please see the 3 example algorithms in the documentation
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.
James Parrish
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!