Advertisement IC Markets

Backtesting with variable spread files instead of a fixed spread

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS London Scalper
Posts: 806
Joined: Sun Oct 18, 2026 12:25 pm

Backtesting with variable spread files instead of a fixed spread

Post by FXS London Scalper »

When I started backtesting in MT5, I used a fixed spread setting. My results looked much better than live. Switching to real tick data with variable spreads closed most of the gap.

What changed in the backtest of my EURUSD scalping EA:
  • With a fixed 0.2 pip spread, profit factor was 1.45.
  • With the broker's real tick data and spreads, profit factor dropped to 1.18.
  • Most of the difference came from the first minutes after 08:00 and from news times, where real spreads were much wider.
For scalping, I think a fixed spread backtest is close to useless. The edge is small, and spread changes are a big part of the cost.

In MT5 the option is "Every tick based on real ticks", and the tick history comes from the broker, so it's worth checking that the data covers the period you're testing. Gaps in the tick data can produce strange results.

Do others test with real spreads? And how do you handle brokers whose tick history is incomplete?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Shadow Trader
Posts: 5438
Joined: Wed Sep 09, 2026 5:19 pm

Re: Backtesting with variable spread files instead of a fixed spread

Post by Shadow Trader »

Setting the tester's spread to two pips and running five years of data is easy. It's also quite wrong.

Spreads vary. They tighten in London, widen in the late New York session, spike at rollover, balloon at news. A model that applies the same cost to every trade misprices all of them.

For strategies that trade mainly in liquid hours, a fixed spread near the typical value is a reasonable approximation. For strategies that trade at all hours, or around events, it understates costs in the worst conditions, which are often the conditions where signals appear.

Variable spread data exists. Some brokers provide history with bid and ask. Others allow exporting the spread alongside the bars. Capturing live spread data for a few months and building a model by time of day improves realism.

Another useful sanity test is stress: increase the spread by 50 percent during the highest-volatility hours and see what happens.

The goal isn't a perfect model. It's avoiding the situation where a strategy's entire profit comes from an assumption that doesn't hold live.

Even a rough variable model can be built cheaply. Record the spread at the start of every hour for a month, then use the hourly average in the tester as a time-dependent cost. The first run with realistic spreads often cuts the profit factor noticeably, and that lowered figure is closer to the truth.

How closely did the live spread match the assumption made in the last test?
Post Reply