Execution & cost
Two pieces of every realistic backtest: how trades exit and what they cost. Get these wrong and your numbers will look great but won't survive contact with reality.
Take-profit & stop-loss
Every trade has both a TP (take-profit) and SL (stop-loss) measured in pips from the entry price.
- TP pips — distance to the profit target. Hit → trade closes as a WIN.
- SL pips — distance to the protective stop. Hit → trade closes as a LOSS.
If neither is hit before the data ends, the trade closes at the last candle's close (END_OF_DATA).
Same-candle resolution
If a single candle's range covers both the TP and the SL — which happens often on volatile bars — the engine doesn't know in real life which fired first. You choose:
| Mode | Behaviour |
|---|---|
sl_first | Assume the worst — SL hit first |
tp_first | Assume the best — TP hit first |
by_candle_direction | Up bars → TP first, down bars → SL first |
skip_trade | Don't take the trade at all |
The conservative defaults will usually understate your strategy slightly. That's safer than the alternative.
Costs
Every trade pays:
Spread
The bid-ask gap, measured in pips. Three modes:
- From CSV — read the
spreadcolumn directly (most accurate if available) - Fixed — apply the same value (e.g.
2 pips) to every trade - Dynamic — recompute from the candle's high/low
Spread is paid once at entry — it widens the effective entry price.
Commission
A flat per-lot fee charged at exit. Set in dollars per lot (e.g. 7 for $7/lot round-turn).
Slippage
Random extra cost beyond the planned entry/exit price. Adds realism — a fast market often fills you a few pips off your trigger.
Slippage in this engine is symmetric and applied to both entry and exit.
Swap (rollover)
The overnight financing charge for holding a position past 5pm New York time.
The current engine ignores swap (V1 simplification). If your strategy holds positions overnight and you want to be precise, mentally subtract a few pips per night from your net PnL, or wait for V1.2 which models swap.
A worked example
Strategy: long EUR/USD with 30 pip SL, 60 pip TP.
| Cost piece | Value | Effect |
|---|---|---|
| Spread on entry | 1.0 pip | entry effectively 1 pip worse |
| Slippage (each side) | 0.5 pip | another 1 pip worse round-trip |
| Commission | $7/lot | flat $7 |
| Net target on a 0.1 lot win | +60 pips × $1/pip × 0.1 = $6 ⇒ minus $7 commission = −$1 |
That's why commission and spread make a huge difference at small lot sizes — and why the engine forces you to model them.