Loading…

Slippage Spike Circuit Breaker

Execution quality is not constant. News releases, thin overnight liquidity, or a broker server under load can make fills land well past where they were requested for a stretch of time, and a strategy that keeps trading through that stretch pays the difference on every single order. This watches the live order pool for newly appeared market tickets matching a magic filter, measures how far each fill landed from the market's own current price at the moment the ticket was first noticed, and keeps a rolling record of those measurements. The average of the newest few samples is compared against the average of an older window and against a flat pip ceiling; either one being exceeded trips an advisory halt that stays set for a configurable cooldown even if slippage recovers immediately, so a single fast spike does not flicker the flag on and off within seconds. The reference price used for each fill is a documented approximation. This tool did not send the order, so the exact price actually requested at the moment of the OrderSend call - which is what "true" slippage would be measured against - is not visible to a separate program. The closest available substitute is the market's own current price the instant this tool notices the new ticket, which is stated here honestly as an approximation rather than implied to be exact. As with any tool of this kind in MQL4, there is no mechanism for one Expert Advisor to intercept or veto another program's OrderSend call. This cannot itself stop a trade. What it does is publish an "SSB_Halt" GlobalVariable that any cooperating EA can check before sending an order - a convention between programs, not an enforced gate, stated plainly rather than dressed up as automatic protection. Notes and limitations - Advisory only. It cannot force any EA to read the published GlobalVariable, and it cannot intercept or block another program's OrderSend call. - The per-fill slippage measurement is an approximation using the market's current price at the moment the ticket is first noticed, not the actual price requested by whatever program sent the order - the true requested price of another program's OrderSend call is not visible to this tool. - Only market orders (OP_BUY/OP_SELL) are measured; pending orders that later trigger are not currently tracked as fills. - The recent/baseline sample buffer is capped at 200 total entries; the sum of InpRecentSampleCount and InpBaselineSampleCount must not exceed that, and the tool refuses to start otherwise. - A restart resets the in-memory sample buffer to empty; only the "last ticket processed" watermark survives via GlobalVariable, so slippage history itself is not persisted across a terminal or EA restart.

Expert advisor · MT5 · v1.0 · Free

About Slippage Spike Circuit Breaker

Slippage Spike Circuit Breaker is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Magic filter, Recent sample count and Baseline sample count. MQL source code included.

Files in the download: SlippageSpikeBreaker.ex5, SlippageSpikeBreaker.mq5, SlippageSpikeBreaker.txt.

Settings

SettingDefaultWhat it does
Magic filter0Magic number of positions to watch; 0 = every magic number
Recent sample count5How many of the newest fills form the "recent" average
Baseline sample count50How many older fills (before the recent window) form the baseline average
Spike multiplier3.0Recent average trips the breaker once it exceeds baseline times this
Hard ceiling pips5.0Recent average trips the breaker on its own past this many pips, regardless of baseline
Cooldown minutes30Minutes the halt flag stays set after the last spike sample, even if slippage recovers
Scan interval sec5Seconds between pool scans for newly appeared positions

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: News Trading · Alerts · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria