Hello everyone!
I've been working on strategies on QuantConnect for awhile now and I recently came across one detail that I've overlooked. When you initialize an indicator for a stock with its helper method in OnSecuritiesChanged, for example, a momentum percent (MOMP) indicator and you initialize with self.MOMP(symbol, period, resolution.daily) the indicator should automatically update with the given universe resolution right? We don't need to manually update it.
The MOMP takes in close prices by default I believe, so does that mean that we don't need to register the indicator since we're not using any other custom values other than the values that we initialize it with? i.e. symbol, period, resolution
Varad Kabade
Hi Li Cheng,
When using the helper function to create an indicator, the indicator is created and hooked to automatic updates at the given resolution. Refer to the following docs for more information. We also recommend going through the following example algorithm.
Best,
Varad Kabade
Li Cheng
Hi Varad, thanks for answering my question! I've tried to use the automatic update function for a basic MACD strategy for SPY, for some reason, the algorithm isn't placing any trades. I've tried to debug it with self.Debug(self.macd[symbol].Current.Value) in OnData but no value shows up, can you advise me on what changes I should make to the algorithm?
Louis Szeto
Hi Li Cheng
The indicator warm-up and auto-update subscription is correctly set up. The reason for no trade in this backtest is because there is no symbol returned from FineSelectionFunction:
The following should work for SPY, we also included a backtest using AAPL for the same mechanism.
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.
Li Cheng
Hi Louis, thanks for the reply!
I was dumb, should've noticed that no symbols were returned from Fine selection and that SPY didn't have fundamentals. But I learned something new from your reply, that only symbols with fundamentals are returned from Fine selection, and that coarse selection allows the return of symbols even if they didn't have fundamentals.
I suppose that another way to do this with SPY would be to use the AddEquity function for SPY in initialize.
Varad Kabade
Hi Li Cheng,
Yes, you are right; we can manually add spy in the Initialize method; also as we are not doing any fine filtering we can just use the coarse filter function suggested by Louis which will also add spy in the universe.
Best,
Varad Kabade
Li Cheng
Hi Varad, really appreciate the clarification! Thanks a bunch!
Li Cheng
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!