mt5.copy_ticks_from() in MetaTrader5 Python: get ticks forward from a date

Copies a number of ticks of one symbol, starting at a date you give and going forward, into a numpy array. Returns None when the ticks can't be read.

Signature

mt5.copy_ticks_from(symbol, date_from, count, flags)

What it does

copy_ticks_from() returns up to count ticks from date_from onwards, oldest first. Use it to study spreads or replay price moves in detail.

time_msc in each row is the tick time in milliseconds, which is finer than time.

Parameters

ParameterWhat it is
symbolThe symbol name. Required.
date_fromThe date to start from. 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.
countHow many ticks to return.
flagsWhich 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, flags and volume_real.
  • None on failure. Check mt5.last_error().

Example

from datetime import datetime, timezone
import MetaTrader5 as mt5

if not mt5.initialize():
    raise SystemExit(mt5.last_error())

mt5.symbol_select("EURUSD", True)
since = datetime(2026, 10, 1, 8, tzinfo=timezone.utc)
ticks = mt5.copy_ticks_from("EURUSD", since, 1000, mt5.COPY_TICKS_INFO)
if ticks is None:
    raise SystemExit(mt5.last_error())

spreads = ticks["ask"] - ticks["bid"]
print(len(ticks), "ticks, widest spread", spreads.max())
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.
  • Select the symbol in Market Watch first. A hidden symbol can return no ticks.
  • Tick history is large. Ask for what you need, not millions of rows at once.

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 returns up to limit ticks (1000 at most) at or after startTime, going forward, with offset to page. Each tick has a UTC time and a brokerTime.

Tick history is MT5 only. On MT4 the route answers not_supported_on_mt4. features.historicalTicks on the capabilities route says which you have.

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']}"

ticks = requests.get(f"{base}/historical-market-data/symbols/EURUSD/ticks",
                     params={"startTime": "2026-10-01T08:00:00Z", "limit": 1000},
                     headers=h).json()
print(len(ticks), ticks[0]["time"], ticks[0]["bid"])

Related error codes

All MetaTrader5 Python functions

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.