Different result from optimization and single backtest

 

Hi,

I wonder if anyone experiencing or knowing the issue that I faced.

I just backtest a strategy and resulting in loss, then I start the optimization with a result like image below,

From that result I kind of skeptic with the 0 trade result. After optimization I tried to do a single backtest for combination of 300 stoploss and 4 times take profit (second row from the image with #44), and this is the result of the single backtest,

from a single backtest it shows that using that combination resulting in a loss which of course the EA opening a trade instead 0 trade from optimization. There's no changing in anything other than the combination of SL and TP.

Does anyone knows why this happened?

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Luandre Ezra:

Hi,

I wonder if anyone experiencing or knowing the issue that I faced.

I just backtest a strategy and resulting in loss, then I start the optimization with a result like image below,

From that result I kind of skeptic with the 0 trade result. After optimization I tried to do a single backtest for combination of 300 stoploss and 4 times take profit (second row from the image with #44), and this is the result of the single backtest,

from a single backtest it shows that using that combination resulting in a loss which of course the EA opening a trade instead 0 trade from optimization. There's no changing in anything other than the combination of SL and TP.

Does anyone knows why this happened?

Because something leads to 0 trade while optimizing. You have to investigate, we can't do it for you. Check the logs, check your code, etc...
 
Alain Verleyen #Check the logs, check your code, etc...

What should I check on the log? found no error at all.

Currently backtest (after deleting logs and opt file) using non visual and visual mode. The result when I backtest in non-visual mode will result 0 trade while backtest in visual mode resulting in profit.

This one backtest using non-visual mode,

Non-visual backtest

and here's the one with visual mode.

The confusing part is when I backtest with different set of combination that I never test, when I test on visual mode first and non-visual mode at the second time, the result came out the same.

 

This is the log from a combination that resulting 0 trades.

EM      0       17:27:42.191    Tester  single pass started
PQ      0       17:27:42.217    Tester  USDCAD: history data begins from 2011.01.03 00:00
HK      0       17:27:42.217    Tester  USDCAD: history data begins from 2011.01.03 00:00
HJ      0       17:27:42.217    Core 1  connecting to 127.0.0.1:3000
CK      0       17:27:42.218    Core 1  connected
DM      0       17:27:42.224    Core 1  authorized (agent build 4040)
FG      0       17:27:42.229    Tester  USDCAD,M15 (Eightcap-Demo): testing of Experts\Master\EA Master.ex5 from 2022.01.01 00:00 to 2022.12.31 00:00
KF      0       17:27:42.237    Core 1  common synchronization completed
HQ      0       17:27:42.261    Tester  quality of analyzed history is 99%
MD      0       17:27:47.126    Core 1  1478 bytes of tester parameters loaded
FP      0       17:27:47.126    Core 1  23236 bytes of input parameters loaded
IJ      0       17:27:47.126    Core 1  8943 Mb available, 111 blocks set for ticks generating
KP      0       17:27:47.126    Core 1  initial deposit 500.00 USD, leverage 1:100
LI      0       17:27:47.126    Core 1  successfully initialized
CN      0       17:27:47.126    Core 1  1907 bytes of total initialization data received
QJ      0       17:27:47.126    Core 1  AMD Ryzen 3 2200G with Radeon Vega, 16312 MB
OO      0       17:27:47.126    Core 1  USDCAD: symbol to be synchronized
PE      0       17:27:47.126    Core 1  USDCAD: symbol synchronized already, 18 bytes received
LH      0       17:27:47.126    Core 1  USDCAD,M15: history cached from 2021.01.04 00:00
DS      0       17:27:47.126    Core 1  USDCAD,M15 (Eightcap-Demo): every tick generating
HH      0       17:27:47.126    Core 1  USDCAD,M15: testing of Experts\Master\EA Master.ex5 from 2022.01.01 00:00 to 2022.12.31 00:00 started with inputs:
KE      0       17:27:47.126    Core 1    InpTradeSymbols=CURRENT
GM      0       17:27:47.126    Core 1    InpTradeTimeframe=0
PK      0       17:27:47.126    Core 1    InpBarProcessingMethod=2
FN      0       17:27:47.126    Core 1    InpTradeDirection=0
FS      0       17:27:47.126    Core 1    InpSettingsFile=
IF      0       17:27:47.126    Core 1    InpTradeAllowed=true
NQ      0       17:27:47.126    Core 1    =
GQ      0       17:27:47.126    Core 1    InpStdDevDesc=***** Standard Deviation Indicator *****
ER      0       17:27:47.126    Core 1    InpStdDevSmoothingPeriod=12
MO      0       17:27:47.126    Core 1    InpStdDevSmoothingMethod=1
DJ      0       17:27:47.126    Core 1    InpStdDevAppliedPrice=1
MO      0       17:27:47.126    Core 1    InpStdDevMaxTrendLevel=100
GD      0       17:27:47.126    Core 1    InpStdDevMiddleTrendLevel=40
KP      0       17:27:47.126    Core 1    InpStdDevFlatLevel=10
JG      0       17:27:47.126    Core 1    InpTrendLevel=0
CF      0       17:27:47.126    Core 1    InpZeroLagRVIDesc=***** Zero Lag RVI Indicator *****
PE      0       17:27:47.126    Core 1    InpRviSmoothing=15
JK      0       17:27:47.126    Core 1    InpFactor1=0.05
LP      0       17:27:47.126    Core 1    InpRVIPeriod1=8
CG      0       17:27:47.126    Core 1    InpFactor2=0.1
FF      0       17:27:47.126    Core 1    InpRVIPeriod2=21
JQ      0       17:27:47.126    Core 1    InpFactor3=0.16
GI      0       17:27:47.126    Core 1    InpRVIPeriod3=34
HJ      0       17:27:47.126    Core 1    InpFactor4=0.26
EL      0       17:27:47.126    Core 1    InpRVIPeriod4=55
HG      0       17:27:47.126    Core 1    InpFactor5=0.43
CG      0       17:27:47.126    Core 1    InpRVIPeriod5=89
QL      0       17:27:47.126    Core 1    ATRIndDesc=***** ATR Indicator *****
RF      0       17:27:47.126    Core 1    InpATRPeriod=14
JS      0       17:27:47.126    Core 1    =
JP      0       17:27:47.126    Core 1    GroupDesc2====== TRADE SETTING =====
NH      0       17:27:47.126    Core 1    SectionDesc2=***** Volume or Lot setting *****
RF      0       17:27:47.126    Core 1    InpVolumeMode=0
NK      0       17:27:47.126    Core 1    InpVolume=0.01
PN      0       17:27:47.126    Core 1    SectionDesc3=***** TP/SL/Trail Stop setting *****
JK      0       17:27:47.126    Core 1    InpStoplossMethod=1
IN      0       17:27:47.126    Core 1    InpSLCoef=400
IE      0       17:27:47.126    Core 1    InpTakeProfitMethod=2
NK      0       17:27:47.126    Core 1    InpTPCoef=4.0
FO      0       17:27:47.126    Core 1    InpOtherCloseMethod=0
RG      0       17:27:47.126    Core 1    InpOtherCloseCoef=0
PR      0       17:27:47.126    Core 1    SectionDesc4=***** other general setting *****
CG      0       17:27:47.126    Core 1    InpSlippage=10
LE      0       17:27:47.126    Core 1    InpMaxSpread=20
HL      0       17:27:47.126    Core 1    InpMagicNumber=1
HD      0       17:27:47.126    Core 1  2022.01.01 00:00:00   EA will process USDCAD only
IO      0       17:27:47.126    Core 1  2022.01.01 00:00:00   Handle for Std Dev Indicator / USDCAD / PERIOD_CURRENT successfully created
RO      0       17:27:47.126    Core 1  2022.01.01 00:00:00   Handle for Zero Lag RVI Indicator / USDCAD / PERIOD_CURRENT successfully created
FP      0       17:27:47.126    Core 1  2022.01.01 00:00:00   Handle for ATR Indicator / USDCAD / PERIOD_CURRENT successfully created
JO      0       17:27:47.126    Core 1  2022.01.01 00:00:00   All arrays sized to accomodate 1 symbols
FE      0       17:27:47.126    Core 1  2022.01.01 00:00:00   EA USING ONLY_PROCESS_TICKS_FROM_NEW_TRADE_TF_BAR PROCESSING METHOD AND INDICATORS WILL USE BAR 1
PK      0       17:27:47.126    Core 1  final balance 500.00 USD
FP      0       17:27:47.126    Core 1  USDCAD,M15: 21501486 ticks, 24851 bars generated. Test passed in 0:00:04.887.
ER      0       17:27:47.126    Core 1  754 Mb memory used including 3 Mb of history data, 448 Mb of tick data
HI      0       17:27:47.126    Core 1  log file "C:\Users\ezral\AppData\Roaming\MetaQuotes\Tester\BD3E608861B7C23BB6C3F206D58D0B48\Agent-127.0.0.1-3000\logs\20231117.log" written
JR      0       17:27:47.136    Core 1  connection closed

There isn't any error message and it just runs like normally would but without opening any trades.

 

And this is log of optimization backtest. Again no warning or error but all the result is 0 trade.


Files:
20231117.log  204 kb
 

Update:

Something new that I notice. When running single test from optimization tab for a profitable trade, it return 0 trade even though on optimization it result in profit.

 

Thanks @fxsaber for your suggestion, but sadly it's not solving my problem.

I just check my code with print statement and found the problem lies in position ticket. I have a line of code to return if there is already an open position. When I check the position number it's written with ticket #1362, the problem is there is no open trade at all.

Update: I already found the problem. I never initialize OpenPositionTicket variable at OnInit and I don't know why that the EA at some optimization combination fill the variable with number 1362, but everything is correct when I Initialize it. Thanks everyone for your help.

Reason: