Error 4107 is a
Sometimes, it can also appear in non-backtesting situations, both in
OrderModify() functions. The error is called ERR_INVALID_PRICE_PARAM (Invalid price) in the MT4 documentation; it has no counterpart in MT5.
There are two main reasons for this 4107 error to appear:
To solve the issue in any of the two cases, you will need an .mq4 file with the source code of the expert advisor. Unfortunately, you won't be able to fix MT4 Error 4107 if you only have an .ex4 file.
If it is the first case — negative values — just make sure you pass the valid price parameters to your order opening or modification functions. These parameters surely shouldn't be negative.
In case of unnormalized doubles, if your Forex broker uses 4 decimal places in its quotes and you are trying to use 5 decimal places in your orders, then you will be getting error 4107 during backtesting. The best solution here is to always normalize all the price doubles using the standard MetaTrader function before passing them to
OpenPrice = NormalizeDouble(OpenPrice, Digits); StopLossPrice = NormalizeDouble(StopLossPrice, Digits); TakeProfitPrice = NormalizeDouble(TakeProfitPrice, Digits); OrderSend(Symbol(), OP_BUY, 1, OpenPrice, StopLossPrice, TakeProfitPrice, ...);
If you have your own ideas for dealing with MT4 Error 4107 or have some questions about it, feel free to join our Forex forum to discuss them.
If you want to get news of the most recent updates to our guides or anything else related to Forex trading, you can subscribe to our monthly newsletter.