Different bar counts in live vs Strategy Tester (XAUUSD H1) despite large live history

 

I’m seeing a consistent mismatch between the history available on a live chart and what the Strategy Tester gives me. I only need to show OnInit() to illustrate it.

Code used in OnInit :

int OnInit()
{
   PrintFormat("MQL_TESTER=%d | DATA_PATH=%s",
               (int)MQLInfoInteger(MQL_TESTER),
               TerminalInfoString(TERMINAL_DATA_PATH));

   int total = (int)SeriesInfoInteger(_Symbol, PERIOD_H1, SERIES_BARS_COUNT);
   datetime first = (datetime)SeriesInfoInteger(_Symbol, PERIOD_H1, SERIES_FIRSTDATE);
   datetime last  = (datetime)SeriesInfoInteger(_Symbol, PERIOD_H1, SERIES_LASTBAR_DATE);

   PrintFormat("H1 bars=%d | first=%s | last=%s",
               total,
               TimeToString(first, TIME_DATE|TIME_MINUTES),
               TimeToString(last,  TIME_DATE|TIME_MINUTES));

   return INIT_SUCCEEDED;
}


Live chart (XAUUSD, H1):

H1 bars=61795 | first=1998.04.22 00:00 | last=2025.08.12 09:00


Strategy Tester run #1 (settings):
Symbol: XAUUSD, H1
Date: Custom period, From 2020.04.30 to 2025.07.31
Model: Every tick (other settings standard)

Tester log:

MQL_TESTER=1 | DATA_PATH=C:\Users\...\Agent-127.0.0.1-3000

H1 bars=7820 | first=2019.01.02 01:00 | last=2020.04.29 23:00

Strategy Tester run #2 (to check behavior):
Date: From 2021.04.30 to 2025.07.31

Tester log:

H1 bars=7828 | first=2020.01.02 01:00 | last=2021.04.29 23:00

Observations:

  • On a live chart I have ~61k H1 bars (data since 1998).

  • In the tester I consistently get ~7.8k bars and the earliest date sits roughly ~10–11 months before the “From” date (2019-01-02 or 2020-01-02 in the examples).

  • “Max bars in chart = Unlimited” doesn’t change this in the tester.

  • I also tried forcing loads with CopyRates (date ranges and start/count), polling Bars() , and waiting for SERIES_BARS_COUNT to grow. No effect in the tester.

Questions:

  1. Is the Strategy Tester sandbox limited to whatever historical depth the agent has cached for the symbol, regardless of what’s available on the live terminal?

  2. Is there a supported way to force the tester to download/use deeper prehistory for a broker symbol (e.g., ensure ~24 months prior to the test start), without switching to a custom symbol?

  3. If I run a dummy test with an earlier “From” date, should that permanently extend the agent’s cache so later tests see deeper history, or is the depth still constrained per test/run?

  4. Any known XAUUSD/H1 limitations (broker-side or tester-side) that would explain why live has data back to 1998 but the tester stops ~10–11 months before the “From” date?

Thanks in advance for any pointers.

 
Enrique Enguix:

It's not a bug: it's the tester's design. OnInit() only sees the pre-history that the agent preloads before the From. To have more previous months: drag the From back and filter internally, or use a custom symbol if you need complete control.

 
Miguel Angel Vico Alba #:

It's not a bug: it's the tester's design. OnInit() only sees the pre-history that the agent preloads before the From. To have more previous months: drag the From back and filter internally, or use a custom symbol if you need complete control.

Hi Miguel Ángel,

Got it — so the ~7.8k H1 bars limit I’m seeing is just the tester agent’s preload window before the From date, and that’s fixed by design.

If I need a longer lookback, the workaround is basically to set From further back, let the tester feed those extra months during the run, and then filter internally so the EA only starts trading from my intended date.

I’ll just move the “heavy” stuff (like large indicator caches) out of OnInit and only build them once enough bars have come in during the test. That way the EA warms up naturally without depending on the full history being available right at the start.

Thanks for clearing that up — makes sense now.
 
Effectively, that's how it worked. It's not completely practical, but it can be useful for experimental purposes.
 

The Strategy Tester data is limited to 1 year back the "From date". 

The testing agent downloads only the missing history, with a small margin to provide the necessary data on the history, for the calculation of the indicators at the starting time of testing. For the time-frames D1 and less, the minimum volume of the downloaded history is one year.

Thus, if we run a testing on an interval 2010.11.01-2010.12.01 (testing for an interval of one month) with a period of M15 (each bar is equal to 15 minutes), then the terminal will be requested the history for the instrument for the entire year of 2010. For the weekly time-frame, we will request a history of 100 bars, which is about two years (a year has 52 weeks). For testing on a monthly time-frame the agent will request the history of 8 years (12 months x 8 years = 96 months).

If there isn't necessary bars, the starting date of testing will be automatically shifted from past to present to provide the necessary reserve of bars before the testing.

https://www.mql5.com/en/docs/runtime/testing#multicurrency

Documentation on MQL5: MQL5 programs / Testing Trading Strategies
Documentation on MQL5: MQL5 programs / Testing Trading Strategies
  • www.mql5.com
The idea of automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot...