Gap Statistics Report
"Gaps get filled" is repeated often enough that it sounds settled, but it is rarely checked against the specific symbol and timeframe someone is about to trade it on. This script checks it directly: it walks the loaded history of a chosen symbol and timeframe, finds every bar-to-bar gap of at least a minimum size, and records whether price traded back through the prior close within a chosen number of bars afterwards. A gap here is the bar's open against the PREVIOUS bar's close, not a high/low comparison. That is the actual discontinuity a trader sitting in front of the chart would have faced, and on the default daily timeframe it is exactly what "opening gap" means. Sub-pip differences from feed rounding are excluded with a minimum gap size so the count reflects genuine gaps rather than noise. Fill is checked within a fixed lookback window, not "eventually" - a gap that fills six months later is not the same trade opportunity as one that fills within the next few bars, and folding both into one "filled" statistic would overstate how tradeable the pattern actually is. Results are reported separately for gap-up and gap-down, since the two are not required to behave the same way on every instrument, and a combined number can hide a real asymmetry. Notes and limitations - A gap right at the newest end of the loaded window, with fewer than InpFillLookbackBars bars after it, is skipped rather than scored on a truncated lookback, which would understate the fill rate. - Fill is judged by low/high touching the prior close level, not by close price - a wick through the level counts as filled even if the bar closed back on the gap side. - This is a descriptive study of the loaded history, not a signal generator, and says nothing about spread, slippage or whether the base rate has been stable over time. - Weekend gaps on symbols that trade continuously (some indices, crypto) will simply show as smaller, more frequent gaps rather than the large weekly gap forex traders usually mean by the term.
Script · MT4 · v1.0 · Free
About Gap Statistics Report
Gap Statistics Report is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Symbol, Timeframe and Max bars. MQL source code included.
Files in the download: GapStatisticsReport.ex4, GapStatisticsReport.mq4, GapStatisticsReport.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Symbol | Symbol to study, blank = this chart's symbol | |
| Timeframe | PERIOD_D1 | Timeframe whose bar-to-bar gaps are measured |
| Max bars | 2000 | Most recent bars to include |
| Min gap pips | 1.0 | Smallest gap counted, in pips (filters feed jitter) |
| Fill lookback bars | 5 | Bars after the gap checked for a fill back to prior close |
| Save csv | true | Write every gap event to a CSV file |
| Delimiter | DelimiterComma | CSV column separator |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT4 Script · MQL4 Source Code