Home · Guides · Backtest an XAU/USD intraday strategy in Python with 1-minute data

GUIDE · XAU/USD · BACKTEST · PYTHON · CATALOG VERIFIED 2026-10-08

Backtest an XAU/USD intraday strategy in Python with 1-minute data

A useful XAU/USD intraday backtest needs 1-minute bars on one clock, an explicit spread cost and no look-ahead. AI Options Data Store sells XAU/USD spot 1-minute OHLC (bid-side, UTC) from 15 Mar 2009 to 2 Oct 2026 as Parquet; the example below tests a London opening-range breakout in plain pandas.

Get the XAU/USD packXAU/USD historical dataSession analysis Free sample (no email)

Download the sample → check the columns

Dates on this page are read from the live file catalog, not typed by hand. Full matrix: /coverage.

What the data gives you

One row per minute with open, high, low and close of the bid quote, timestamps in UTC. Minutes without a quote are absent and weekends are closed, so loop over days that exist rather than a calendar.

Bid-side prices mean a long entry really fills at the ask: subtract a spread per trade. The example uses a fixed USD-per-ounce assumption; set your own.

Example: London opening-range breakout

Box = high and low of 08:00–09:00 London time. Enter on the first break of the box until 16:00, exit at the 16:00 close. Entry is at the box level (a stop order), so the bar that breaks it is not used to decide the price.

import pandas as pd

df = pd.read_parquet('XAUUSD_SPOT_1min_2025-01-01_2025-12-31.parquet').set_index('datetime')
lt = df.index.tz_convert('Europe/London')
df['day'], df['hm'] = lt.date, lt.hour * 60 + lt.minute

SPREAD = 0.30                                   # assumed USD per ounce, per trade
pnl = []
for day, g in df.groupby('day'):
    box = g[(g.hm >= 480) & (g.hm < 540)]       # 08:00-09:00 London
    run = g[(g.hm >= 540) & (g.hm < 960)]       # 09:00-16:00
    if box.empty or run.empty:
        continue
    hi, lo = box.high.max(), box.low.min()
    brk = run[(run.high > hi) | (run.low < lo)]
    if brk.empty:
        continue
    b = brk.iloc[0]
    if b.high > hi and b.low < lo:              # both sides in one bar: skip
        continue
    side, entry = (1, hi) if b.high > hi else (-1, lo)
    pnl.append(side * (run.close.iloc[-1] - entry) - SPREAD)

pnl = pd.Series(pnl)
print('total', round(pnl.sum(), 2), 'win rate', round((pnl > 0).mean(), 3))

Avoid the usual mistakes

Look-ahead: decide with data up to the bar before you act, and fill at a level or the next bar open, not the close of the signal bar.

Clock: build windows in local time with tz_convert so daylight-saving changes do not shift your box by an hour.

Costs: include spread (and swap if you hold overnight). Results without costs flatter intraday rules.

Other timeframes: build M5, H1 or daily bars first with the resampling guide; session windows are in the session analysis guide.

Exactly which fields are in the files

XAU/USD 1-minute files

ColumnTypeMeaning
datetimetimestamp (UTC)Minute start, timezone-aware UTC
open / high / low / closefloatBid-side XAU/USD quote OHLC, US dollars per troy ounce

Not included: ask-side prices, futures, options, implied volatility or Greeks. 1-minute bars, not tick data.

Format: Parquet (XAUUSD_SPOT_1min_….parquet), UTC. Run the example on the free September 2026 sample before buying.

FAQ

Where can I get XAU/USD 1-minute data for backtesting?

AI Options Data Store sells XAU/USD spot 1-minute OHLC from 15 Mar 2009 to 2 Oct 2026 as Parquet with UTC timestamps, paid by UPI; a free one-month sample needs no email.

Do I need a backtesting library?

No. A daily loop in pandas is enough for most intraday rules; move to a vectorised version or a library once the logic is settled.

How do I account for the spread?

The quotes are bid-side, so subtract an assumed spread per round trip (or add it to long entries). Use a value that matches your own execution.

Are the timestamps UTC or local?

UTC, minute start, normalised across daylight-saving changes. Convert with tz_convert for London or New York hours.

Can I test on CSV in another tool?

Yes. df.to_csv() writes datetime, open, high, low and close for any year.

Is this XAU/USD or MCX GOLD?

XAU/USD spot in US dollars per troy ounce. MCX GOLD futures are a separate MCX pack.

Get the data

Free sample · Schema · Ask the AI for your data

Get the XAU/USD packXAU/USD historical dataSession analysis Free sample

Related guides

Example code for research only; it is not trading advice.