The MQL4 OrderSend Error 4107 mainly occurs during an Expert Advisor (EA) backtesting in the MT4 platform. It refers to an invalid price issue in the OrderSend function that prevents your EA from reading the price data correctly.
An automated trading system may fail to recognize the MT4 price quote for multiple reasons. However, fixing such issues is not as complex as we might think. This guide will explain what is MQL4 OrderSend Error 4107 and how to fix it within a few simple steps.
What is MT4 (MQL4) Error 4107?
MT4 error 4107 is an MQL4 runtime error that refers to an invalid price parameter of the expert advisor.
It means your EA is not reading the ask/bid rate provided by the MT4 system as a valid price. Whenever the system encounters an invalid price for the OrderSend function, it stops working and sends the error code.
Generally, we experience the MT4 OrderSend error 4107 while performing the backtest of EAs. However, your system may send the same error code due to OrderSend and OrderModify function failures. In such a case, the platform displays ERR_INVALID_PRICE_PARAM to address the invalid price issue.
Why does MT4 (MQL4) error 4107 happen?
MQL4 error 4107 happens due to the following reasons:
- Negative value issue: When your EA uses an invalid price parameter, it may read the MetaTrader 4 quotes as invalid prices and display “error 4107 – invalid price for OrderSend function.” An invalid price parameter means the order execution price requested by the EA is not matching the current ask/bid rate. A negative value issue may also affect buy-stop, sell-stop, stop-loss, and take-profit parameters of the OrderSend or OrderModify functions.
- Unnormalized doubles: If your expert advisor tries to place a five decimal price order in a 4-digit MT4 terminal, you will still encounter MQL4 OrderSend error 4107. In this case, the EA finds the 5th decimal missing in the MetaTrader price quote and eventually considers it an invalid price for order executions. Like negative values, unnormalized doubles also affect your automated trading program’s OrderSend and OrderModify functions.
How to fix MT4’s OrderSend error 4107 in MQL4?
Time needed: 5 minutes
- Check the price parameters of the EA:
Make sure your expert advisor is not applying negative parameters in the order opening and modification functions. You may consider checking the RefreshRates, OrderSend, OrderModification, ask/bid point limits, and stop-loss functions to ensure a valid price parameter.
Moreover, some brokers allow the take profit target and stop-loss settings or modification only after activating an order. In that regard, an EA should request an order activation and TP/SL parameters only after executing an entry successfully.
If you want your EA to open orders without a TP or SL, try the following settings in the OrderSend function:
- Normalize price doubles:
Both the EA and MetaTrader4 terminal should be using the same digit price to avoid unnormalized doubles. Therefore, consider normalizing all the price doubles by using the standard MT4 functions:
- Consider changing the broker:
If you want to fix the MQL4 OrderSend Error 4107 without modifying your EA, then consider switching to a 5-digit broker.