I've created this EMA crossing strategy where the only time a long/short trade is entered with TSLA is at the point of the 12/26 EMA crossing. I've established a rolling window for both EMA indicators and hold the previous and current values in them. I then logically short only if the previous 12EMA is > the previous 26 EMA and the current 12EMA is < the 26 EMA (hence, at crossing). Similar logic for entering into a long position but in reverse. I also create a 1% stop market order to protect my downside risk and have a 2% take-profit established. I've combed through this algorithm many times but cannot determine why it isn't trading. Everything seems to logically flow on my end. Am I missing something?
Fred Painchaud
Hi James,
You simply forgot to make sure your indicators and windows were ready in your OnData method. OnData is called actually to warm up the algorithm, with data that comes from before your starting date.
Then, you had some typos in your algo and since it is Python, it pops out only when those typos “are executed”.
I have divided also your two EMA updated event handlers. You do not want fast and slow to Kris Kross. (You'll make it, huhuh huhuh! 😊)
Cheers,
Fred
P.S. For EMA, you could actually warm up for a much longer period. Another subject.
Vladimir
James Hawkins,
We prefer :
1 instead of RollingWindow to use IndicatorExtensions.Of (Delay (1), self.emaFast).
2 instead of self.StopMarketOrder to use self.Portfolio [self.stock].UnrealizedProfit.
Try "EMAC, Take Profit and Stop Loss with UnrealizedProfit", which never executed a Margin Call with your settings.
James Hawkins
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!