Hello all traders and quants,
I am comparatively very new to Algo trading. So I wrote this algo to trade based on simple EMA crossover strategy.
Strategy on the lines of -
There are three EMAs - slow ,fast and medium. I maintain the current price and the one last price in Rolling Window,.
- BUY signal - whenever there is a
- medium EMA crossing up slow EMA
- also the fast EMA is higher than slow EMA
- then BUY 5% of portfolio amount.
- SELL signal - it is just opposite of BUY that is same signals but crossing down
- Now I tried to put in a Trailing SL but yet only on BUY Orders.,
- If the profit for a symbol is more than 10% then make the SL at current 10% less than current price
- Also if the fast EMA crosses down medium EMA, then liquidate the BUY orders and same for SELL signals
I have attached the backtest based on one of these signals.
Now, my questions
- I feel the strategy always start good and then mid way it either stops getting the profits or hits a snag. What is the best way to test out the details like how many trades did the algo skipped, or Equity after each day so that I can find a pattern of when the algo starts giving the losses.
- How can I improve this strategy like the next steps, what additional things I should try? Like I already tried changing EMA time periods and percentage of the portfolio to make each order. What other variations can I try with an algo?
- Any other suggestions based on Algo
Derek Melchin
Hi Ray,
After a backtest is complete, we can download some statistics about its performance by clicking the "Download Results" button in the Overview tab. In the file that is downloaded, we have access to the strategy equity curve plot data. We can also track this metric during the backtest by adding a property to our algorithm class in Initialize
self.daily_equity = pd.Series([])
and update it each day with
def OnEndOfDay(self): self.daily_equity = self.daily_equity.append(pd.Series(self.Portfolio.TotalPortfolioValue, index=[self.Time]))
Then we can just add the `daily_equity` series to the logs at the end of the backtest for us to gather and analyze.
def OnEndOfAlgorithm(self): self.Log(self.daily_equity.to_string())
See the attached backtest for an implementation of this `daily_equity` tracking. Just note that the logging is limited.
Although the possibilities are virtually endless, here are some things we could try changing in this strategy:
Best,
Derek Melchin
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.
Ray Trader
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!