EA Doctor rule · Prices and stops
Changes near the price without the freeze level check
The EA modifies stops or deletes orders without reading the freeze level, inside which the broker refuses changes with 10029.
Why it matters
Close to the price that would trigger them, the broker can freeze orders and positions: within SYMBOL_TRADE_FREEZE_LEVEL points, a pending order cannot be modified or deleted and a position's stop loss and take profit cannot be changed. The server answers 10029 (frozen).
Trailing stops and order managers that move levels near the market meet it first, often in fast markets when the level is raised.
When the rule fires
The EA modifies or deletes (PositionModify(), OrderModify(), OrderDelete(), TRADE_ACTION_SLTP, TRADE_ACTION_MODIFY, TRADE_ACTION_REMOVE) and SYMBOL_TRADE_FREEZE_LEVEL (or CSymbolInfo::FreezeLevel()) appears nowhere in the file.
When it stays quiet
The freeze level is read anywhere in the file, or the EA never modifies or deletes.
How to fix it
- Read
SymbolInfoInteger(_Symbol, SYMBOL_TRADE_FREEZE_LEVEL)next to the stops level. - Before a change, check that both the current level and the new one are farther from the price than the larger of the two; otherwise wait for the next tick.
Code that fires it
void Trail(const ulong ticket, const int trailPoints)
{
if(!PositionSelectByTicket(ticket))
return;
const double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
const double sl = NormalizeDouble(bid - trailPoints * _Point, _Digits);
if(sl > PositionGetDouble(POSITION_SL))
if(!trade.PositionModify(ticket, sl, PositionGetDouble(POSITION_TP)))
Print("Trail failed: ", trade.ResultRetcodeDescription());
}Fixed code
bool FarEnough(const double level, const double price)
{
const long stops = SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL);
const long freeze = SymbolInfoInteger(_Symbol, SYMBOL_TRADE_FREEZE_LEVEL);
return(MathAbs(price - level) > MathMax(stops, freeze) * _Point);
}
void Trail(const ulong ticket, const int trailPoints)
{
if(!PositionSelectByTicket(ticket))
return;
const double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
const double curSl = PositionGetDouble(POSITION_SL);
const double sl = NormalizeDouble(bid - trailPoints * _Point, _Digits);
if(sl <= curSl)
return;
// the current stop and the new one must both be outside the freeze and stops levels
if(!FarEnough(sl, bid) || (curSl > 0.0 && !FarEnough(curSl, bid)))
return;
if(!trade.PositionModify(ticket, sl, PositionGetDouble(POSITION_TP)))
Print("Trail failed: ", trade.ResultRetcodeDescription());
}The fixed code shows this rule’s fix and compiles in MetaEditor for MetaTrader 5 (with CTrade trade, InpLots and InpMagic declared, as in a typical EA). Other rules may still apply to it as a fragment: check your whole EA.
Related MQL5 errors
More rules on prices and stops
- HighStops set without the stops level checkThe EA sets a stop loss or take profit without reading the broker's minimum stop distance, which is refused with 10016 when it is too close.
- MediumPrices not rounded to the symbol's digitsA price, stop loss or take profit is computed with _Point arithmetic and sent without NormalizeDouble() or rounding to the tick size.
- MediumHard-coded point size or digitsThe code writes 0.0001 for a pip or rounds prices to a fixed number of digits, which is wrong on JPY pairs, gold, indices and crypto.
Sources
Get your EA fixed
Check a whole EA for this and 29 other mistakes with EA Doctor, free and in your browser. Or send it to us: we confirm the price in writing, then fix it.