$ £ ¥
¥ £ $

OrderSend Error 138 (Requote) in MT4

What is MT4 error 138?

OrderSend Error 138 (or ERR_REQUOTE) may appear during the execution (but not backtesting) of MetaTrader expert advisors. This error appears only in MT4 as the MetaTrader 5 platform uses a different system of OrderSend error codes. Error 138 means that the broker replied with a "Requote" signal to your expert advisor's OrderSend() function call. In other words, the price used in the order is outdated compared to the current market price.

Also, error 138 can appear as a result of the OrderClose() function call if it is performed with an outdated or wrong price.

Why does MT4 error 138 appear?

There are two main reasons for this error to appear:

  1. The order price is completely outdated and is not present in the recent quotes. The order will not be executed (and the error 138 will be generated) even if the current market price is within the given Slippage from the order price.
  2. The order price is present in the recent quotes but differs from the current market price by more than the given Slippage parameter.

How to fix OrderSend error 138 in MT4?

To avoid getting OrderSend Error 138 from your expert advisors, you have to use RefreshRates() function call immediately before calling OrderSend() function and before you use the Ask/Bid to calculate parameter values for OrderSend() function. This will save you from the first of the above-listed cases. However, if your broker is experiencing some technical problems, this won't help and the error may still appear — there is little you can do in that case.

Here is an MQL4 example of how this is handled in the Chart Pattern Helper EA's code:

// Get current market prices.
// Calculate volume based on the current Bid.
NewVolume = GetPositionSize(Bid, LowerSL);
// Send a Sell order at the current Bid price.
LowerTicket = OrderSend(Symbol(), OP_SELL, NewVolume, Bid, Slippage, LowerSL, LowerTP, "ChartPatternHelper", Magic);

Additionally, you should specify a rather large slippage in the parameters of the OrderSend() function to prevent error 138 from appearing during very volatile conditions. Even if you use the RefreshRates() function, there is a possibility that prices will change between the call of RefreshRates() and the execution of OrderSend(). Setting a tolerable slippage of 5&ndas;10 pips (normal ones, not fractional) will allow your expert advisors to execute orders without requote errors. Of course, if you are scalping or otherwise aiming for small profit targets, you should set a much smaller slippage parameter and bear with the error 138 and failed orders. As an alternative solution, you can always switch your Forex broker to one with less slippage and fewer requotes.

How to fix OrderClose error 138 in MT4?

With OrderClose(), it is usually much simpler — you just have to make sure that you are closing Buy orders using the current Bid price, and Sell orders using the current Ask price. If you encounter MQL4 error 138 with OrderClose(), check if you are sending the correct variable for a price parameter.

Here is an example of a correctly set up OrderClose() call to close out a trade from our News Trader EA:

// Get current market prices.
// Select the correct price.
if (OrderType() == OP_BUY) price = Bid;
else if (OrderType() == OP_SELL) price = Ask;
if (!OrderClose(OrderTicket(), OrderLots(), price, Slippage, clrBlue))
        Print("OrderClose() failed: ", GetLastError());

If you have any thoughts, comments, or questions regarding MT4 OrderSend Error 138 and the ways to fix it, feel free to discuss it on our forum with other traders and MQL4 developers.

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.