OrderSend Error 129 — What to Do?

When using some MT4 expert advisors you may have encountered a rather annoying error message, which reads «OrderSend Error 129». This error should be avoided during 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 platform is internally called ERR_INVALID_PRICE («Invalid Price»), which means that expert advisor is trying to open an order with the invalid current price. There are two possible reasons for this error and respectively two solutions.
First reason can be that the price (Ask or Bid) used in the OrderSend function is different from the current market price and theis 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 code before every OrderSend call:


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

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

You can use any other number instead of 10 to increase the amount of tries. But if 10 tries isn’t enough then your broker’s MT4 server is probably to slow to trade with this EA at all.
Second reason is more trivial and easy to fix than the first one. The price that is sent with 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 price like 1.23339 to open EUR/USD position and 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 6-digit quotes for EUR/USD then sending price like 1.2334 when the actual rate is 1.23345 will also generate 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: first is the value you want to normalize (the price), second is the number of digits after the dot in the resulting number. Here is the example of its usage for the brokers with 6-digit quotes (like 1.23345 for EUR/USD):

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

It’s 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.
I don’t know if the listed ways of handling OrderSend Error 129 are universal and are suitable for all cases but they’ve always worked for me. If you have any thoughts, comments or questions regarding MT4 Error 129 and the ways to treat it, feel free to reply to this post using the form below.

Leave a Reply

Your email address will not be published. Required fields are marked *