Backtesting Costs: Spread, Commission and Slippage
See how spread, commissions and slippage change a backtest. Use worked R examples and a cost ledger that avoids double counting.
Trading costs can turn a positive backtest into a negative one. Start with the result before costs, then account for the spread, commission and slippage that apply to the assumed execution. The important part is consistency: know which costs are already inside your fill prices before adding anything else.
This guide builds a simple cost worksheet. The numbers are hypothetical and are not a quote from a broker or a performance result from TestMax.
Separate the three costs
| Cost | What it represents | A common mistake |
|---|---|---|
| Spread | Difference between bid and ask | Subtracting it again after using bid/ask execution prices |
| Commission and fees | Charges associated with execution | Counting one side when the quoted rate is per side |
| Slippage | Difference between your assumed price and the execution price | Using the same optimistic fill on every fast or gapping bar |
If a forex round trip buys at the ask and sells at the bid, its fill-to-fill result already reflects the spread. A midpoint-only calculation does not. If your execution assumptions are mixed, a precise spreadsheet can still give you the wrong answer. OANDA's spread explanation describes bid/ask spread measurement.
For positions held across financing or rollover boundaries, other charges can apply. This worksheet focuses on an intraday exercise; extend it before using it for longer holding periods.
Put costs in the same unit as the result
Suppose your initial risk is $100. A $7 total round-trip cost is 0.07R. A gross winner of +1.5R becomes +1.43R, and a gross loser of -1R becomes -1.07R, assuming the $7 applies to each outcome.
Keep 1R tied to the planned risk at entry. If you later tighten a stop, do not shrink the denominator and make the trade appear larger after the fact.
You can express expectancy in money or R. R is convenient when sizes vary, provided every row uses the same definition of initial risk.
A strategy can be positive before costs and negative after them
Imagine 100 trades with 45 winners averaging +1.5R and 55 losers averaging -1R:
gross total = 45 × 1.5R − 55 × 1R = +12.5R
That is +0.125R per trade before costs. Now apply different cost assumptions:
| Average round-trip cost | Total cost for 100 trades | Net result | Net average per trade |
|---|---|---|---|
| 0.05R | 5R | +7.5R | +0.075R |
| 0.10R | 10R | +2.5R | +0.025R |
| 0.15R | 15R | -2.5R | -0.025R |
These scenarios do not estimate your actual costs. They show how little room the example has for execution friction. A small apparent edge needs a careful cost model and further testing.
The win-rate calculator is a useful companion for checking how costs change a breakeven calculation. Keep the detailed trade record too; averages can hide difficult sessions.
Build a cost ledger you can audit
Add these columns to your trading journal:
| Field | What to record |
|---|---|
| Price basis | Bid, ask, midpoint or another documented convention |
| Entry and exit assumption | Order type and when it becomes eligible to fill |
| Gross result | Result before any separately modeled cost |
| Cost already included | Spread or fees already reflected in the result |
| Additional commission | Correct total for entry and exit |
| Additional slippage | Entry and exit assumptions, shown separately |
| Net result | Gross result minus costs not already included |
| Uncertainty note | Gap, missing data, ambiguous bar or unusual conditions |
The “already included” column saves more mistakes than adding another decimal place. If you cannot explain how one row was calculated, pause the analysis and fix that row before interpreting the average.
Give difficult executions their own scenario
A resting limit touched by a candle is not proof that an order at that price would have filled. A stop crossed during a gap may execute beyond the trigger. Historical OHLC bars do not reconstruct queue position or every change in available liquidity.
Make the uncertainty visible. For example, calculate one result with your standard assumptions and another with less favorable execution on flagged trades. Do not apply a universal number of ticks and call it realistic without evidence about the instrument, time and order type.
Likewise, separate scheduled-news sessions if your strategy trades them. If the rules exclude those sessions, make that exclusion before viewing the result. Deleting an ugly news day afterward changes the strategy you tested.
Why tight stops magnify the issue
A fixed $5 charge is 0.05R on $100 of planned risk, but 0.20R on $25 of planned risk. Smaller monetary risk can therefore make the same charge much larger relative to the expected trade result.
This does not mean widening a stop improves a strategy. A wider stop changes the trade. It means position size, stop distance and costs need to be evaluated together. The futures calculator can help translate tick distances into dollar amounts for its supported contracts.
Use replay for observation and a worksheet for assumptions
TestMax provides historical market replay and simulated order execution. Do not assume every real execution cost is automatically represented in its results. Record the available instrument's specifications and apply any additional cost assumptions separately, avoiding double counting.
Create a TestMax account and replay a small block of sessions using a supported instrument. Save every trade, then compare the gross result with two clearly labeled cost scenarios. Free access covers a limited recent history window on eligible instruments, including NQ and ES futures; MNQ, MES and GC require Pro. Review the current plans before choosing your market.
Your next decision should come from the difference between those scenarios: whether the test remains worth investigating, which execution assumption needs better evidence, or which rule needs a new, separately recorded experiment. Use the manual forex backtest if you want a complete entry-and-exit exercise to accompany the worksheet.