History Gap Auditor
A gap in history data is silent by default. The strategy tester, and most indicators, simply step over a missing bar and carry on as if nothing happened. That means a strategy can be tuned and "optimised" against data that is quietly full of holes, and the first anyone hears about it is when live behaviour does not match the backtest. This header exists to make gaps visible before that happens, by scanning a time series and reporting exactly where consecutive bars are further apart than the chart's own period says they should be. The one detail that makes or breaks a gap auditor is the weekend. Forex trades roughly Sunday evening to Friday evening, so every single week produces a jump of up to about seventy-two hours between the last bar before the close and the first bar after the reopen - completely normal, and reporting it as a data problem every week would drown out every gap that actually matters. This header recognises that specific shape (the older bar falling on a Friday, and the gap not exceeding roughly three days) and excludes it from the gap count, tracking it separately instead. Everything else - a hole in the middle of a trading week, a duplicated timestamp, an out-of-order bar - is reported as a genuine anomaly, deliberately including mid-week holidays. A market being closed for a holiday is exactly the kind of thing a backtest should be told about explicitly, not have silently absorbed into "business as usual" the way the weekend gap is. Duplicate timestamps are counted separately again, since a repeated timestamp is a different failure mode from a missing one - it usually means a history file was concatenated badly rather than that the feed dropped data, and conflating the two would make an audit report harder to act on. Both headers implement identical audit logic - the weekend-gap shape test and the duplicate/gap bookkeeping are pure computation over a caller- supplied datetime array, with no platform-specific behaviour anywhere in the algorithm itself. Notes and limitations - Weekend recognition checks only that the OLDER bar in a gap falls on a Friday and the gap does not exceed about seventy-two hours. A broker whose weekly close falls on a different weekday (some CFD and index feeds close earlier) will have its weekly closure reported as a genuine gap - this is a known limitation, not a bug, and worth knowing before auditing anything other than standard Forex majors. - Non-Forex holiday closures (Christmas, New Year, national holidays) are reported as genuine gaps by design. This header does not maintain a holiday calendar; treat holiday-shaped genuine gaps as expected once you have looked at the dates and confirmed that is what they are. - Out-of-order timestamps (a "newer" bar chronologically before the "older" one) are silently skipped rather than reported - that failure mode belongs to a different kind of check and mixing it into gap counts would blur two unrelated problems together. - Exact-period matching means brokers whose bar timestamps drift by even a few seconds around DST changes can show spurious small gaps around those dates. Inspect the printed gap list rather than trusting the count alone near a DST boundary. - Pure computation, no chart or trade calls inside the header itself - safe to call from a script, indicator or expert with no side effects on either platform.
Script · MT4 · v1.0 · Free
About History Gap Auditor
History Gap Auditor is a script for MetaTrader 4. It has 2 settings, such as Bars to audit and Max gaps print. MQL source code included.
Files in the download: DataGapAuditor.mqh, DataGapAuditor.txt, DataGapAuditorDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Bars to audit | 500 | how many bars of real chart history to scan |
| Max gaps print | 10 | how many of the largest real gaps to print |
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: MT4 Script · MQL4 Source Code