S&P500 Backtest shows different numbers than the Report
01/01/2023 at 4:15 PM #206598
Hello, Happy New Year!
I have put together the following code and tried to run it TF M15 on S&P500 (Broker IG / code SPTRD at $50 per point). The results generated in the optimization table (+$25,365) do not match with the results shown on the Report (-$6385). Anyone can help please? could it be the Ticker? or something wrong with the code itself? Thanks12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697DEFPARAM CUMULATEORDERS = FALSEDEFPARAM PRELOADBARS = 2500TIMEFRAME(DAILY)TKD = TenkanSen[9,26,52]KJD = KijunSen[9,26,52]TIMEFRAME(240 minutes)TKH4 = TenkanSen[9,26,52]KJH4 = KijunSen[9,26,52]RSIH4Exit = RSI(close)TIMEFRAME(60 minutes)TKH1 = TenkanSen[9,26,52]KJH1 = KijunSen[9,26,52]RSIH1Exit = RSI(close)TIMEFRAME(15 minutes)condvol = 0Bull = 0Bear = 0LongExit = 0ShortExit = 0myATR = AverageTrueRange(close)TK = TenkanSen[9,26,52]KJ = KijunSen[9,26,52]LR100 = LinearRegression(close)EMA100 = ExponentialAverage(close)EMA34H = ExponentialAverage(high)EMA34L = ExponentialAverage(low)StoK = Stochastic[14,3](close)voltrigger = 25lengthvolstd = 200multvolstd = 1.0AvgVol = Average(volume)VolSpike = (1 + (voltrigger / 100)) * AvgVolcondvol1 = volume > VolSpikevolumeStDev = STD[lengthvolstd](volume)highVol = volume - volume > volumeStDev*multvolstdcondvol = (highVol or condvol1)ca1 = (close > TK and close > KJ)ca2 = (close > EMA34H and close > EMA34L)ca3 = (close > LR100 or close > EMA100)Bull1 = (ca1 or ca3) and ca2 and close crosses over high and condvol and StoK < 80cv1 = (close < TK and close < KJ)cv2 = (close < EMA34H and close < EMA34L)cv3 = (close < LR100 or close < EMA100)Bear1 = (cv1 or cv3) and cv2 and close crosses under low and condvol and StoK > 20Bull = Bull1 and not Bull1Bear = Bear1 and not Bear1LongExit = close crosses under KJD or close crosses under KJH4 or close crosses under KJH1 or TKD crosses under KJD or TKH4 crosses under KJH4 or TKH1 crosses under KJH1ShortExit = close crosses over KJD or close crosses over KJH4 or close crosses over KJH1 or TKD crosses over KJD or TKH4 crosses over KJH4 or TKH1 crosses over KJH1nLots = 0.5IF time >=080000 and time <= 215500 thenIF NOT LongOnMarket AND Bull THENBUY nLots CONTRACTS AT MARKETENDIFIF NOT ShortOnMarket AND Bear THENSELLSHORT nLots CONTRACTS AT MARKETENDIFENDIFIF LongOnMarket AND Bear THENSELL AT MARKETENDIFIF ShortOnMarket AND Bull THENEXITSHORT AT MARKETENDIFIF LongOnMarket AND LongExit THENSELL AT MARKETENDIFIF ShortOnMarket AND ShortExit THENEXITSHORT AT MARKETENDIFSET STOP pLOSS max(myATR * 1.5,10)SET TARGET PPROFIT TPSET STOP PTRAILING SLTIF time = 220000 THENSELL AT MARKETEXITSHORT AT MARKETENDIF01/01/2023 at 4:55 PM #20660101/01/2023 at 7:01 PM #20660601/01/2023 at 7:13 PM #20660901/01/2023 at 7:30 PM #20661101/01/2023 at 7:57 PM #20661401/01/2023 at 8:21 PM #206616
What I have always understood is that the optimization never works with “tick by tick mode” but that only ProBackTest uses “tick by tick mode”…
So, when you optimize and you get a certain (optimal) result, this is always without “tick by tick mode”.
You will see that your optimization and your ProBackTest give the same results when you turn off “tick by tick mode”…01/01/2023 at 8:26 PM #20661701/01/2023 at 8:26 PM #20661801/01/2023 at 8:35 PM #20662201/01/2023 at 8:46 PM #206626
How did you arrive at 6 for Stop pTrailing? (Stop pTrailing is fraught with problems anyway, best to use a coded Trailing Stop)
You would be stopped out (with SLT 6) almost each and every 15 min bar and so get a ‘high value in the Tick Mode column‘ on backtest results. This is likely the reason for your odd results (same / similar to what JS has said).
Ideally we want 0 / zero in the Tick Mode column‘ on backtest results … backtest result will then be same as shown on the Chart and Detailed Report (allowing for any open trades … which are NOT taken account of in backtest results).01/01/2023 at 8:50 PM #206628
The difference between the optimization (without tick by tick mode) and the ProBackTest (with tick by tick mode) is so big here because the code uses stop loss, take profit and trailing stop that are only calculated in the ProBackTest in a “good way”…01/01/2023 at 9:05 PM #20662901/01/2023 at 9:43 PM #206632
Thank you. the Spread of 0.4 is the IG Spread during regular market hours, which I used as an estimation. The Spread on official Futures is 0.25.
The SL (line 90) is useful in case the position goes immediately into red and does not have the chance to comeback to green (news for example).01/01/2023 at 9:45 PM #206635
You’re absolutely right. I’ve optimized with T by T and get the same result on the optimization and the Report, which is by the way very close to the one reported on your graph. Thank you!
The system looks promising though. Every single month is green from Oct. 2021 to Dec. 2022. Based on the report, very minimal drawdown. R/R x3.3