Adaptive Spread Monitoring and Order Gating in MQL5
by
, 07-28-2026 at 02:37 PM (72 Views)
more...Most spread guards in an Expert Advisor work the same way: check the current spread against a fixed number and block the trade if it is too wide. This catches some bad fills, but it treats every instrument as if the same spread value means the same thing everywhere.
A spread of 3 pips on an instrument that normally trades at 1 pip is a genuine anomaly. That same 3-pip spread on an instrument that normally sits at 3 pips is completely ordinary. A static threshold cannot tell the difference.
The fix is to compare the live spread not to a constant but to the instrument's own recent distribution. This article builds that comparison. It introduces CSpreadHistogram, a rolling histogram accumulator that tracks what spread values are typical for an instrument in real time, and CSpreadMonitor, which manages several symbols and exposes a simple order gate. A CDashboardRenderer provides a live visual panel built on MQL5's CCanvas class, and SpreadMonitorDemo.mq5 ties everything together. No external DLLs are used.












Email Blog Entry