SMA Crossover Strategy

This is a simple SMA Crossover strategy that longs/shorts the SPY during strong trends, and liquidates during times of high market volatility, to withstand whipsaws (false signals). This liquidation function is especially helpful during 2011 and 2015, as it would have suffered from greater drawdowns otherwise. 

The 3 main components are as follows: 

1. When the 50 day SMA goes above the 200 day SMA, long the SPY.

2. When the 50 day SMA goes below the 200 day SMA, short the SPY. 

3. If the unrealized losses on any given day exceed $2000, liquidate. This was done by using:

if (profitloss <= -2000)

with profitloss being:

var profitloss = Portfolio[_symbol].UnrealizedProfit;

Please feel free to make any suggestions on how this can be improved. 

Update Backtest

Here is the backtest with $10,000 starting capital:

Notice how the amount for the liquidation component was changed from $2,000 to around $400 to reflect similar returns. 

If you changed the starting capital to 1 million, for example, then you would use 50k. 

if (profitloss <= -50000)

Update Backtest


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.


This discussion is closed