A breakout EA can identify a valid signal yet enter at an unfavorable transaction cost. In MT4, a spread gate separates the closed-bar trading signal from the live execution decision. This is especially useful around rollover and thin liquidity, when the ask-bid difference may expand without a comparable change in the chart's bid-based signal.

Example: EUR/USD breakout

Assume a completed candle closes above the highest high of the previous 20 candles. The EA permits a buy only when it is flat and the current spread is at most 2 pips. On a five-digit EUR/USD quote, one pip equals 0.00010 or ten broker points.

Live Spread Gates for MT4 Breakout Entries
With a two-pip ceiling, 1.2 and 2.0 pass; 3.8 is rejected.
Bid Ask Spread Decision
1.10000 1.10012 1.2 pips Eligible
1.10000 1.10020 2.0 pips Eligible
1.10000 1.10038 3.8 pips Skip

For a hypothetical 0.10 standard lot of EUR/USD in a USD account, the pip value is approximately $1. The initial spread cost is therefore about $1.20 versus $3.80 in the first and third cases, before commissions and slippage.

MQL4 implementation

The following helper is an integration excerpt for conventional FX quoting, not a complete EA. It uses chart-symbol Bid, Ask, Point and Digits. RefreshRates updates the local quote variables when newer data is available; it does not guarantee a fresh market quote during disconnection.

// FX only; call from OnTick on the chart symbol.
bool SpreadAllowed(double maxPips)
{
    RefreshRates();
    if(Bid <= 0 || Ask < Bid || maxPips <= 0)
        return false;
    double pip = (Digits == 3 || Digits == 5)
                 ? 10 * Point : Point;
    return (Ask - Bid) / pip <= maxPips + 1e-8;
}
// After confirming a closed-bar signal and flat state:
// if(SpreadAllowed(2.0)) { /* submit validated entry */ }

Calculate the breakout on bar 1 and the reference high on bars 2 through 21, for example with iHighest using count 20 and start 2. Check sufficient history and a valid returned index. Track the signal bar time and consume each signal once, even if rejected, to prevent repeated attempts on every tick. If delayed entry is desired instead, define an explicit expiration and revalidate the setup.

Execution and risk controls

Filter open and pending orders by symbol and magic number before submission. Refresh and validate quotes, volume increments, margin and protective levels. A market buy uses Ask, whereas a sell uses Bid. The spread can change between the check and OrderSend; the filter is not a guaranteed execution-price cap. OrderSend slippage is expressed in broker points, not pips, and its behavior depends on execution mode. Handle rejection without blind retries. Never use the spread gate to suppress protective exits.

Testing

Test four- and five-digit EUR/USD, two- and three-digit JPY pairs, exact threshold values and stale quotes. Compare rejected signals, net returns and drawdown with the filter disabled. MT4 tester spread assumptions may not reproduce historical variable spreads, so supplement tests with demo forward observations and recorded bid/ask data. For metals and CFDs define units explicitly rather than reusing FX pip conventions.

Spread filtering may reduce costs but can also exclude profitable trades. Gaps, commissions and slippage remain material risks. This excerpt has not been compiled or backtested here.

References: MQL4 OrderSend and RefreshRates.

To customize this strategy, contact us about Custom MT4 strategy Development Services.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.