HI, I am trying to create a momentum strategy based on EMA 200 and 50. I am trying to store symbol, 200ema and 50ema in a placeholder class while universe selection so that I can sort the stocks having highest momentum of 50ema over 200ema. But following code snippet is not working as I always see IsReady false when I debug the code. Can you please help me pointing out what am I missing? Thanks in advance
def CoarseSelectionFunction(self, universe):
selected = []
universe = sorted(universe, key=lambda c: c.DollarVolume, reverse=True)
universe = [c for c in universe if c.Price > 10][:10]
# Create loop to use all the coarse data
for coarse in universe:
symbol = coarse.Symbol
#2. Check if we've created an instance of SelectionData for this symbol
if symbol not in self.averages and symbol is not None:
security=self.AddSecurity(SecurityType.Equity, symbol,Resolution.Daily)
#3. Create a new instance of SelectionData and save to averages[symbol]
fastEma=self.EMA(symbol,50,Resolution.Daily)
slowEma=self.EMA(symbol,200,Resolution.Daily)
self.RegisterIndicator(symbol, fastEma, Resolution.Daily)
self.RegisterIndicator(symbol, slowEma, Resolution.Daily)
# slowEma and fastEma IsReady is always shown as false in code
self.averages[symbol] = SelectionData(symbol,slowEma,fastEma)
Louis Szeto
Hi Log Up
Although self.EMA is an auto-updating indicator, it would still require warm-up from historical data. Call self.History and iterate the rows to update the indicator. Refer to the docs on how to do so.
Best
Louis
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.
Log Up
Hi Louis Szeto , thanks for the answer, I get it now. Does it mean if I don't use warm-up from historical data, I need to wait for N periods till my N period indicator is automatically updated and ready with the data?
Louis Szeto
Yup. 🚀
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.
Log Up
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!