Skip to content

Trade server return code

10029 TRADE_RETCODE_FROZEN

Order or position frozen: too close to its trigger to change

What it means

The order or position cannot be changed right now because the price is within the symbol's freeze level of the level you want to move (SYMBOL_TRADE_FREEZE_LEVEL, "Distance to freeze trade operations in points"). Near its trigger, the server locks a stop, target or pending price so it cannot be pulled away at the last moment.

Common causes

  • A trailing stop or break-even step that tries to move a stop loss the price has almost reached.
  • Moving a take profit that is a few points from the price.
  • Deleting or moving a pending order that is about to trigger.
  • Brokers that widen the freeze level around news.

A real scenario

During a news spike a trailing stop tries to move the stop loss of a buy while the Bid is 15 points above it, and the broker's freeze level for the symbol is 20 points. The modification fails with 10029; the EA retried on each tick and added 10024 to it. Checking the freeze level first lets the EA skip those ticks and try again once the price has moved away.

How to fix it

  1. Read SYMBOL_TRADE_FREEZE_LEVEL and the current price before changing a stop, target or pending order.
  2. If the price is within the freeze distance of the level, skip the change for now.
  3. A freeze level of 0 means no freeze distance is set.

Fixed MQL5 code

MQL5
bool OutsideFreezeLevel(const ulong ticket)
{
   if(!PositionSelectByTicket(ticket))
      return false;
   double freeze = (double)SymbolInfoInteger(_Symbol, SYMBOL_TRADE_FREEZE_LEVEL) * _Point;
   if(freeze <= 0.0)
      return true;                                  // no freeze distance on this symbol
   bool   isBuy = PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY;
   double price = isBuy ? SymbolInfoDouble(_Symbol, SYMBOL_BID) : SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double sl    = PositionGetDouble(POSITION_SL);
   double tp    = PositionGetDouble(POSITION_TP);
   if(sl > 0.0 && MathAbs(price - sl) <= freeze) return false;
   if(tp > 0.0 && MathAbs(price - tp) <= freeze) 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 10029? 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.