Loading…

History Gap Finder

Bar history has holes for reasons ranging from harmless to serious: a weekend, a public holiday, a broker outage, a symbol that was added to Market Watch late and never backfilled. Telling these apart by eye across months of H1 bars is slow and error-prone. The naive version of this script - diff every consecutive bar time against the expected step and print whatever is bigger - produces a report that is mostly noise. Every single week contributes a "gap" from Friday's close to Monday's (or Sunday's) open, and on a year of H1 data that is around 52 entries that mean nothing. Burying two real gaps inside fifty-two fake ones defeats the point of automating the check at all. This script excludes the weekend specifically: a gap counts as a weekend close only when it spans a Saturday AND its total length does not run past roughly three days plus a tolerance you set, which covers brokers that shut a little early on Friday or open a little late on Sunday. The Saturday test is worked out from the bar timestamps themselves, day by day, not from a weekday assumption about what timezone the broker's server clock is in - that assumption is exactly the kind of thing that quietly breaks on a broker whose day boundary does not line up with GMT. A holiday is not swallowed by this rule. If a gap spans a Saturday but runs longer than the weekend ceiling - a bank holiday Monday tacked onto the normal close, say - it is reported like any other gap, because a holiday closure is still a hole in the data and the user, not the script, should decide whether it matters for what they are about to do with that history. Notes and limitations - Only bars already loaded in the terminal are scanned. This script does not force history to download; if the report looks short, scroll the chart back (MQL4) or increase the chart's history depth, then run again. - A daily (D1) or higher timeframe can show a small, harmless "gap" around a broker's daylight-saving clock change, because the server-time distance between two calendar days briefly stops being exactly 24 hours. These come through with a missing-bar estimate of zero - that zero is the honest signal that it is a clock artefact, not lost data. - The missing-bar estimate is exactly that, an estimate: round(gap length / bar step) minus one. It assumes bars would have landed exactly on the step, which is normally true but is not a guarantee from the broker. - This is a read-only report. It does not attempt to fill, request or repair anything - see DownloadAllHistory in this catalogue if what you actually need is more bars in the terminal.

Script · MT5 · v1.0 · Free

About History Gap Finder

History Gap Finder is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Symbol, Timeframe and Weekend tolerance hours. MQL source code included.

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

Settings

SettingDefaultWhat it does
SymbolSymbol to scan (blank = this chart's symbol)
TimeframePERIOD_CURRENTTimeframe to scan
Weekend tolerance hours4Slack around the normal weekend length, hours
Save csvfalseAlso write the gap list 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: Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria