Hey guys!
I have a problem!
The problem is, I need a different EMA according to which Ticker I am using. Take this code for example:
# In Initialize
for symbol, data in self.symbolData.items():
self.ema = self.EMA(data.symbol, 15, Resolution.Daily)
# CONSOLIDATED DATA
thirty_min_consolidator = TradeBarConsolidator(timedelta(minutes=30))
thirty_min_consolidator.DataConsolidated += self.OnThirtyMinBar
self.SubscriptionManager.AddConsolidator(data.symbol, thirty_min_consolidator)
daily_consolidator = TradeBarConsolidator(1)
daily_consolidator.DataConsolidated += self.OnTwoDayBar
self.SubscriptionManager.AddConsolidator(data.symbol, daily_consolidator)
# SCHEDULED EVENTS
self.Schedule.On(self.DateRules.EveryDay(data.symbol), self.TimeRules.AfterMarketOpen(data.symbol, 60), self.TradingOn)
self.Schedule.On(self.DateRules.EveryDay(data.symbol), self.TimeRules.BeforeMarketClose(data.symbol, 10), self.TradingOff)
self.Schedule.On(self.DateRules.EveryDay(data.symbol), self.TimeRules.BeforeMarketClose(data.symbol, 2), self.LiquidateCheck)
self.Schedule.On(self.DateRules.EveryDay(data.symbol), self.TimeRules.BeforeMarketClose(data.symbol), self.DayEnd)
Does anyone know how I could make the EMA 10 for one of the tickers within the for loop? Is this possible?
Thank you guys so much for your time,
Best,
Jesse
Derek Melchin
Hi Jesse,
One way to solve this is to create a dictionary that stores the EMA period of each symbol.
Then, in the for-loop, we access the EMA period from the dictionary.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Jesse Fleming
That is extremely useful! I would be remissed if I did not bring this error to your attention:
Line 86 being within the for loop. Any ideas how to get around this Mr Derek? Derek Melchin
Best,
And thank you for your timely response,
Jesse
Derek Melchin
Hi Jesse,
This error is probably from trying to access period_by_symbol with a key that doesn't exist in it. To resolve the error, either add all Symbol objects to the dictionary or set a default value if the Symbol isn't in the dictionary.
If this doesn't solve the issue, share more of the algorithm so we can reproduce the error.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Jesse Fleming
Hey Derek Melchin !!
It worked brother! Here is all the code for my next question:
Questions:
To reiterate the goal:
Thank you for being humble enough to help out a beginner,
Best,
Jesse
Alexandre Catarino
Hi Jesse Fleming ,
The backtest shows the same EMA for both symbols because it's the same EMA. self.ema is not being saved by Symbol and the iterations are overriding the reference to the object. Please replace:
for
The best approach to ensure indicators are being updated is to plot them. Alternatively, you can use the debugger to inspect their values.
Best regards,
Alex
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
Jesse Fleming
I really appreciate your response my brother. So concise and useful and great advice.
Such a simple fix! Thank you for pointing this out for me
Jesse Fleming
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!