Home › Guides

Download years of MT5 price history to CSV

Updated 2026-11-26 · HostMT5 guides

Backtests in Python, Excel or another platform need your broker's own price history, and MT5 already has it. The trouble is getting it out. With your MT5 hosted on HostMT5 you can download years of candles or ticks to CSV with one command, from Windows, macOS or Linux.

Why export from your own broker

Prices, spreads, session times and symbol names differ between brokers, so a backtest on someone else's data can disagree with what your account actually trades. HostMT5 reads history from your own MT5 terminal, so you get the same candles your MT5 shows, including the spread on each bar.

The quick way: one script

  1. Create a free account, add your MT5 account and create a Read only API key under AI & API.
  2. Download hostmt5.py and export_history.py into one folder.
  3. Run:
export HOSTMT5_KEY=mc_your_key        # Windows: set HOSTMT5_KEY=mc_your_key
python export_history.py 1 XAUUSD M15 2024-01-01 xauusd_m15.csv

The arguments are your account id (from the dashboard or api.accounts()), the symbol as your broker names it, the timeframe, the start date and the output file. The script pages back 50,000 bars at a time until it reaches the start date.

Each row has time, open, high, low, close, tick_volume, spread, real_volume. time is broker server time as Unix seconds, the same numbers MT5 itself uses.

In your own code

from hostmt5 import HostMT5
acc = HostMT5("mc_your_key").account(1)

df = acc.bars_df("EURUSD", "H1", count=50000)                     # pandas DataFrame
week = acc.bars("XAUUSD", "M5", start="2026-11-16", end="2026-11-21")
everything = acc.history("EURUSD", "H1", "2023-01-01")            # pages for you
ticks = acc.ticks("EURUSD", count=100000)                         # bid/ask ticks

Without Python, one curl call per period works too:

curl -G https://hostmt5.com/api/v1/accounts/1/bars -H "Authorization: Bearer mc_your_key" \
     -d symbol=XAUUSD -d timeframe=M5 -d from=2026-11-16 -d to=2026-11-21

How far back it goes

TimeframeTypical depth
M1About 1.4 years
M5About 7 years
M15 and aboveAs far as your broker has
TicksUp to 100,000 per call; page with dates

The terminal keeps the newest 500,000 bars of each symbol and timeframe, as far back as your broker serves them. If you ask for an older period you get no bars and a note saying where the history starts. The first request for very old data can take a minute while MT5 downloads it from the broker; the clients retry by themselves.

Other ways to get MT5 data

Honest limits

Sources

  1. MQL5 docs: MetaTrader for Python and PyPI: MetaTrader5 (Windows wheels only, checked 26 Nov 2026)

FAQ

How do I download MT5 historical data?

Host your MT5 account on HostMT5, create a Read-only API key, and run export_history.py with the symbol, timeframe and start date. It writes a CSV with time, open, high, low, close, tick volume, spread and real volume.

How far back does MT5 history go?

On HostMT5 the terminal keeps the newest 500,000 bars per symbol and timeframe, as far as your broker serves them: about 1.4 years of M1 and about 7 years of M5; M15 and above go as far as the broker has.

Can I download tick data?

Yes, up to 100,000 ticks per call, by count or date range.

What time zone are the timestamps in?

Broker server time written as Unix seconds, the same numbers MT5 and its Python package use.

Host your MT5 in the cloud, free

Real MetaTrader 5 in any browser. EAs 24/7, copy trading, TradingView webhooks. No card needed.

Start free →
More guides

All guides · HostMT5 facts