Posted By: Smon
Bug? Backtest performance getting worse with smaller timeframes - 05/07/17 18:50
This strategy uses only simple pending orders and shows a whopping 360% annual profit in H4, but an annual loss in M1.
This is how I thought the backtest works with pending orders:
bar crosses limit order -> simulated trade opened (add spread and slippage)
bar hits stop -> book a loss
bar hits TP -> book a profit
bar hits both TP and SL within the same candle -> book a loss.
Using a smaller Timeframe, some trades that the backtester booked as a loss before, because it wasn't sure if TP or SL was hit first should turn into winners and performance should get even better.
This is how I thought the backtest works with pending orders:
bar crosses limit order -> simulated trade opened (add spread and slippage)
bar hits stop -> book a loss
bar hits TP -> book a profit
bar hits both TP and SL within the same candle -> book a loss.
Using a smaller Timeframe, some trades that the backtester booked as a loss before, because it wasn't sure if TP or SL was hit first should turn into winners and performance should get even better.
Code:
/* Mean Reversion Strategy ATR Band - looks similar to BollingerBands, without widening of the bands during spikes in Volatility Entry: Pending order at the perimeter of the ATR Band Exit: TP at the middle of the ATR Band */ function run() { //settings set(PLOTNOW); StartDate = 20100101; EndDate = 20161231; LookBack = 500; BarPeriod = 240; //set this to 60, 15 or even 1 to see what I mean NumWFOCycles = 8; //PriceSeries vars Price = series(price()); //Optimization Parameters var ATR_multi = 1; //optimize(2,1,4,0.2); //optimization disabled //static parameters TimeFrame = 240 / BarPeriod; //keep Timeframe for the ATR Bands at H4 at all times //ATR Bands vars middle = series(LowPass(Price,10)); vars upperATR = series(LowPass(Price,10)+ATR_multi*ATR(100)); vars lowerATR = series(LowPass(Price,10)-ATR_multi*ATR(100)); //Trendfilter // vars Trend = series(LowPass(Price,200)); //Trendfilter disabled //TradeManagement Stop = 2*ATR(25); //optimize(2, 1, 6, 1)*ATR(25); TakeProfit = middle[0]; EntryTime = 1; //TradeLogic if (true) //(rising(Trend)) Trendfilter disabled { Entry = -lowerATR[0]; reverseLong(1); } if (true) //(falling(Trend)) { Entry = -upperATR[0]; reverseShort(1); } PlotBars=300; plot("upperATR",upperATR,MAIN,GREY); plot("lowerATR",lowerATR,MAIN,GREY); }