Back

Testing various EMA crosses on different time frames for AAPL

Hello Community,
I was wondering if someone can make me a skeleton code I can try here where I will be able to easy modify my EMA crosses and time frames. I would like to start by testing a 13/3 EMA CROSS on a 1 minute chart, backtesting at least 6 months to 1 year. I would like the code to only recognize the ema cross once the candle has closed. So at the end of each candle did the signal change from long to short for example, if yes, then send signal at close of candle or open of very next candle only.
Update Backtest








Chris, if you go to the QCU tab of the back tester, you should find on the very last page, "C# Strategy example : Moving Average Cross Strategy". Which I think is the starting point you're after, you'll obviously need to tweek it so that it runs on minute data, and change the EMA periods, bit I think that's what you're after..

Cheers,
Paul
0

Great advice Paul! I recommend everyone check out the university tab first, as there's some great examples there. Also, if you can't find what you're looking for there, there's also examples for each features in the github project here.

Chris, try putting something together from the examples and if you get stuck, post your algorithm to the forums and we'll help you out!
0

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.


Ok thanks guys I'm on it
0

I modified the Moving Average templet. This algo Buy $aapl stock if EMA 89 is above SMA 140, and Close the trade if the opposite occurs. 

Since I am new to programming, I suspect I there might be some issues that is not apparent to me.

Any input from the Quantconnect community?

Thanks for any input.

 

Avi

1


Avi, the issue with this algorithm has nothing to do with your programming skills, instead the problem here is the selection bias. Basically, you made a long strategy with a bullish stock like AAPL in the period under study. You can achieve a higher Net Profit if you just buy the stock at the beginning of the strategy.

0

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.


Great Thanks JayJayD for your response. I agree there is selection bias issue. I wanted to create a starting point by testing different stocks, APPL just came to mind. Next step will be to test this strategy on portfolio of stock, and measure its performance to SPY.

I don't quite understand how to work with portofio of stocks yet, but will dig deeper.

If you or anyone elso have any tips regarding coding protfolio of stocks, please share them.

 

Thanks

0

Avi, you can use Dictionaries and make every module of you algorithm an object for each one of the securities.

I made this example with a module for teh crossing moving averages and another module for risk managment.

The cross moving average module is the signal generator (buy - sell) and a instance is declared for each one of the securities.

Finally, don't forget to check the QCUniversity, there are tons of great examples.

 

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed