mt5.copy_ticks_range() in MetaTrader5 Python: get ticks between two dates
Copies every tick of one symbol between two dates into a numpy array, with flags to choose price ticks or trade ticks. Returns None on failure.
Signature
mt5.copy_ticks_range(symbol, date_from, date_to, flags) What it does
copy_ticks_range() takes a start and an end date instead of a count. Use it to pull the ticks of one session or one news release.
Parameters
| Parameter | What it is |
|---|---|
symbol | The symbol name. Required. |
date_from | The start of the range. Dates can be datetime objects or seconds since 1970. Make datetime objects with tzinfo=timezone.utc so your own machine's time zone does not shift them, and remember the terminal reads them on the broker's clock. |
date_to | The end of the range, in the same form as date_from. |
flags | Which ticks to copy: mt5.COPY_TICKS_ALL for every tick, mt5.COPY_TICKS_INFO for ticks where bid or ask changed, or mt5.COPY_TICKS_TRADE for ticks where the last price or volume changed. |
What it returns
- A numpy structured array, one row per tick, with
time,bid,ask,last,volume,time_msc,flagsandvolume_real. Noneon failure. Checkmt5.last_error().
Example
from datetime import datetime, timezone
import pandas as pd
import MetaTrader5 as mt5
if not mt5.initialize():
raise SystemExit(mt5.last_error())
start = datetime(2026, 10, 2, 12, 25, tzinfo=timezone.utc)
end = datetime(2026, 10, 2, 12, 35, tzinfo=timezone.utc)
ticks = mt5.copy_ticks_range("EURUSD", start, end, mt5.COPY_TICKS_ALL)
if ticks is None:
raise SystemExit(mt5.last_error())
df = pd.DataFrame(ticks)
df["time"] = pd.to_datetime(df["time_msc"], unit="ms") # broker clock
print(df[["time", "bid", "ask"]].head())
mt5.shutdown() Common mistakes
- Bar and tick times are the broker's server clock written as if it were UTC. On most servers that is two or three hours ahead of true UTC. Add the broker's offset before you compare them with real UTC times.
- A ten-minute window around a news release can hold thousands of ticks. Keep ranges short.
- Select the symbol in Market Watch first.
The same with Tickwire on Linux
The package needs a Windows terminal on the same machine. Tickwire runs the terminal for you and gives you a REST API, so the code below runs on Linux, macOS or a server.
Tickwire's ticks route reads forward from startTime with limit and offset. For a range, keep paging until a tick's time passes your end date. It is MT5 only; MT4 answers not_supported_on_mt4.
import os, requests
API = "https://api.tickwire.io"
h = {"auth-token": os.environ["TW_KEY"]} # your Tickwire key
base = f"{API}/users/current/accounts/{os.environ['TW_ACCOUNT']}"
url = f"{base}/historical-market-data/symbols/EURUSD/ticks"
rows, offset = [], 0
while True:
page = requests.get(url, params={"startTime": "2026-10-02T12:25:00Z",
"offset": offset, "limit": 1000}, headers=h).json()
rows += [t for t in page if t["time"] < "2026-10-02T12:35"]
if len(page) < 1000 or page[-1]["time"] >= "2026-10-02T12:35":
break
offset += len(page)
print(len(rows), "ticks") Related functions
- mt5.copy_ticks_from() in MetaTrader5 Python: get ticks forward from a date
- mt5.copy_rates_range() in MetaTrader5 Python: get bars between two dates
- mt5.symbol_info_tick() in MetaTrader5 Python: get the latest bid and ask
Related error codes
MT5 from Python, on any machine
One REST API for MT4 and MT5, with idempotent orders and an audit log. Read the MT5 Python API page or the quickstart.