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.

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.

© 2005–2021

Design — Mart Studio

Forex trading bears intrinsic risks of loss. You must understand that Forex trading, while potentially profitable, can make you lose your money. Never trade with the money that you cannot afford to lose! Trading with leverage can wipe your account even faster.

CFDs are leveraged products and as such loses may be more than the initial invested capital. Trading in CFDs carry a high level of risk thus may not be appropriate for all investors.