MT4 backtesting with tick data
What .hst and .fxt are, why quality shows n/a, and how to check your data.
Read the file, measure spread, build bars, convert time zones and find gaps. Copy the code and run it; all you need is pandas.
Updated 2026-12-02
The generic CSV has four columns: time (UTC, to the millisecond), bid, ask and volume.
datetime,bid,ask,volume 2026-07-17 10:00:00.088,1.14402,1.14406,6.75 2026-07-17 10:00:00.191,1.14404,1.14405,1.80 2026-07-17 10:00:00.294,1.14403,1.14405,6.75
Volume here is the size quoted on both sides of this tick, not exchange volume. Forex has no single exchange, so there is no volume for the whole market.
import pandas as pd
ticks = pd.read_csv("EURUSD.csv", parse_dates=["datetime"], index_col="datetime")
print(ticks.head())One pip is 0.0001 for EURUSD and 0.01 for yen pairs.
pip = 0.0001 ticks["mid"] = (ticks["bid"] + ticks["ask"]) / 2 ticks["spread"] = (ticks["ask"] - ticks["bid"]) / pip print(ticks["spread"].describe()) print(ticks.groupby(ticks.index.hour)["spread"].median()) # median spread by hour, UTC
The last line shows when trading is cheap during the day. Spread is not constant, so the median tells you more than the average.
m1 = ticks["bid"].resample("1min", label="left", closed="left").ohlc()
m1["ticks"] = ticks["bid"].resample("1min").count()
m1 = m1.dropna() # drop minutes without quotes
h1 = m1.resample("1h").agg({
"open": "first", "high": "max", "low": "min",
"close": "last", "ticks": "sum",
}).dropna()bid. For research you can use mid.label="left" gives each bar its start time, as MT4 and MT5 do.dropna(). Weekends and minutes without quotes leave empty rows.For H4 and D1, convert to your broker's time before building bars, or they will start at a different hour:
server = ticks.tz_localize("UTC").tz_convert("America/New_York").tz_localize(None)
server.index = server.index + pd.Timedelta(hours=7) # GMT+2/+3, New York close
d1 = server["bid"].resample("1D").ohlc().dropna()For the reason, see time zones in forex data.
gap = ticks.index.to_series().diff() print(gap[gap > pd.Timedelta(minutes=10)])
There is always one large gap at the weekend, which is normal. Holidays and gold's daily break show up too.
One million rows of EURUSD ticks take about 45 MB as CSV. Several years take several GB, too much to load at once. You can:
parts = []
for part in pd.read_csv("EURUSD.csv", parse_dates=["datetime"], chunksize=1_000_000):
part = part.set_index("datetime")
parts.append(part["bid"].resample("1min").ohlc())
m1 = pd.concat(parts).dropna()
# a minute may be split between two chunks, so merge once more
m1 = m1.groupby(level=0).agg({"open": "first", "high": "max", "low": "min", "close": "last"})ticks.to_parquet("EURUSD.parquet").On the client's Export data page, choose Python / pandas. You get the CSV, pandas code that runs as it is, and a Jupyter notebook. The columns of each format are on export formats, and the symbols are on forex.
Guides
What .hst and .fxt are, why quality shows n/a, and how to check your data.
How the five tester models differ, what happens to missing ticks, and when to use which.
Spread, slippage, commission, time zones, overfitting: seven reasons and a checklist.
Download the client and, the first time you open it, click “Try free for 7 days” in the setup guide: no sign-up and no payment. Choose one symbol and download its last 7 days of data; every export format and one-click import are available. Once you're sure it suits you, choose a single symbol or all markets.