
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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:
For example - look at key post #2 of the thread:different results in optimization and single test
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.
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.
The thread with good discussion and some ideas related to the subject of the thread:
For example - look at key post #2 of the thread:different results in optimization and single test
Hi Sergey,
Many thanks, I will study all the threads above.
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 ?
How do you know that ?
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.
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:
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.