different results in optimization and single test

 

Hello everyone.

I do optimization based on real ticks. When it finishes I try running single tests and compare with results I see in optimization table. They are not the same. What could the problem be?

 
It may be the different number of ticks.
Anyway - there is the discussion thread about it: https://www.mql5.com/en/forum/448844
MT5 tester bug: same conditions, different results - What you need to know about the MT5 bug?
MT5 tester bug: same conditions, different results - What you need to know about the MT5 bug?
  • 2023.06.12
  • www.mql5.com
I found a few similar posts (questions) with no solution: when run the same backtest two times (one after another) , the mt5 tester sometimes gives different results. It's just mt5 tester that gives sometimes different results with the same input. There is no mt5 bug unless your prove it otherwise by providing all the information, parameters and code to reproduce it
 
Yashar Seyyedin: I do optimization based on real ticks. When it finishes I try running single tests and compare with results I see in optimization table. They are not the same. What could the problem be?

99% of the time it is due to a bug in the EA code.

One possible cause that used to happen to me, was about Globally scoped variables not being properly initialised in the OnInit().

Forum on trading, automated trading systems and testing trading strategies

No trades open during strategy optimization

Fernando Carreiro, 2023.02.24 14:08

One common cause for optimisation passes to be different from individual back-test runs, is globally scoped variables that are not properly initialised in functions and only initialised in their global declarations.

The reason is that the EA's global variables are not reinitialised based on their declarations on every new optimisation pass (I don't know if this is a bug or intentional, but it is what happens).

So, make sure you initialise all your globally scoped variables in the OnInit() event handler if they are not initialised elsewhere in other functions

However, that is just one possible cause. It is only a guess. If you want an informed answer, then you will have to provide the actual source code of the EA that has this issue.

Forum on trading, automated trading systems and testing trading strategies

No trades open during strategy optimization

Fernando Carreiro, 2023.02.24 17:23

Yes, but I not always. I don't know the exact conditions for it to be recreated.

All I know is that it happened to me often on both MT4 and MT5 in the past, until I started making sure to initialise at runtime instead of only declaratively.

EDIT: It also sometimes happened on Indicators when they reload on a chart due to a recompile. Again, not always, but sometimes.

 
Thanks for all the responses. I feel the problem is that in optimization phase the real ticks are not being loaded exact same as in single test mode.
 
If i choose not to use real ticks then it works fine. This means the problem with globally scoped variables cannot be the problem. At least in my EA.
 
Yashar Seyyedin #:
Thanks for all the responses. I feel the problem is that in optimization phase the real ticks are not being loaded exact same as in single test mode.

Why ?

Forum on trading, automated trading systems and testing trading strategies

MT5 tester bug: same conditions, different results

Alain Verleyen, 2023.06.13 20:13

Can you reproduce it, if you run an other optimization with other magic numbers, do you still have such outlier ?

If you do the same with a standard EA provided with the platform (Moving Averages for example), do you still have this issue ?


 
Alain Verleyen #:

Why ?


You are right. I tested with another EA and no problem with that.

 
Yashar Seyyedin #:

You are right. I tested with another EA and no problem with that.

check global variables if you have any in code.

try to delete them all inside of OnDeinit function with reason value = 1 or 4. this helped me most of times. 

 
I got the same problem when testing my EA, when investigating I found out there is a lot of reasons that can cause this problem
1. Bug on the usage of 
MQLInfoInteger(MQL_VISUAL)

or similar statements

2. Wrong buffer constant(this was my case)

CopyBuffer(handle_KAMAs[SymbolLoop], 0, bufferKAMA, numValuesNeeded, CurrentSymbol, "KAMA")

instead of 

CopyBuffer(handle_KAMAs[SymbolLoop], 1, bufferKAMA, numValuesNeeded, CurrentSymbol, "KAMA")

when filling indicators copied values

3. Conflicts/Bug on global variables and indicators handles. Try to delete them after use 

Reason: