Detecting Missing Bars in MetaTrader History Before Backtesting
Info
The Detecting Missing Bars in MetaTrader History Before Backtesting is a Indicator for MetaTrader 5 that a backtest is only as good as the historical data it uses. MetaTrader 5 does not inherently warn users about missing historical bars (gaps).
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Indicator works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Indicators folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Detecting Missing Bars in MetaTrader History Before Backtesting
1. Installation: Place your file in the MQL/Indicators folder via "Open Data Folder" and restart your terminal.
2. Loading: Find the indicator in the Navigator, drag it onto your chart, and configure the input parameters in the popup window.
3. Customization: Press Ctrl+I to open the indicator list, select your tool, and click "Properties" to change colors, levels, or visual styles.
4. Updating: Replace the old file in the Indicators folder with the new version and restart the platform to apply changes.
Frequently Asked Questions
Q: Why is my indicator not showing? A: Verify the file is in the MQL/Indicators folder, or try right-clicking the "Indicators" tree in the Navigator and clicking "Refresh."
Q: Do custom indicators slow down the platform? A: Too many complex indicators can impact performance; remove unused ones via the "Indicator List" (Ctrl+I).
Q: Can I use MT4 indicators on MT5? A: No, MQL4 and MQL5 are distinct languages; ensure the indicator is compiled specifically for your platform version.
What this tool does
A backtest is only as good as the historical data it uses.
Typical Use Case
This Indicator excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Indicator works on MetaTrader 5. Place the file in the MQL5/Indicators folder and restart the terminal.
Description & Settings
Related: Truncation Audit: Detecting Look-Ahead and Repainting in MQL5 Indicators - another powerful indicator for MetaTrader 5 traders.
A backtest is only as good as the historical data it uses. MetaTrader 5 does not inherently warn users about missing historical bars (gaps). When gaps exist, the chart simply displays the next available bar, potentially causing Expert Advisors (EAs) to miss crucial market movements that occurred within the gap. Standard methods for checking history, such as counting bars or looking for time discrepancies, often flag regular intervals like weekends and daily breaks, obscuring genuine data gaps.Also recommended: Session Sweep Boxes: Detecting Liquidity Sweeps - similar indicator with strong performance on MetaTrader 5.
This indicator analyzes the trading sessions for a symbol, as defined in the symbol specifications, and identifies any discrepancies where a bar is expected but absent during market open hours. Missing bars are categorized into three types to help distinguish between data issues and scheduled market closures (holidays).
Example for XAUUSD M15 since November 2026: one genuine gap of 2 bars, 42 short sessions around holidays, and 4 days with no bars recorded.
The Three Gap Categories
Hole: Bars are missing during a period when the market session was open on both preceding and succeeding bars. These are the gaps most likely to impact backtest accuracy. Marked with a red line on the chart.
Short Session: The market opened later than usual or closed earlier than usual, common on holidays like Thanksgiving or Christmas Eve, or during US bank holidays. Thin trading periods around these times are also counted here. These are typically not considered data problems.
Day with No Bars: A day designated as a trading day according to the session table, yet no trading bars were recorded. This can occur on holidays like Good Friday, December 25th, or January 1st for many data feeds.
Panel Display Information
First Date Checked: Displays the earliest date for which historical data is analyzed. If this date is later than the user's specified range, it indicates that the terminal has fewer bars available than requested. Users may need to increase the 'Max bars in chart' setting in the terminal preferences.
Coverage: The percentage of expected trading session bars that are actually present. Short sessions and days with no bars are excluded from this calculation.
Gap Summary: Shows the total number of holes, the total number of missing bars within these holes, and details of the largest single gap (including its start and end times).
Holiday Data: Reports the count of short sessions and days with no bars.
Current Time Sync: Indicates whether the historical data reaches the current server time, or if it stops short by a certain number of bars.
Users can hover over any line on the chart to view detailed information about the gap, including its type, start and end times, and the number of missing bars.
Input Parameters
Days to Check: Specifies the number of past days, counted backward from the most recent bar, to analyze for gaps.
Mark Gaps on Chart: If enabled, a vertical red line will be drawn after each detected gap.
Mark Short Sessions and Empty Days: If enabled, dotted grey lines will be drawn to indicate short sessions and days with no bars.
Write CSV Report: If enabled, a CSV file containing details of each gap (type, start time, end time, number of bars) will be saved to the MQL5\Files\HistoryGaps_<symbol>_<timeframe>.csv directory.
Appearance Settings: Options to customize colors and font size for both dark and light chart themes.
Notes
The indicator operates on the chart's current timeframe, from M1 to D1. It re-evaluates the history each day. The analysis uses the broker's session table; if this table includes trading hours when the market was not actually active, these will be flagged as holes, providing potentially useful information about data feed discrepancies. The determination of a short session is an approximation based on the location of the gap; the generated CSV report allows for detailed verification of any suspicious period. The indicator visually represents objects on the chart and does not utilize data buffers.
You may also like: Daily Loss Limit Tracker for Prop Firm Trading - excellent alternative for indicator users on MetaTrader 5.
Source Code
#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version "1.00"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#property indicator_chart_window
#property indicator_plots 0
input int InpDays = 365;
input bool InpMark = true;
input bool InpMarkShort = false;
input bool InpCsv = false;
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.