$ £ ¥
¥ £ $

Error 4107 in MT4 (MQL4)

Error 4107 is a so-called MQL4 runtime error that is similar to OrderSend Error 129 but, unlike the latter, appears usually during backtesting of MT4 expert advisors, not during their live or demo run.

Sometimes, it can also appear in non-backtesting situations, both in OrderSend() and 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:

  • Negative values in price, stoploss or takeprofit parameters of the OrderSend() or OrderModify() function.
  • Unnormalized doubles in price, stoploss or takeprofit parameters of the OrderSend() or OrderModify() function.

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 OrderSend() or OrderModify():

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.