Loading…

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

SettingDefaultWhat it does
SymbolSymbol to study, blank = this chart's symbol
TimeframePERIOD_D1Timeframe whose bar-to-bar gaps are measured
Max bars2000Most recent bars to include
Min gap pips1.0Smallest gap counted, in pips (filters feed jitter)
Fill lookback bars5Bars after the gap checked for a fill back to prior close
Save csvtrueWrite every gap 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 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria