Hello,
Thanks for all that can help.
My moving average crossover algorithm is ordering at random times.
It is supposed to buy as 20 day ema passes over 200 day ema( 5 minutes consolidators for each).
However, it orders at times not warranted:
Order # 1 BUY: 2019-12-23 09:40:00 : [200 EMA = 43.46] [ 20EMA = 44.17](this one is kinda ok)
Order # 2 SELL :2019-12-23 15:45:00 : [200 EMA = 44.52] [ 20 EMA = 45.47]
Order # 3: ok
Order # 4 SELL: 2019-12-26 11:50:00 : EMA200 = 45.97--- EMA20=46.87
Order # 5 BUY: 2019-12-26 13:45:00 : EMA200 = 46.01. EMA20 = 46.25
As you can see these are totally random.
Any and all help is appreciated!
Ivan Baev
Okay. The thing is most of the stuff should be performed in the OnData function. When you program your algo entirely in OnDataConsolidated - it's not exactly what its built for. Please refer to a manual or a bootcamp.
Attached is your working example. But I'm not entirely sure its 100% correct implementation.
Andrés M
Hello... I added 2 lines to show what ema values and prices your code is picking up and it seems the EMA values seem to be incorrect (I am having a very similar issue lol). See the logs section in QuantConnect and compare those values to whatever charting website you use (ex: stockcharts.com, freestockcharts.com). In my 5 minute chart in freestockcharts.com it shows me the EMA200 is under the EMA20 but in QuantConnect logs, the EMA200 is above EMA20... the prices however do seem to be correct.
Not much help, but I am hoping someone can help you out since I am almost on the same boat with some of my ema projects lol
Christian Olsen
Thanks so much Andres!!!!!!!!!!!!
Andrés M
No problem Christian... if you find out what is causing the issue, please let me know
Alexandre Catarino
Hi Christian Olsen ,
First of all, thank all of you that tried to help. I know it is not only the Holiday Spirit!
The issue with the algorithm is that the indicators are registered to receive updates twice:
fiveMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=5)) # Here we are subscribing to 1-minute bars self.EMAFAST = self.EMA(self.equity, 20, Resolution.Minute) # Here we are subscribing to 5-minute bars self.RegisterIndicator(self.equity, self.EMAFAST, fiveMinuteConsolidator)
So the indicator is updated every minute plus every 5 minutes. Consequently, the value is completely off from what we would expect from either a 1-minute and a 5-minute EMA.
Assuming that we only want to use a 5-minute EMA, we would need to have:
fiveMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=5)) # Here we are creating an indicator without a subscription self.EMAFAST = ExponentialMovingAverage(20) # Here we are subscribing to 5-minute bars self.RegisterIndicator(self.equity, self.EMAFAST, fiveMinuteConsolidator)
Please check out the docs, under Indicators, for more details.
Christian Olsen
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!