Loading…

Spread Widening Trigger Analyzer

Spread widens for different reasons at different times - a scheduled news release, a session handover, or simply a quiet market where the last quote is stale and the next one jumps. Traders usually notice this only when it costs them a fill, and rarely have any record of when or how often it actually happens on their own feed. This script builds that record. It polls live spread on the chosen symbol for InpDurationSeconds and maintains a short rolling baseline average. A widening EVENT is logged only when spread rises above that baseline by both a ratio (InpWideningRatio) and an absolute minimum (InpMinWideningPoints) - and it is edge-triggered, firing once when spread first crosses the threshold and staying silent until spread drops back below it. Without that edge-trigger, one wide burst that stays wide for several polls would be logged as dozens of near- identical "events", badly overstating how often widening actually occurs. For every event, the script records the server hour it happened, the symbol's own ATR on a configurable timeframe at that moment (context for whether the market was already moving), and how close the current price was sitting to a round level. At the end it prints a per-hour event count and compares the observed rate of events landing near a round level against what a uniform baseline would predict, using the same distance-to-level logic as the companion Round Level Tick Clustering Sampler script in this catalogue. Notes and limitations - Events are capped at 500 per run to keep memory bounded. If the cap is hit, the summary says so; a symbol that widens more than 500 times in one window needs a shorter InpDurationSeconds or a stricter threshold to get a complete record. - The baseline needs InpBaselineSampleCount samples before the script will detect anything - the first few seconds of a run never produce events even on a genuinely widening spread, by design. - ATR context is read at the moment of the event, not averaged over the event's duration - it describes conditions at the trigger instant, not the whole widening episode. - This is a live, one-shot polling window, not a historical spread log. MT4 keeps no spread history to scan retroactively; running the script is the only way to build the record.

Script · MT5 · v1.0 · Free

About Spread Widening Trigger Analyzer

Spread Widening Trigger Analyzer is a script for MetaTrader 5 based on ATR. It can alert you with a pop-up, sound, email or push message. It has 12 settings, such as Symbol, Duration seconds and Poll interval ms. MQL source code included.

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

Settings

SettingDefaultWhat it does
SymbolSymbol to sample, blank = this chart's symbol
Duration seconds900How long to sample, seconds (max 3600)
Poll interval ms50Poll interval while sampling, milliseconds
Baseline sample count20Rolling window used for the baseline spread (max 200)
Widening ratio2.0Spread must exceed baseline x this ratio to trigger
Min widening points3...and exceed baseline by at least this many points
Volatility timeframePERIOD_M15Timeframe used for the ATR context reading
Volatility period14ATR period used for the context reading
Round step points100Round-level spacing used for the price-level context, points
Near round threshold points5"Near a round level" distance used in the summary, points
Save csvtrueWrite every widening event to a CSV file
DelimiterDelimiterCommaCSV column separator

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: ATR · Trading Sessions · News Trading · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria