I would say this: you haven't really optimized the MAs for this particular scenario. since there is no cost in stuttering in and out of a trade, it is better to make the MAs closer in duration and shorter. Then what happens is when the price takes a big trend, you capture most of those big trends as profits. But you don't pay when the price moves sideways, causing you to enter and exit with no profit. Also by making the MAs shorter, you will have less of a chance that an entry/exit results in a loss. Here I would agree with you that less lag will be better because of this tracking error. But simply making the MA periods smaller will help you here.
Quote from jcl:
At first, I made a mistake with the code, I got the crossover the wrong way around - sorry for that. Here's the fixed code, with the MA plots:
Code:function run() { Spread = 0; Slippage = 0; Commission = 0; RollLong = 0; RollShort = 0; DataSplit = 80; var *Close = series(priceClose()); var *MA1 = series(SMA(Close,optimize(100,10,1000))); var *MA2 = series(SMA(Close,optimize(300,30,3000))); Stop = 2*ATR(100); if(crossOver(MA1,MA2)) enterLong(); else if(crossUnder(MA1,MA2)) enterShort(); plot("MA1",*MA1,0,RED); plot("MA2",*MA2,0,BLUE); }
And here's the chart:
![]()
As you see, the fixed version ends indeed with a win, not with a loss, but it is obviously not a profitable strategy - the drawdown is larger than the profit, and the positive result was just random. The Sharpe Ratio is 0.39.