$ £ ¥
¥ £ $

OrderSend Error 129 (Invalid Price)

When using some MT4 expert advisors, you might have encountered a rather annoying error message, which reads OrderSend Error 129. This error should be avoided during the EA’s creation, but even if you aren’t the author of the problematic EA, this error is rather easy to fix. OrderSend Error 129 in MetaTrader 4 platform is internally called ERR_INVALID_PRICE ("Invalid Price"), which means that an expert advisor is trying to open an order with an invalid current price. In MetaTrader 5, this error is represented by the return code 10015 (TRADE_RETCODE_INVALID_PRICE) when sending a trade request using the OrderSend() function. There are two possible reasons for this error and, respectively, two solutions.

The first reason can be that the price (Ask or Bid), which is used in the OrderSend() function call, is different from the current market price and this difference is greater than the Slippage parameter of the OrderSend() function. In this case, the problem usually lies in the fast market price action, which requires a price refresh inside MT4 immediately before calling the OrderSend() function. Just add this line of code before every OrderSend call:

If this is the only error popping up with this EA, it is also a good idea to use a cycle that will try several RefreshRates() and OrderSend() calls for higher reliability:

int count = 0;
while ((result == -1) && (count < 10))
        result = OrderSend(...);

You can use any other value instead of 10 to increase the number of tries. But if 10 tries isn’t enough, then your broker’s MT4 server is probably too slow to trade with this EA at all.

In MT5, there is no RefreshRates() function, but the issue can be solved in a similar manner — a call to the symbol's current Ask or Bid price should be positioned as close to the OrderSend() function as possible. For example, a piece of code like this:

double Bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
PositionSize = (AccountInfoDouble(ACCOUNT_BALANCE) * Risk / 100) / (SL * Point() * SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE) / SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE));
Trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, Lots, Bid, StopLoss, TakeProfit, Commentary);

...becomes this:

PositionSize = (AccountInfoDouble(ACCOUNT_BALANCE) * Risk / 100) / (SL * Point() * SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE) / SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE));
double Bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
Trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, Lots, Bid, StopLoss, TakeProfit, Commentary);

The second reason is more trivial and is easier to fix than the first one. The price that is sent with the OrderSend() function should be normalized to the standard of rates that is used in your broker’s MT4 server. For example, if you try to use a price like 1.23339 to open a EUR/USD position when the current EUR/USD rate at your broker is 1.2334, it won’t work because your order open price isn’t normalized. If your broker uses 5 decimal places quotes for EUR/USD, then sending a price like 1.2334 when the actual rate is 1.23345 will also generate an OrderSend Error 129.

In any case, you should use NormalizeDouble() function to fix the open price before sending it to your broker. It takes two parameters: the first one is the value you want to normalize (the price), the second one is the number of digits after the decimal separator in the resulting number. Here is an example of its usage for brokers with 5 decimal places quotes (e.g., 1.23345 for EUR/USD):

OpenPrice = NormalizeDouble(OpenPrice, Digits());
OrderSend(Symbol(), OP_BUY, 1, OpenPrice, ...);

It is also a good idea to normalize all your StopLoss and TakeProfit values before using them in the OrderSend() function. This is a good coding practice even if you don’t get any Error 129 messages.

Of course, this probably doesn't cover all the possible ways of handling an OrderSend Error 129, but the proposed solutions should work in the majority of cases. If you have any thoughts, comments, or questions regarding MT4 Error 129 (or MT5 Error 10015) and the ways to solve it, feel free to share them on our forum.