conceptcar3
New member
Hey everyone, I made a strategy that times the SPX market, it has outperformed the SPX since 1928 and with less drawdown (risk) than buy and hold. Here is the strategy for you to check out. hope you enjoy. The method is rather simple, merely buy the SPX approximately 60 trading days (approximately 3 months, exact numbers can be seen in the source code below) after the 1 period moving average crosses over the 200 period EMA. the same goes for shorting it, this is a long short strategy.
Any feedback or thoughts appreciated! The code is very sloppy but it was the only way I could figure out how to do it. Make sure you are on a daily SPX chart. Also, very importantly, I use the strategies stoplosslx and stoplosssx to implement stop losses on each trade of the strategy, 6 percent on stoplosssx and 12 percent on stoplosslx. Enjoy!
Here is the code
Any feedback or thoughts appreciated! The code is very sloppy but it was the only way I could figure out how to do it. Make sure you are on a daily SPX chart. Also, very importantly, I use the strategies stoplosslx and stoplosssx to implement stop losses on each trade of the strategy, 6 percent on stoplosssx and 12 percent on stoplosslx. Enjoy!
Here is the code
Code:
#longtermspxstrategy
input price = close;
input fastLength = 1;
input slowLength = 200;
input averageType = AverageType.EXPONENTIAL;
plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
FastMA.SetDefaultColor(GetColor(1));
SlowMA.SetDefaultColor(GetColor(2));
def bullishsignal = fastma > slowma and fastma[1] > slowma[1] and fastma[2] > slowma[2] and fastma[3] > slowma[3] and fastma[4] > slowma[4] and fastma[5] > slowma[5] and fastma[6] > slowma[6] and fastma[7] > slowma[7] and fastma[8] > slowma[8] and fastma[9] > slowma[9] and fastma[10] > slowma[10] and fastma[11] > slowma[11] and fastma[12] > slowma[12] and fastma[13] > slowma[13] and fastma[14] > slowma[14] and fastma[15] > slowma[15] and fastma[16] > slowma[16] and fastma[17] > slowma[17] and fastma[18] > slowma[18] and fastma[19] > slowma[19] and fastma[20] > slowma[20] and fastma[21] > slowma[21] and fastma[22] > slowma[22] and fastma[23] > slowma[23] and fastma[24] > slowma[24] and fastma[25] > slowma[25] and fastma[26] > slowma[26] and fastma[27] > slowma[27] and fastma[28] > slowma[28] and fastma[29] > slowma[29] and fastma[30] > slowma[30] and fastma[31] > slowma[31] and fastma[32] > slowma[32] and fastma[33] > slowma[33] and fastma[34] > slowma[34] and fastma[35] > slowma[35] and fastma[36] > slowma[36] and fastma[37] > slowma[37] and fastma[38] > slowma[38] and fastma[39] > slowma[39] and fastma[40] > slowma[40] and fastma[41] > slowma[41] and fastma[42] > slowma[42] and fastma[43] > slowma[43] and fastma[44] > slowma[44] and fastma[45] > slowma[45] and fastma[46] > slowma[46] and fastma[47] > slowma[47] and fastma[48] > slowma[48] and fastma[49] > slowma[49] and fastma[50] > slowma[50] and fastma[51] > slowma[51] and fastma[52] > slowma[52] and fastma[53] > slowma[53] and fastma[54] > slowma[54] and fastma[55] > slowma[55] and fastma[56] > slowma[56] and fastma[57] < slowma[57];
def bearishsignal = fastma < slowma and fastma[1] < slowma[1] and fastma[2] < slowma[2] and fastma[3] < slowma[3] and fastma[4] < slowma[4] and fastma[5] < slowma[5] and fastma[6] < slowma[6] and fastma[7] < slowma[7] and fastma[8] < slowma[8] and fastma[9] < slowma[9] and fastma[10] < slowma[10] and fastma[11] < slowma[11] and fastma[12] < slowma[12] and fastma[13] < slowma[13] and fastma[14] < slowma[14] and fastma[15] < slowma[15] and fastma[16] < slowma[16] and fastma[17] < slowma[17] and fastma[18] < slowma[18] and fastma[19] < slowma[19] and fastma[20] < slowma[20] and fastma[21] < slowma[21] and fastma[22] < slowma[22] and fastma[23] < slowma[23] and fastma[24] < slowma[24] and fastma[25] < slowma[25] and fastma[26] < slowma[26] and fastma[27] < slowma[27] and fastma[28] < slowma[28] and fastma[29] < slowma[29] and fastma[30] < slowma[30] and fastma[31] < slowma[31] and fastma[32] < slowma[32] and fastma[33] < slowma[33] and fastma[34] < slowma[34] and fastma[35] < slowma[35] and fastma[36] < slowma[36] and fastma[37] < slowma[37] and fastma[38] < slowma[38] and fastma[39] < slowma[39] and fastma[40] < slowma[40] and fastma[41] < slowma[41] and fastma[42] < slowma[42] and fastma[43] < slowma[43] and fastma[44] < slowma[44] and fastma[45] < slowma[45] and fastma[46] < slowma[46] and fastma[47] < slowma[47] and fastma[48] < slowma[48] and fastma[49] < slowma[49] and fastma[50] < slowma[50] and fastma[51] < slowma[51] and fastma[52] < slowma[52] and fastma[53] < slowma[53] and fastma[54] < slowma[54] and fastma[55] < slowma[55] and fastma[56] < slowma[56] and fastma[57] < slowma[57] and fastma[58] < slowma[58] and fastma[59] < slowma[59] and fastma[60] < slowma[60] and fastma[61] < slowma[61] and fastma[62] < slowma[62] and fastma[63] > slowma[63];
def buy = bullishsignal;
def sell = bearishsignal;
AddOrder(OrderType.buy_auto, buy, open[-1], 1, Color.ORANGE, Color.ORANGE, "buy" + open[-1]);
AddOrder(OrderType.sell_auto, sell, open[-1], 1, Color.ORANGE, Color.ORANGE, "sell" + open[-1]);