Advertisement IC Markets

Building a max spread filter for gold in MT5

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: 806
Joined: Sun Oct 18, 2026 12:25 pm

Building a max spread filter for gold in MT5

Post by FXS London Scalper »

Gold spreads vary a lot through the day. A max spread filter stops your EA or manual workflow from entering when spread is unreasonably wide.

Basic MQL5 logic:

Code: Select all

double spread = (SymbolInfoDouble(_Symbol, SYMBOL_ASK) - SymbolInfoDouble(_Symbol, SYMBOL_BID));
if(spread > MaxSpread) return; // skip entry
Things to get right:
- Units: gold spread in price units (e.g. 0.25 = 25 cents), not points. Check the symbol's digits.
- Value: what's "too wide"? Base it on your own spread data by hour. A fixed value might be too strict in Asia and too loose during London.
- Timing: check spread immediately before sending the order, not at the start of the bar.

Refinements:
- Hour-dependent thresholds: a table of max spread per hour.
- Relative threshold: skip if current spread > 2x the median of the last 100 ticks.
- Log every skipped signal, so you can check later whether the filter is too tight.

What spread threshold do you use for gold?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Shadow Trader
Posts: 5438
Joined: Wed Sep 09, 2026 5:19 pm

Re: Building a max spread filter for gold in MT5

Post by Shadow Trader »

Brokers often say their servers are in London, New York, or Tokyo. That's true, but it leaves out the building. In London, the main FX hub is Equinix LD4 in Slough. In New York, it's NY4 in Secaucus. In Tokyo, TY3 or a nearby facility.

A VPS in a data center in the same city might be 30 km from the broker's matching engine. That's a fraction of a millisecond in theory, but real network paths aren't straight. Packets pass through multiple routers, and the actual delay can be 5 to 15 ms.

A VPS in the same building, connected through a cross-connect or the same network switch, can bring the round trip to under 1 ms.

Some VPS providers specialize in this, advertising "in the same data center as brokers". The claim is worth checking with an actual ping to the trade server IP, not a general one to the broker's website, which often sits elsewhere.

The advantage only matters for certain strategies. A 3 pip target on a 1 minute chart won't care about 10 ms. A 0.5 pip target on tick-level signals will.

Honestly assessing which kind of strategy is running is the first step, before paying for a premium location.

What ping to the actual trade server has been achieved, and did the improvement show up in the results?
Post Reply