A trailing-stop calculation may produce a mathematically reasonable price that the broker refuses. MT4 exposes stop and freeze distances in points, and they must be distinguished from pips. A robust EA separates the proposed stop from validation and actual modification.
Example: a five-digit EURUSD quote
Assume Bid=1.10500, Point=0.00001, minimum stop distance 30 points, freeze distance 20 points, and an existing buy stop at 1.10400. Candidate 1.10490 is 10 points away and fails. Candidate 1.10470 is exactly 30 points away, a boundary that may be affected by floating-point representation or price movement. Candidate 1.10450 is 50 points away and improves the existing stop while passing the nominal checks.

Validate before OrderModify
The illustrative excerpt runs in OnTick after selecting the intended market buy order by ticket and checking symbol and magic number. candidateSL is supplied by the trailing calculation. The code deliberately does not handle other symbols or sell positions.
// Selected BUY order on current chart symbol only
RefreshRates();
double pt = MarketInfo(Symbol(), MODE_POINT);
int digits = (int)MarketInfo(Symbol(), MODE_DIGITS);
double sl = NormalizeDouble(candidateSL, digits);
double distance = (Bid - sl) / pt;
double minStop = MarketInfo(Symbol(), MODE_STOPLEVEL);
double freeze = MarketInfo(Symbol(), MODE_FREEZELEVEL);
if (sl > OrderStopLoss() && sl < Bid &&
distance >= minStop && distance > freeze)
{
ResetLastError();
if (!OrderModify(OrderTicket(), OrderOpenPrice(), sl,
OrderTakeProfit(), 0, clrNONE))
Print("Modify failed: ", GetLastError());
}
For sells, measure distance from Ask to the proposed stop and require the stop to tighten downward, handling the zero-stop case separately. Normalizing decimal digits alone may not align prices to every instrument's tradable tick grid. Validate the tick size as well. A zero MODE_STOPLEVEL can still represent dynamic server restrictions. Freeze restrictions may affect other order levels or operations; this check is not an exhaustive server-side validation.
Operational checks
- Only modify when the stop tightens by a meaningful increment; avoid repeated requests with effectively unchanged values.
- Log old stop, proposed stop, current bid/ask, stop and freeze levels, ticket and error code.
- On errors such as invalid stops or modification denied, refresh prices and re-evaluate on a later eligible tick. Never silently widen the protective stop just to force acceptance.
- Test boundary values, spreads, price gaps and broker-specific dynamic restrictions in a demo environment. Historical testing may not reproduce server rejection behavior.
Official reference: MQL4 symbol properties.
This hypothetical teaching excerpt has not been compiled or backtested here. Trading involves risk of loss; simulated results do not guarantee future performance.
To adapt this free strategy idea to your trading rules, contact us about Custom MT4 strategy Development Services.