Back

How do I prepare indicators for usage?

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!

Update Backtest








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
0

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.


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?

0

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

https://www.quantconnect.com/docs#Historical-Data
0

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.


Update Backtest





0

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.


Loading...

This discussion is closed