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
- Create a free account, add your MT5 account and create a Read only API key under AI & API.
- Download hostmt5.py and export_history.py into one folder.
- 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
| Timeframe | Typical depth |
|---|---|
| M1 | About 1.4 years |
| M5 | About 7 years |
| M15 and above | As far as your broker has |
| Ticks | Up 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
- MetaQuotes' Python package has functions such as
copy_rates_range, but it works only on Windows with MT5 running on the same machine [1]. More in MT5 Python API on Mac and Linux. - An MQL5 script in desktop MT5 can write bars to a file with MQL5's file functions. That works if you have Windows and can write MQL5.
Honest limits
- You get what your broker serves; HostMT5 doesn't sell or merge third-party data.
- Read-only keys are limited to 1,200 data requests a minute, which is plenty for exports.
- MetaTrader 5 only.
Sources
- 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.
Real MetaTrader 5 in any browser. EAs 24/7, copy trading, TradingView webhooks. No card needed.
Start free →- A free MT5 VPS alternative: hosted MetaTrader 5, free during launch
- Do you still need an MT5 VPS?
- How to run an MT5 Expert Advisor 24/7 without your PC
- TradingView alerts to MT5 orders with a webhook
- Copy trades between MT5 accounts at different brokers
- A MetaApi alternative for traders, not only developers
- A free PineConnector alternative with MT5 hosting included
- The full MT5 terminal in your browser
- Let an AI assistant work with your MT5 account
- Use MT5 from Python on Mac, Linux or a notebook
- A REST API and live stream for MetaTrader 5
- Let Claude or ChatGPT build and run your MT5 EA
- Moving Skynet MT5 alerts to HostMT5