strange problem: strategy tester (optimizer) MINIMIZES instead of maximizes result (MT5, build 2085), HELP NEEDED

 

I've got a strange problem with the strategy optimizer recently: it starts the first few iterations with results that make sense, from then on all results go down to the minimum, like this:

optimizer results

It happens with different EAs, so it shouldn't have to do anything with the specific code. What is further strange: this minimization happens early on, within the same generation, whereas the first generation shouldn't be completed usually before 512 passes (core-8, 8x64 passes).

The results of the individual passes shouldn't be interdependent before a generation is complete (at least if it doesn't have to do with memory issues e.g.). I get no errors on the optimizer journal, nor in the logs of local agents. I use only local agents.

I work a lot with OOP and the objects can contain larger arrays, but I don't declare any objects via pointer and the "new" function, so it shouldn't be the case of missing objects deinitializations, if that's your thought.

I use the Metatrader 5 with the newest build 2085 (13 Jun 2019).


Another strange thing: if I store the results into a csv-file upon deinitialization, I see that for those results that were extremly bad (=basically account down to zero), the official result put out by the strategy tester is just balance=initial balance, 0 trades, whereas in reality the EA could count many trades with a balance close to zero in the end.


As optimization criterion I usually use the "custom max" option, which just puts out the result of a formula for the net result (profits + swap - losses - commissions), but the problem is just the same if I just use the built-in "max balance".


I'm really running out of ideas here and need some help - thankful for any inspiration!


(on a side note: as posted elsewhere I also have my own library for custom genetic optimization, but this was NOT in use in the mentioned cases). 

 

in this example you can see, that the minimization process starts shortly after the beginning of a generation:

optimizer results

 

I use "real tick data" by the way..

and this is an example if I just use "max balance" as optimization criterion (all those data points at the level of the initial balance are not correct! in reality many trades were simulated during those tests and the result should be close to zero balance)

optimizer result with max balance

 
Without posting a test case code to reproduce the issue, I doubt you will get useful help.
 

The code that caused the issue has about 4000 lines, that's one reason why I didn't post it here. Apart from that, I saw the same problem with old EAs that I didn't backtest for months and that worked flawlessly in the past (under earlier MT5 versions), so it had to do with my individual style of coding AND changes in the new MT5 build. They explicitly mention, that the optimization algorithm has been profoundly changed. Thanks for answering nevertheless.

I could resolve parts of the problem in the meantime: it seems to have to do with the declaration of variables within classes. I know that it is common, that array elements can (or usually do) contain garbage bytes if they are not initialized with a value, e.g. using the ZeroMemory() function. This is why I ALWAYS initialize arrays (not talking about dynamic size but the stored element values) - otherways errors are for sure. With normal variables I'm used to them being automatically assigned with "0" or "false" for bool or empty string "" for string variables, even if I don't explicitly assign a value in the class constructur. However, if I run the strategy optimizer, the auto-assignment of "0" only happens periodically, sometimes it works, sometimes it doesn't. I don't know why that is and I'm not used to this from previous MT5 builds. Maybe it has something to do with timing between destructor calls and initializiation of the next EA instance when that CPU-core is done with that pass? I know this doesn't make sense 100%, but there must be a reason why the first passes per core always work correctly.

Because of this matter, my own tracking of performed trades and other account statistics went wrong and the EA sometimes didn't count the trades from zero. This is why I had a discrepancy between official trade numbers and my own counting. This is now resolved by explicitly initializing every single variable (not only arrays) to "0" in the constructor.

However, the strange behaviour that I still often get "0" official trades in those cases where the account went to almost 0 still remains. I can even protocol those trades with exact entry and exit prices into a file, so those trade DO exist. However - this is not really a problem, because settings that kill the account are useless for trading anyways. Only I think that the genetic algorithm should need correct figures, cause there is still a difference between -1000 and -10000 € that should be accounted for for the genetic "fitness" of a pass.

So for myself the thread can already be closed, but maybe it is still useful for somebody in the future who observes the same behaviour.

Reason: