Skip to content
TradingTune
Make it realistic Intermediate

Modeling slippage and commission

A backtest with zero costs is a fantasy, and optimizing against a fantasy tunes your strategy to exploit free trading. The moment you add realistic commission and slippage, many high-frequency, thin-edge settings collapse. Better to find that out now than with real money.

Why a costless backtest lies

Every real trade pays a spread, a commission, and some slippage between the price you wanted and the price you got. Those costs are tiny per trade and enormous in aggregate: a strategy that takes 500 trades a year at a quarter percent round-trip cost pays 125 percent of capital in friction before it makes a cent. Optimize without costs and the search gravitates toward exactly these high-churn settings, because in a frictionless world more trades just means more profit.

Gross profit minus slippage minus commission leaves net. The thinner the edge per trade, the more of it costs eat.

Set the Strategy Tester properties

TradingView's Strategy Tester reads commission and slippage from the strategy's Properties, and you can set sensible defaults right in the strategy() call so every backtest starts honest. Commission can be a percent of the trade value or a fixed cash amount per order; slippage is set in ticks. Tune these to your broker and instrument, not to whatever makes the curve look best.

Realistic costs in strategy() (Pine v5)

Pine v5

Commission as a fixed cash-per-order charge plus a few ticks of slippage. Adjust to your broker; never set costs to zero to flatter a result.

//@version=5
strategy("Cost-Aware Strategy", overlay=true,
     commission_type=strategy.commission.cash_per_order,
     commission_value=1.0,        // 1.00 per order, both sides
     slippage=3,                  // 3 ticks of slippage per fill
     default_qty_type=strategy.percent_of_equity,
     default_qty_value=10)

Defaults by instrument

Liquid large-cap stocks and major FX pairs slip little; small caps, crypto alts, and low-volume futures slip a lot. When unsure, model costs on the pessimistic side and let the strategy earn its keep.

The break-even win rate shifts

Costs raise the win rate you need just to break even. If your average winner and loser are the same size, you break even at 50 percent before costs, but every dollar of round-trip cost pushes that threshold up. The formula below makes the shift concrete, and it is why a strategy that looks profitable at zero cost can be a loser once you model reality.

Break-even win rate after costs

Python

The win rate needed to break even given average win, average loss, and round-trip cost per trade. Rising costs raise the bar.

# Break-even win rate given average win, average loss, and per-trade cost.
def break_even_win_rate(avg_win, avg_loss, cost):
    net_win = avg_win - cost
    net_loss = avg_loss + cost
    return net_loss / (net_win + net_loss)

break_even_win_rate(100, 100, 0)    # 0.50  (no costs)
break_even_win_rate(100, 100, 10)   # 0.55  (10 per round trip)

Always optimize with costs on

Set your costs first, then optimize. If you tune on a frictionless backtest and add costs afterward, the settings you chose were selected for the wrong objective and the realistic result will disappoint. With costs on from the start, the optimizer naturally prefers fewer, higher-conviction trades, which is what you want to trade anyway. This is one of the common backtesting mistakes precisely because it is so easy to skip.

The one rule

Model commission and slippage before you optimize, on the pessimistic side, so the search rewards a real edge instead of free churn.

Key takeaways

  • Zero-cost backtests reward high-churn settings that lose money live.
  • Set commission and slippage in the Strategy Tester properties.
  • Costs raise the win rate you need just to break even.
  • Optimize with costs on from the start, not bolted on after.

Frequently asked questions

What slippage and commission should I use for backtesting?

Match your broker and instrument. Liquid large-cap stocks and major FX pairs need only a tick or two of slippage and small commission; illiquid small caps, crypto alts, and thin futures need much more. When unsure, model costs pessimistically.

Should I add costs before or after optimizing?

Before. If you optimize on a costless backtest and add costs afterward, the settings were chosen for the wrong objective. With costs on from the start, the optimizer prefers fewer, higher-conviction trades.

Why does a profitable backtest become a loss after adding costs?

Thin-edge, high-frequency settings make money only in a frictionless world. Real commission and slippage are small per trade but huge in aggregate, and they raise the break-even win rate above what the strategy actually achieves.

Share this guide
X LinkedIn Email

All guides

Put it into practice

Install TradingTune and optimize any TradingView strategy right in your browser. Free tier, no API keys. A free account is required to run.

Add to Chrome, it's free