Forex Blog

First-hand Forex trading experience and information about foreign exchange market that will be useful to traders

Archives

OrderSend Error 129 — What to Do?

May 3, 2009 (Last updated on March 28, 2016) by

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:

RefreshRates();

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))
{
	RefreshRates();
	result = OrderSend(...);
	count++;
}

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.

14 Responses to “OrderSend Error 129 — What to Do?”

  1. Zach

    Thanks a lot mate. This was very, very helpful. I had been back and forth with this all night. I implemented both of your suggestions and it worked for me.

    Reply

    Andrei Reply:

    I am glad that I helped you :).

    Reply

  2. luke

    Excellent Article!

    Inserting RefreshRates(); before the OrderSend did the trick. The normalization process was not necessary in my case

    Reply

    admin Reply:

    Glad to help!

    Reply

  3. Wasseem

    very helpful mate.
    good to know people like you are around.

    Reply

  4. Dave

    Thanks for the tips Refreshrates and normalizedouble works with error 129 !
    Thanks a lot !
    Dave

    Reply

  5. frank

    I have tried a free Ea called Pseudocarcharias or forex wonder. It has returned error 129 during fast price change. I have no idea how to insert or where to insert the recomended changes. Would you know of a service that could modify the EA for me.
    Thanks Frank

    Reply

    admin Reply:

    If you have the EA’s source code (.mq4 file) then you can ask on a Forex forum. Perhaps someone will be able to help you there.

    Reply

  6. Payam

    Thanks very helpful!

    Reply

    Andriy Moraru Reply:

    You are welcome! I would appreciate if you could tell us more of how the post has helped you.

    Reply

  7. RobotFX

    I wonder if we need to Normalize the Ask or Bid when sending simple orders. Now I have this:
    BuyTicket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,Slippage*Pipmulti,0,0,TradeComment,MagicNumber,0);
    It works fine. What do you say?

    Reply

    Andriy Moraru Reply:

    Sometimes it works just fine without normalization, but sometimes it will produce an error. Better be safe than sorry. I recommend adding NormalizeDouble() function to all calculated price levels in order to avoid Error 129.

    Reply

  8. Ruud F. de Graaf

    I have implemented all three methods in my EA a half year ago, but I still get this error sometimes. Could it be because NormalizeDouble leaves sometimes a very small amount after normalization like 1.000000001 or 0.9999999999?

    Reply

    Andriy Moraru Reply:

    If you could share the code and the Experts/Journal logs where the error appears, it would definitely help me to help you in this regards.

    Reply

Leave a Reply

required
required (will not be published)
optional