Skip to content

Trade server return code

10016 TRADE_RETCODE_INVALID_STOPS

Invalid stops: SL or TP too close to the price or on the wrong side

What it means

The stop loss or take profit in the request is not allowed. A stop must be on the correct side of the price at which the position closes, and at least SYMBOL_TRADE_STOPS_LEVEL points away from it ("Minimal indention in points from the current close price to place Stop orders"). In the journal it usually appears as "OrderSend error 4756" followed by "retcode=10016".

Common causes

  • A stop or target closer to the price than the stops level, for example a tight scalping stop on a symbol with a 30-point level.
  • A stop on the wrong side: a buy's stop loss above the Bid, or a sell's take profit above the Ask.
  • Distances in pips used as points (or the reverse) on 5-digit and 3-digit quotes.
  • Stops measured from the open price instead of the price the position closes at (the Bid for a buy, the Ask for a sell).

A real scenario

A scalping EA ported from MQL4 sets a 2-pip stop loss on GBPUSD. On the new broker the stops level is 30 points (3 pips), so every entry comes back with 10016, which the MQL4 version had reported as error 130. The EA now reads the stops level and widens the stop to it, or skips the trade when the strategy cannot accept the wider stop.

How to fix it

  1. Read SYMBOL_TRADE_STOPS_LEVEL and the current tick before setting stops.
  2. For a buy, compare the stop loss and take profit with the Bid; for a sell, with the Ask.
  3. A stops level of 0 means the broker sets no fixed minimum, but the stop must still be on the correct side.
  4. Normalise stops to the symbol's digits, and widen or skip rather than send a request you know will fail.

Fixed MQL5 code

MQL5
bool StopsValid(const ENUM_ORDER_TYPE type, const double sl, const double tp)
{
   MqlTick t;
   if(!SymbolInfoTick(_Symbol, t))
      return false;
   double minDist = (double)SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL) * _Point;
   if(type == ORDER_TYPE_BUY)
   {
      // a buy closes at the Bid: SL below it, TP above it, both at least the stops level away
      if(sl > 0.0 && t.bid - sl < minDist) return false;
      if(tp > 0.0 && tp - t.bid < minDist) return false;
   }
   else if(type == ORDER_TYPE_SELL)
   {
      // a sell closes at the Ask: SL above it, TP below it
      if(sl > 0.0 && sl - t.ask < minDist) return false;
      if(tp > 0.0 && t.ask - tp < minDist) return false;
   }
   return true;
}

A focused example for MetaTrader 5: adapt names, magic number and limits to your EA, and test it on a demo account first.

EA Doctor rules that catch it

Sources

Get your EA fixed

Still failing with 10016? Send us the EA and the journal lines: we find the cause in the code and fix it. Or check it yourself first with the EA Doctor.