MT5 tester bug: same conditions, different results - page 2

 
Alexander Kalinkin #:

Hi Sergey,

Yes, my EA works on every tick. However, I use time range with latest date in the past (e.g. 01.01.2016-05.05.2023) so the MT should not add automatically new ticks to the testing volume.

Please find below the example: I ran optimization with change in only magic number. All the results but one are the same, one is wrong.


What's wrong here? Why one result is different? It's only magic number, nothing more.
If I re-run this one (double-click and run the single test) this will show normal result as others (958 trades). But here in optimization results it is obviously wrong.

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 ?

 

The thread with good discussion and some ideas related to the subject of the thread:
different results in optimization and single test  

For example - look at key post of the thread:

Forum on trading, automated trading systems and testing trading strategies

different results in optimization and single test

Fernando Carreiro, 2023.06.21 16:21

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.


different results in optimization and single test
different results in optimization and single test
  • 2023.06.21
  • www.mql5.com
Hello everyone. I do optimization based on real ticks...
 
Alain Verleyen #:

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 ?

Hi Alain,


Thanks for the idea.

No, I was not able to reproduce it with a simple open-sourced EA ( Moving Averages from the MT basic package).
Have no idea why at some single tests within optimization array sometimes the tester doesn't use all the available tick history.

 
Sergey Golubev #:

The thread with good discussion and some ideas related to the subject of the thread:
different results in optimization and single test  

For example - look at key post of the thread:


Hi Sergey,


Many thanks, I will study all the threads above.

 
Alexander Kalinkin #:

Hi Alain,


Thanks for the idea.

No, I was not able to reproduce it with a simple open-sourced EA ( Moving Averages from the MT basic package).
Have no idea why at some single tests within optimization array sometimes the tester doesn't use all the available tick history.

How do you know that ?

 
Alain Verleyen #:

How do you know that ?

Hi Alain, 

Just a guess from my side. I see that in general EA works as it should, just there were much less trades that in other similar single tests. Re-run of a such "faulty" test as a single test usually gives correct results. 
 

Hey guys, 

Have you found a solution for this?

I reproduce it with a simple EA - check this thread : https://www.mql5.com/en/forum/463308#comment_52588654

As soon as I use a higher timeframe I am able to reproduce it. 

I am using broker data, I will check if using third party data would have an effect or not. 

Metadrader handling weirdly data read from different time frame
Metadrader handling weirdly data read from different time frame
  • 2024.02.29
  • Grap the Trade
  • www.mql5.com
Hi, I was optimizing an EA and noticed that with the same parameters, I had different results...
 

I was having the same issue when optimizing symbol WIN$D in Brazilian market, which has tick size of 5.

But it was intermittent. At the result table, some results when I ran single test, the output was the same, some were different. Sometimes they were all correct.

I did several fixes but none worked, like deleting some cache files, only using local farm, or only local processor, checking my code for uninitialized variables or structures, etc.

Until I saw on test log that some tests had this error of invalid price, due to price no multiple of 5 (tick size):

failed exchange buy 5 WIN$D at 136712, close #2 sell 5 WIN$D.15R 136500 [Invalid price]

The weird part was this didn't happen all the times, considering same symbol, same EA, same parameters. I don't understand why sometimes MT5 sends correct price and other times don't. Testing with market closed, in history, with no prices changing. So seems like a bug to me.

Well, the fix was to adjust the price to me multiple of tick size, to use in all calls, like position open, position modify, etc. A function as simple as this:

double AdjustPriceTick(double price)
{
   double tick_size = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
   return MathRound(price/tick_size)*tick_size;
}
  

I always used this fix so I didn't understand why this issue was happening. I use CTrade class, so all prices in Buy, BuyLimit, BuyStop, Sell, SellLimit, SellStop, PositionModify functions I pass it adjusted.

The problem was on PositionClose function, which doesn't have a price argument, and it was sending orders with incorrect price.

So to fix it, I copied Trade/Trade.mqh to Include folder with a different name and modified PositionClose function to adjust price to close positions.

And DONE, no more errors or different results!!

 

I experienced the same issue with the optimization results showing different (more) profits than the actual single tests and different drawdown, sharpe ratio and all the other values.

For me the problem was starting the optimization on a Saturday, when the markets are closed and it looks like my broker is feeding different tick values into MT5 over the weekend. Once the market opened I reoptimized and then the single test are showing the same profits and values as the optimization list.

I don't know why the tick data is different though over the weekend and closed markets, maybe someone has more knowledge and can shed some light on this issue..
Processing optimization results using the graphical interface
Processing optimization results using the graphical interface
  • www.mql5.com
This is a continuation of the idea of processing and analysis of optimization results. This time, our purpose is to select the 100 best optimization results and display them in a GUI table. The user will be able to select a row in the optimization results table and receive a multi-symbol balance and drawdown graph on separate charts.