Backtest Data Preflight won’t tell you whether your history is good. It’s a free script for MetaTrader 5 and MetaTrader 4 that I run before a backtest. You pick a symbol, a timeframe and a date range in broker server time, it asks the terminal for the bars in that range (on MT5 for the ticks too), and the Experts tab gets what came back: how many bars, the first and last open, how far those sit from the dates you asked for, and every spot where two opens are further apart than one bar. A weekend is a gap. A holiday is a gap. Three days the broker never stored are a gap as well, printed the same way, with dates and seconds, and the verdict stays with you.
That’s on purpose. Any tool that turns this into a quality score has to guess which hours the market should have been open, and I’d rather read the dates myself than trust a guess wearing a percentage. A score built on a guess is bullshit with a decimal point.
Text in the Experts tab, nothing on the chart
The report is plain key=value lines in the Experts tab. It draws no panel and no chart objects, because all I ever do with the result is read it and copy it somewhere, and text survives both.
Both CodeBase entries, MetaTrader 5 and MetaTrader 4, hold the source file and a screenshot and nothing else. BacktestDataPreflight.mq5 belongs in MQL5/Scripts under the terminal’s data directory (BacktestDataPreflight.mq4 in MQL4/Scripts), and File > Open Data Folder takes you there. Compile it in MetaEditor, then drag it from the Navigator onto a chart. On Linux, docker-mql-compiler builds it without anyone clicking through MetaEditor under goddamn Wine by hand.
The inputs dialog shows these:
input string InpSymbol = ""; // Broker symbol (blank = chart)
input ENUM_TIMEFRAMES InpPeriod = PERIOD_CURRENT; // Bar timeframe
input datetime InpFrom = 0; // From (server time, inclusive)
input datetime InpTo = 0; // To (server time, exclusive)
input bool InpCheckTicks = false; // Check tick history- Broker symbol, blank by default, which means the chart’s symbol.
- Bar timeframe, the chart’s own by default.
- From and To, both 0 by default, which means the last 30 days up to the broker’s current time.
- Check tick history, off by default, MT5 only.
A gap is two opens more than one bar apart
The check in the code is one line:
if(interval > 0 && elapsed > interval)
{
summary.gaps++;There’s no trading-hours table behind it, no holiday calendar and no opinion about which sessions a symbol should have, and that’s deliberate. Each of those would be one more way to be wrong about a broker’s schedule. A calendar that files a real hole under “holiday” screws you out of the one gap you ran the script to find, while a weekend you already knew about costs you two seconds of reading.

The run above has 48 hourly bars, first open Friday 00:00, last open Monday 23:00. bar gaps count=1 longest_seconds=176400 is 49 hours, and the gap line under it puts the hole between Friday 23:00 and Monday 00:00. The weekend. You know it’s the weekend because the dates are right there, and a missing Wednesday afternoon would print in exactly the same format, with its own dates.
Only the first ten gaps get a line with dates. The count and the longest one cover the rest, which keeps a year of M1 from dumping ten thousand lines into the log. Monthly bars get the first and last open but no gap count, bar gaps status=not_checked reason=monthly_period, because a calendar month has no fixed length to compare against. Opens that come back out of order or outside the window you asked for get bars status=invalid_history and no summary at all. Summarizing that would be horseshit.
To is exclusive, and the ticks agree with the bars
From is included, To is not. A run from 20 November to 24 November covers the 20th through the 23rd and leaves out anything that opens at midnight on the 24th. The bar read stops one second before To. The tick read took more care, because MetaTrader’s tick range call includes both ends, so To becomes the last millisecond before it:
long BdpTickToMillis(datetime edge, bool exclusiveEnd)
{
return (long)edge * BDP_MILLIS_PER_SECOND - (exclusiveEnd ? 1 : 0);
}If the two reads disagreed on that edge, the bars and the ticks would describe two different windows, and comparing them would be pointless as hell. The same rule explains end_offset_seconds=3600 on H1. The last bar opens an hour before To, because To itself is outside the range.
The window rules are strict:
if(start == 0 && end == 0)
{
end = now;
start = now - BDP_DEFAULT_DAYS * BDP_DAY_SECONDS;
}
if(start <= 0 || end <= start || end > now || end - start > BDP_MAX_WINDOW_SECONDS)
{
return BDP_ERROR_WINDOW;
}Both dates at zero gets the 30-day default. Otherwise you set both dates, because From with To left at zero puts To before From, and the script refuses that. It also refuses a To in the future and anything wider than 366 days. I want a refusal here, not a window quietly trimmed into something I never asked for. The refusal prints preflight refused reason=invalid_window_or_period with the limit, your two inputs and the server time, so you can see which one was the problem.
It won’t build a window on a stale broker clock
The default window is built from the broker’s current time. A terminal that just started or lost its connection is still holding whatever time came with its last quote, and a window built from that ends somewhere before the weekend. So the script first waits for the terminal to be connected and for the server time to be within a week of the computer’s UTC clock:
long offset = (long)server - (long)utc;
return server > 0 && utc > 0 && offset >= -BDP_MAX_CLOCK_OFFSET_SECONDS && offset <= BDP_MAX_CLOCK_OFFSET_SECONDS;A week covers broker time zones and normal market closures. The wait is 60 tries, 500 milliseconds apart, about 30 seconds, and then it gives up with preflight refused reason=no_recent_server_clock. A refusal costs me one rerun. A report on the wrong dates costs me a backtest I trusted for no reason, which is a much bigger pile of crap.
It won’t add a symbol to Market Watch for you
The symbol has to be in Market Watch already. When it isn’t, the script stops with preflight refused reason=symbol_not_in_market_watch, the symbol it looked for and the terminal’s error code. A typo in the symbol name gets a refusal instead of an empty report that looks exactly like missing history, and hunting a hole in the data that turns out to be your own typo is a pain in the ass. Add the symbol yourself and run it again.
Three tries, then the terminal’s own error
History the terminal hasn’t loaded yet can come back as an error while it downloads. The bar read gives it three tries, 500 milliseconds apart, and stops early as soon as bars arrive. When it still has nothing, it says which kind of nothing, bars status=read_error or bars status=empty, with the terminal’s error code either way. Bars that came back alongside an error get the full report plus bars warning=read_error. A download in progress and a broker with no data need different fixes, and one lazy “no data” line would hide which fix you need.
Ticks one server day at a time, and only when asked
On MT5, Check tick history adds a tick scan. Ticks get big fast, so it reads one server day per request and never holds more than that day in memory. Each day ends up in one of three piles: ticks, empty, or a read that failed. The first ten empty or failed days get a line each, then the totals.
In the screenshot that’s four slices, Friday to Monday. Saturday and Sunday came back empty, no read errors, 179,451 ticks in total from Friday 00:05:10 to Monday 23:55:00. A scan stopped halfway through ends its totals line with status=cancelled instead of finished, so a partial count never passes for a full one. With the box unticked the report still says so, ticks status=not_requested, rather than leaving a silence you could mistake for a clean result.
No pretend tick check on MT4
The MT4 version has no Check tick history input, no tick scan and no ticks line in the report, rather than a box that does nothing. The window rules, the clock wait, the Market Watch check, the retries and the gap report are the same code as on MT5. Its screenshot is the same EURUSD run minus the tick lines, so it didn’t earn a spot here. When the first bar on MT4 opens long after From, the entry page says to open the History Center (F2), download the history for the symbol and run the check again.
The checks don’t need the script
The inputs and the script’s start function sit behind a switch. #define BDP_NO_PROGRAM ahead of the include turns them off and leaves the window, gap and tick-slice functions, for anyone who wants the same checks inside their own code. One copy of the rules means one place for them to be wrong.
It answers the question before the tester’s
It doesn’t certify what the Strategy Tester runs on. The tester’s own report says what a test actually ran on. This script answers the question before that one: did the broker hand my terminal anything near the dates I’m about to test? If I rebuilt it tomorrow, it still wouldn’t pretend those are the same question.
Backtest Data Preflight is a free download from the MQL5 CodeBase for MetaTrader 5 and MetaTrader 4.