Hello,
Finally after months I managed to find some free time to try out your platform and it looks awsome.
But... For educational purpose I'm trying to implement simple scalping strategy found on yt.
It buys or sells based on 5 min EMA 8, 23 and 1h EMA 8, 23 . For now it is suuuper bad. Way to bad to be real so I started to look for mistakes in my implementation. After printing some values I found out that my EMA's are off.
I need 5m EMA and 1h EMA so according to documentation for QC I implemented it this way:
self.PreferedResolution = Resolution.Second
self.AddForex(self.FXSymbol, Resolution.Second, Market.Oanda)
consolidator5m = QuoteBarConsolidator(timedelta(minutes=5))
self.price = self.Identity(self.FXSymbol, self.PreferedResolution)
self.RegisterIndicator(self.FXSymbol, self.price, consolidator5m)
self.ema8 = self.EMA(self.FXSymbol, 8, self.PreferedResolution)
self.ema21 = self.EMA(self.FXSymbol, 21, self.PreferedResolution)
self.RegisterIndicator(self.FXSymbol, self.ema8, consolidator5m)
self.RegisterIndicator(self.FXSymbol, self.ema21, consolidator5m)
consolidator1h = QuoteBarConsolidator(timedelta(hours=1))
self.emah8 = self.EMA(self.FXSymbol, 8, self.PreferedResolution)
self.emah21 = self.EMA(self.FXSymbol, 21, self.PreferedResolution)
self.RegisterIndicator(self.FXSymbol, self.emah8, consolidator1h)
self.RegisterIndicator(self.FXSymbol, self.emah21, consolidator1h)
consolidator5m.DataConsolidated += self.OnDataConsolidated
self.SubscriptionManager.AddConsolidator(self.FXSymbol, consolidator5m)
self.SubscriptionManager.AddConsolidator(self.FXSymbol, consolidator1h)
With :
self.PreferedResolution = Resolution.Second
5m EMA is equal to 1h EMA which is absolutely incorrect.
With :
self.PreferedResolution = Resolution.Minute
self.PreferedResolution = Resolution.Hour
Values of 5m EMA and 1h EMA are different but still look wrong but at least they are updated every 5 minutes and are diffrent from each other :)
With:
self.PreferedResolution = Resolution.Daily
Values of 1h EMA are updated only every hour and 5m EMA is updated every 5 minutes.
Can someone explain this behaviour and point me to right direction?
I've read somewhere on this community forum that it's better to have higher resolution data input then algorithms decision making resolution so my goal is to have Resolution.Second data consolidated into 5m QuoteBars so my algo will make decision about buying/selling every 5 minutes
Jing Wu
For the helper method "self.EMA()", this indicator updates its value automatically with the specified resolution. Therefore, all indicators in your algorithm now are actually in self.PreferedResolution.
To update the indicator with the consolidator, you should create the indicator with the constructor method for example
# create the constructor method self.ema8 = ExponentialMovingAverage(8)
Then update the indicator with
self.RegisterIndicator(symbol, self.ema8, consolidator)
Instead of using Identity() indicator, you can get the consolidated bar price in OnDataConsolidated() method.def OnDataConsolidated(self, sender, bar): close = bar.Close
Erathan
Thank you for explaining those helper methodes to me. I find python documentation a little bit lacking in some cases.
Jing Wu
We already added the introduction to indicator helper method and the constructor in the documentation. Please see "Indicators" section
Erathan
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!