Why a valid signal may no longer be a valid entry
A completed-bar breakout may be followed by a gap or widening spread. Instead of assuming that a market buy will occur at the signal close, an MT5 expert advisor can measure the difference between that close and the current executable ask before submitting its order. This guard is separate from the entry signal and does not guarantee a fill price.
Strategy example
Use a long signal when the completed close exceeds the highest high of its preceding 20 bars. On the first tick of the next bar, compare the current ask to the signal close using an absolute difference. On five-digit EURUSD, 30 points equal 3 conventional pips. For a signal close of 1.1000, ask 1.1002 passes, whereas 1.1008 fails. Reject both excessively favorable and unfavorable gaps under this symmetric rule; a one-sided rule is a separate hypothesis.

Hypothetical executable quotes compared with a 3-pip entry limit.
MQL5 implementation
// Entry guard for a long signal on the new bar
bool EntryGapOK(double signalClose, double maxPoints)
{
MqlTick tick;
if (!SymbolInfoTick(_Symbol, tick))
return false;
if (signalClose <= 0 || tick.ask <= 0 ||
maxPoints < 0 || _Point <= 0)
return false;
double gap = MathAbs(tick.ask - signalClose);
return gap <= maxPoints * _Point + _Point * 1e-8;
}
// Example on a five-digit EURUSD quote:
// EntryGapOK(iClose(_Symbol, _Period, 1), 30.0)
Call the helper after checking data readiness, once per new bar, before CTrade.Buy. For a rejected price guard, consume the signal rather than chasing later ticks. Retrieve at least 21 completed candles to calculate the breakout without including the signal bar in resistance. Use SymbolInfoTick for a consistent quote snapshot and distinguish points from pips and tick size. A passing guard is not the same as an order deviation setting. Check trade result retcodes and actual executions; broker execution mode can affect deviation handling.
Exit policy and testing
One testable design uses a stop below the signal low and a profit target twice the actual initial risk distance. Validate stop distance, volume and price increments before submission; reject trades whose risk is invalid. Reconcile protection after fills. Compare no guard with 10, 30 and 50 points on five-digit EURUSD using real-tick data, commissions and variable spread. Track rejected signals, realized entry drift, drawdown and missed profitable trades. Repeat on unseen samples and test gaps and delayed quotes. Code is an entry helper, not a complete EA, and has not been compiled or backtested here. Leveraged trading can cause losses beyond intended stop risk.
For custom execution and strategy rules, see Custom MT5 strategy Development Services.