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?