Invalid Stop Loss in MT5: Causes, Checks, and Fixes
By FXNook Lab team
An “invalid stop loss” in MT5 means the trading server rejected the requested SL because it did not meet the symbol’s current trading constraints. The fix is to inspect the request result, compare the stop with the current Bid or Ask and broker limits, and align it to the symbol’s tick size before sending it. A price that passes those checks can still be rejected if the quote or server-side conditions change before the request arrives.
This is a trade-request problem, not a MetaEditor compile error. A program can compile successfully and still send a request the broker will not accept. The exact retcode and message depend on the failure and the broker; for invalid stops, one common MQL5 retcode is TRADE_RETCODE_INVALID_STOPS (10016).
Read the trade result before changing code
Start with the result of the failed trade request. With the standard MQL5 CTrade class, call ResultRetcode() and ResultRetcodeDescription() after Buy, Sell, or PositionModify. The method’s Boolean return value indicates whether the request passed basic checks; it does not by itself prove that the server executed the trade.
For a direct OrderSend call, inspect the MqlTradeResult filled by that call. Its retcode and comment give the server’s result. Print the request’s symbol, order side, price, and SL alongside the result so you can tell which values the server evaluated.
PrintFormat("SL request: symbol=%s side=%s price=%.*f sl=%.*f retcode=%u (%s)",
_Symbol,
isBuy ? "BUY" : "SELL",
_Digits, requestPrice,
_Digits, stopLoss,
trade.ResultRetcode(),
trade.ResultRetcodeDescription());
The variable names in that short logging example stand for the values in your own request. In a complete EA, log the result immediately after the trade call, before another trade call replaces the last result. The Experts tab usually shows messages printed by the EA, while the Journal tab records terminal and trade events; compare both around the request time. The official list of MQL5 trade-server return codes is useful when a description is brief.
Do not treat every failed request as an invalid stop. For example, TRADE_RETCODE_INVALID_PRICE (10015) points to a price problem, while a disabled trading permission or an unsupported filling mode has a different cause. In MT4, the familiar “invalid stops” error is often error 130; MT5 uses trade-server retcodes instead. For the MT4 version of the issue, see How to Fix OrderSend Error 130: Invalid Stops in MT4.
Common causes and what to look for
| Cause | What to check | Typical fix |
|---|---|---|
| SL is on the wrong side | A buy stop loss is at or above the current Bid, or a sell stop loss is at or below the current Ask. | For a buy, place the SL below the relevant market price. For a sell, place it above. Recalculate from a fresh quote. |
| Stop distance is too small | SYMBOL_TRADE_STOPS_LEVEL reports a minimum distance in points, and the requested SL is closer than that limit. | Calculate the minimum distance using the symbol’s point size and leave at least that much room. |
| Freeze restriction affects a modification | The position or stop is close to the market while an EA tries to modify it; the symbol reports a nonzero freeze level. | Defer the modification until it is outside the restricted area. A server may apply its own exact rules, so use the returned retcode as evidence. |
| Price is not on a valid tick | The SL has the expected number of decimal places but is not a multiple of SYMBOL_TRADE_TICK_SIZE. | Round to a tradable tick. Round a buy SL down and a sell SL up, then recheck the distance. |
| Quote is stale or the wrong side was used | The EA used an old Bid/Ask, or compared a buy SL with Ask when it should have checked it against Bid. | Read a fresh MqlTick immediately before the request and use Bid for the buy-side stop check and Ask for the sell-side check. |
| Wrong symbol or position was modified | The request symbol differs from the position’s symbol, or a hedging account has multiple positions on the same symbol. | Select the intended position and use its symbol and position ticket for the modification. |
Read the symbol’s stop and tick constraints
MT5 exposes the relevant symbol properties through SymbolInfoInteger and SymbolInfoDouble. These values belong to the symbol, so do not assume that the chart symbol’s limits also apply to every instrument the EA trades. The MQL5 symbol properties reference lists the properties and their types.
SYMBOL_TRADE_STOPS_LEVELis the minimum stop distance in points. Multiply it bySYMBOL_POINTto convert the reported number into a price distance.SYMBOL_TRADE_FREEZE_LEVELis the freeze distance in points. It can restrict changing or cancelling trade instructions near the market. It matters particularly when modifying an existing position; it is not a substitute for the stop-level check.SYMBOL_POINTis the point value used for point-based distances. It is not necessarily the smallest tradable price increment.SYMBOL_DIGITStells you how many decimal places the symbol’s prices use. It helps format a price, but does not alone make that price tradable.SYMBOL_TRADE_TICK_SIZEis the minimum price change for the symbol. The requested price should land on this tick grid.
For example, normalizing a price to two decimal places does not make it valid if the instrument trades in increments of 0.25 and the normalized price is 0.10 away from a valid increment. Use tick size to align the price, then normalize for display precision and check the stop distance again. If the reported stop level is zero, that only means the property reports no fixed minimum in points; it does not guarantee that every stop will be accepted in every market condition.
For a market position, check a buy SL against the current Bid and a sell SL against the current Ask. The entry side of a market order is different: a buy generally opens at Ask and a sell at Bid. That difference is why comparing every SL to the order’s entry price can produce a misleading distance check.
Validate a stop before sending a market order
This MQL5 example reads a fresh quote, checks the correct side of the market, enforces the published minimum stop distance, aligns the SL to tick size, and logs the trade result. It uses CTrade so the filling mode can be selected from the symbol. The example sends a market order only after the local checks pass; adapt the volume and SL calculation to the EA’s own rules.
#include <Trade/Trade.mqh>
CTrade trade;
bool BuildValidSL(const string symbol,
const bool isBuy,
const MqlTick &tick,
const double requestedSL,
double &validSL,
string &reason)
{
double point = 0.0;
double tickSize = 0.0;
long digits = 0;
long stopsLevel = 0;
if(!SymbolInfoDouble(symbol, SYMBOL_POINT, point) || point <= 0.0 ||
!SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE, tickSize) ||
!SymbolInfoInteger(symbol, SYMBOL_DIGITS, digits) ||
!SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL, stopsLevel))
{
reason = "Could not read symbol trading properties";
return false;
}
if(tickSize <= 0.0)
tickSize = point;
if(isBuy && requestedSL >= tick.bid)
{
reason = "Buy SL must be below the current Bid";
return false;
}
if(!isBuy && requestedSL <= tick.ask)
{
reason = "Sell SL must be above the current Ask";
return false;
}
double steps = requestedSL / tickSize;
if(isBuy)
validSL = MathFloor(steps + 1e-10) * tickSize;
else
validSL = MathCeil(steps - 1e-10) * tickSize;
validSL = NormalizeDouble(validSL, (int)digits);
double minimumDistance = (double)stopsLevel * point;
double actualDistance = isBuy ? tick.bid - validSL : validSL - tick.ask;
if(actualDistance < minimumDistance)
{
reason = "SL is closer than SYMBOL_TRADE_STOPS_LEVEL allows";
return false;
}
reason = "OK";
return true;
}
bool SendMarketWithSL(const string symbol,
const bool isBuy,
const double volume,
const double requestedSL)
{
MqlTick tick;
if(!SymbolInfoTick(symbol, tick))
{
PrintFormat("No fresh quote for %s", symbol);
return false;
}
double sl = 0.0;
string reason;
if(!BuildValidSL(symbol, isBuy, tick, requestedSL, sl, reason))
{
PrintFormat("SL check failed for %s: %s; Bid=%.*f Ask=%.*f requestedSL=%.*f",
symbol, reason, _Digits, tick.bid, _Digits, tick.ask,
_Digits, requestedSL);
return false;
}
if(!trade.SetTypeFillingBySymbol(symbol))
{
PrintFormat("Could not set filling mode for %s", symbol);
return false;
}
trade.SetDeviationInPoints(20);
bool callOK = isBuy
? trade.Buy(volume, symbol, 0.0, sl, 0.0, "SL checked")
: trade.Sell(volume, symbol, 0.0, sl, 0.0, "SL checked");
uint retcode = trade.ResultRetcode();
PrintFormat("Trade result: symbol=%s side=%s Bid=%.*f Ask=%.*f SL=%.*f retcode=%u (%s)",
symbol, isBuy ? "BUY" : "SELL",
_Digits, tick.bid, _Digits, tick.ask, _Digits, sl,
retcode, trade.ResultRetcodeDescription());
return callOK &&
(retcode == TRADE_RETCODE_DONE ||
retcode == TRADE_RETCODE_DONE_PARTIAL ||
retcode == TRADE_RETCODE_PLACED);
}
The rounding direction is deliberate: rounding a buy SL down or a sell SL up avoids moving the stop closer to the market than the requested value. The code then checks the distance again after rounding, because tick alignment can change it. It uses the requested symbol’s point and digits when validating; adapt the log formatting too if your EA sends orders for symbols with different digits from the chart.
The example’s local check cannot reserve a price. The quote can move between SymbolInfoTick and the server processing the request, and the broker can apply current trading conditions that the EA cannot see in advance. If MT5 still rejects the trade, use the returned retcode and the logged Bid, Ask, and SL to identify what changed rather than repeatedly widening the stop without evidence.
Apply the checks when modifying a position
Initial stops and modifications are separate operations. If an EA opens a position without an SL and adds one later, run the same side, stop-distance, and tick-alignment checks using a fresh quote immediately before PositionModify. Also consider the symbol’s freeze level: a modification can be blocked while the relevant trade instruction is inside that restricted area, even when the requested stop otherwise meets the stop-distance check.
In MT5, a position has both a ticket and an identifier. For CTrade.PositionModify, use the position ticket when targeting a particular position on a hedging account. The stable position identifier is not a replacement for that ticket argument. On a netting account there is one position per symbol, while an EA written for a hedging account that expects to close or modify by ticket may select the wrong position if it uses only the symbol.
bool ModifySelectedPositionSL(const string symbol, const double requestedSL)
{
if(!PositionSelect(symbol))
{
PrintFormat("No open position found for %s", symbol);
return false;
}
ulong ticket = (ulong)PositionGetInteger(POSITION_TICKET);
long positionType = PositionGetInteger(POSITION_TYPE);
double takeProfit = PositionGetDouble(POSITION_TP);
bool isBuy = (positionType == POSITION_TYPE_BUY);
MqlTick tick;
if(!SymbolInfoTick(symbol, tick))
return false;
double sl = 0.0;
string reason;
if(!BuildValidSL(symbol, isBuy, tick, requestedSL, sl, reason))
{
PrintFormat("Position SL check failed for %s ticket=%I64u: %s",
symbol, ticket, reason);
return false;
}
bool callOK = trade.PositionModify(ticket, sl, takeProfit);
PrintFormat("Modify result: symbol=%s ticket=%I64u SL=%.*f retcode=%u (%s)",
symbol, ticket, _Digits, sl,
trade.ResultRetcode(), trade.ResultRetcodeDescription());
return callOK && trade.ResultRetcode() == TRADE_RETCODE_DONE;
}
This example assumes BuildValidSL from the previous code block is part of the EA and that the selected position is the intended one. On a hedging account with several positions on the same symbol, select the intended position by ticket before reading its type and take profit; PositionSelect(symbol) alone does not identify which of those positions you mean. Preserve the existing TP when changing only the SL, as the example does.
The code does not attempt to predict every freeze-level rule. Read SYMBOL_TRADE_FREEZE_LEVEL for the target symbol and log it when a modification fails; use the server retcode to distinguish a freeze restriction from an invalid stop. If a request is blocked, wait until the restriction no longer applies and retry only after obtaining a fresh quote. Avoid sending repeated modification requests in a tight loop.
Verify the fix in the Strategy Tester and on demo
- Log the exact request. Record the symbol, buy or sell side, quote, requested SL, aligned SL, stop level, tick size, and result retcode. A log that records only “trade failed” is not enough to diagnose a price constraint.
- Exercise both sides. Test the buy and sell paths separately. Their valid SL directions and quote references are opposite, so a check that works for buys can still be wrong for sells.
- Use more than one symbol. Try instruments with different digits, tick sizes, stop levels, and execution settings. This reveals code that accidentally relies on the chart symbol or assumes that decimal precision equals tick precision.
- Test modifications as well as entries. Confirm the EA selects the intended position, preserves the intended TP, and handles a freeze-related rejection without losing track of the position.
- Verify what the server accepted. After a successful request, read the position’s SL and compare it with the intended value. A successful order response and the final position state are the evidence that the stop is actually attached.
The Strategy Tester is useful for exercising request logic and reviewing the EA’s Experts output, but broker-specific symbol constraints can differ from a live account’s settings. Repeat the checks on a demo account with the same broker and symbol where possible. Tested results do not guarantee future results, and a clean compile does not prove that every trade path behaves correctly.
If the EA compiles but still rejects trades, compare its logged request with the symbol properties and retcode first. If the issue is part of a wider EA path that is not reaching or completing a trade, the FXNook EA debugger can compile an uploaded file, run its checks and AI dry run, and report where the trading logic stops; requested fixes are made as a new version. Your practical next step is to capture one failed request with its quote, SL, symbol limits, and retcode, then use that evidence to correct the check or the position selection.
FAQ
What does invalid stops mean in MT5?
It means the trade server would not accept the requested stop price under the symbol’s trading rules at the time it processed the request. Common reasons include the stop being on the wrong side of the market, too close, off the tick grid, or blocked during a modification. Read the trade retcode and request details to identify which condition applies.
How do I check the minimum stop-loss distance in MQL5?
Read SYMBOL_TRADE_STOPS_LEVEL with SymbolInfoInteger and multiply its value in points by SYMBOL_POINT from SymbolInfoDouble. Compare that price distance with the current Bid for a buy SL or Ask for a sell SL, then align the SL to SYMBOL_TRADE_TICK_SIZE and check again. A zero reported stop level does not ensure every request will be accepted.
Why does MT5 reject a stop loss that looks far enough away?
The displayed chart price may not be the quote side used to validate the stop, or the price may be rounded to digits but not aligned to the symbol’s tick size. The quote can also move before the request reaches the server, and a modification can encounter a freeze restriction. Log the fresh Bid and Ask, the submitted SL, symbol properties, and server retcode to narrow down the cause.
Questions
What does invalid stops mean in MT5?
It means the trade server would not accept the requested stop price under the symbol’s trading rules at the time it processed the request. Common reasons include the stop being on the wrong side of the market, too close, off the tick grid, or blocked during a modification. Read the trade retcode and request details to identify which condition applies.
How do I check the minimum stop-loss distance in MQL5?
Read SYMBOL_TRADE_STOPS_LEVEL with SymbolInfoInteger and multiply its value in points by SYMBOL_POINT from SymbolInfoDouble. Compare that price distance with the current Bid for a buy SL or Ask for a sell SL, then align the SL to SYMBOL_TRADE_TICK_SIZE and check again. A zero reported stop level does not ensure every request will be accepted.
Why does MT5 reject a stop loss that looks far enough away?
The displayed chart price may not be the quote side used to validate the stop, or the price may be rounded to digits but not aligned to the symbol’s tick size. The quote can move before the request reaches the server, and a modification can encounter a freeze restriction. Log the fresh Bid and Ask, the submitted SL, symbol properties, and server retcode to narrow down the cause.