Building a max spread filter for gold in MT5
Posted: Tue Oct 20, 2026 5:15 pm
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:
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?
Basic MQL5 logic:
Code: Select all
double spread = (SymbolInfoDouble(_Symbol, SYMBOL_ASK) - SymbolInfoDouble(_Symbol, SYMBOL_BID));
if(spread > MaxSpread) return; // skip entry
- 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?