
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
I have found same problem. I tested and the it seems to be missing ticks:
https://www.mql5.com/en/forum/360252
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!!