Advertisement IC Markets

Putting the max spread filter in the EA before any entry logic

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS London Scalper
Posts: 1121
Joined: Sun Oct 18, 2026 12:25 pm

Putting the max spread filter in the EA before any entry logic

Post by FXS London Scalper »

A small design choice with large consequences: check spread at the very start of the entry function, before computing signals.

Why first?
- It avoids computing signals that will be rejected anyway.
- It ensures that no code path skips the check (e.g. a signal branch added later that forgets to check spread).
- It makes logs cleaner: a skipped entry due to spread is logged once, clearly.

Structure:

Code: Select all

void CheckEntry() {
   if(!SpreadOK()) { LogSkip("spread"); return; }
   if(!SessionOK()) { LogSkip("session"); return; }
   if(!NewsOK())   { LogSkip("news"); return; }
   // signal logic below
}
SpreadOK() should compare current spread with a threshold that can vary by hour. Store thresholds in an input string or a small file so they can be changed without recompiling.

Bonus: log the spread at the moment the order is sent, not just at the check. They can differ by the time the order leaves.

Do you use guard clauses like this in your EAs?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Amanhasnoname
Posts: 2442
Joined: Fri Oct 30, 2026 9:45 am

Re: Putting the max spread filter in the EA before any entry logic

Post by Amanhasnoname »

Putting the spread check first is sound, and the main thing to get right is what the threshold is compared against. A fixed pip limit is blunt, because normal spread differs a lot between symbols and between sessions. Better to compare the current spread with a typical value for that symbol and hour, for example a rolling median over the last few hundred ticks, and block the entry when it is more than about 1.5 to 2 times that figure.

Remember the spread has to be judged relative to the trade. If your target is 6 pips, a 2 pip spread eats a third of it, so a good guard also checks that spread as a share of the planned stop and target stays under a limit you choose. Watch the rollover hour and the minutes around news releases, since spreads often widen there and then snap back, which makes a single check misleading.

Re-check right before the order is sent, not only at the top of the function, and log the spread at both moments. That gives you data to tune the limit, and a quick way to spot signals that mostly get skipped for cost reasons.
Post Reply