Optimization results inconsistent with backtest of strategy tester

 

Hello,

I just optimized an EA of mine using the MQL Cloud Network. When I backtest the EA using those optimized parameters, the backtest results differ drastically from those reported by the optimizer.

Example:
In the optimization results, a big profit is reported for a given set of parameters, but when I use those same parameters as inputs of a backtest in the strategy tester, a loss occurs.

Did this ever happen to anyone of you and if so, how did you fix it? Do you know what could cause such issues?

Best regards,

Tobias

 
TobiasBecker: I just optimized an EA of mine using the MQL Cloud Network. When I backtest the EA using those optimized parameters, the backtest results differ drastically from those reported by the optimizer.

Example:
In the optimization results, a big profit is reported for a given set of parameters, but when I use those same parameters as inputs of a backtest in the strategy tester, a loss occurs.

Did this ever happen to anyone of you and if so, how did you fix it? Do you know what could cause such issues?

This is can be caused by coding bugs or issues in the EA, usually involving not properly setting initial values of global variables in the OnInit() event handler. It can also be caused by corrupted "cache" files.

However, in the case of MT5, it could also just be an "error" in your own vision, because you may be looking at the "Result" column (which is a combination of values), instead of looking at the "Profit" column, in the "Optimization Results" table.

 
Fernando Carreiro:

This is can be caused by coding bugs or issues in the EA, usually involving not properly setting initial values of global variables in the OnInit() event handler. It can also be caused by corrupted "cache" files.

However, in the case of MT5, it could also just be an "error" in your own vision, because you may be looking at the "Result" column (which is a combination of values), instead of looking at the "Profit" column, in the "Optimization Results" table.


First of all, thank you for your answer.

I have used the optimizer with the same EA before and the results were consistent back then, so I believe there is no such bug inside of the EA.
It was indeed the "Profit" column I looked at, and those results listed there did not match the tester results.

Could you tell me how to fix the issue if it is caused by corrupted cache files, as you mentioned?

Thank you in advance,

Tobias

 
TobiasBecker: I have used the optimizer with the same EA before and the results were consistent back then, so I believe there is no such bug inside of the EA.

It was indeed the "Profit" column I looked at, and those results listed there did not match the tester results.

Could you tell me how to fix the issue if it is caused by corrupted cache files, as you mentioned?

The cache file problem occurs more often in MT4, so just to be clear, is this MT4 or MT5?

In both cases, if you use "File"->"Open Data Folder" and then navigate to the "tester" directory, and there you will find a sub-directory called "cache" (on MT5) or "caches" (on MT4). Just delete the contents of those directories.

However, don't be so quick to dismiss the "code bug" possibility. It can come up in the most unexpected ways, even if you never noticed it happen before. So, if you delete the cache files and the problem persists, then you can be almost sure that it is indeed a code problem.

 
TobiasBecker:

Hello,

I just optimized an EA of mine using the MQL Cloud Network. When I backtest the EA using those optimized parameters, the backtest results differ drastically from those reported by the optimizer.

Example:
In the optimization results, a big profit is reported for a given set of parameters, but when I use those same parameters as inputs of a backtest in the strategy tester, a loss occurs.

Did this ever happen to anyone of you and if so, how did you fix it? Do you know what could cause such issues?

Best regards,

Tobias

Which MT5 version are you using ?

Are you sure all initial values (input and trading environment are the same).

If all the inputs are the same, the output should be the same. If you are using a beta version it could be an MT5, otherwise it could be a typo or some input you didn't think about (conversion rate or stops level...). And finally it could be a bug as Fernando said.

 

I am running on MT5 and just deleted the "cache" folder. Directly after that, there was an update available, which I installed. After restarting the terminal, I tried the old optimization results, which were inconsistent again.

However, after rerunning the optimizer the new optimization results are consistent, the problem seems to be solved. I have no Idea however, if the problem was solved by updating the terminal or if it was solved by deleting the cache files.

 

On the first call the synchronization get's initialized so that it could be used on your second try after the update.

 

Hi, guys!

Recently I've been through a similar issue. Running the optimization using genetics could be a possibility for causing this divergence?

I haven't tried deleting the cache file which Fernando say yet, but I'm using MT5 version 5.00 and something maybe relevant happens: after running the backtest with the optimized set and noticing this divergence, I tried kind of a limited optimization checking only one parameter and modifying it the fewer times possible. In the log window, a warning saying that genetic mode has been disabled due to the low amount of parameters to be optimized so MT5 started running a complete optimization. The result was exactly the same as the backtest. Some pictures below may explain better what I'm trying to say.

Set which I've chosen to be the best of the first optimization


Result when running the backtest using the set above


Screen of the input parameters of the "limited optimization"


Result of "limited optimization". Pass 2 is the combination of the set used in the second picture that is showed here


I'm really fresh and trying to fully understand how this optimization and statistics work. Any help is welcomed.

Thank you, guys!

Best regards.

 
Fernando Carreiro:

The cache file problem occurs more often in MT4, so just to be clear, is this MT4 or MT5?

In both cases, if you use "File"->"Open Data Folder" and then navigate to the "tester" directory, and there you will find a sub-directory called "cache" (on MT5) or "caches" (on MT4). Just delete the contents of those directories.

However, don't be so quick to dismiss the "code bug" possibility. It can come up in the most unexpected ways, even if you never noticed it happen before. So, if you delete the cache files and the problem persists, then you can be almost sure that it is indeed a code problem.

Thank you, you  helped me with my issue. It was indeed a coding issue with the variables being used through all the optimisation runs. 
Reason: