How to Model Slippage, Spread and Fees in a Backtest: Cost Sensitivity and Stress Testing
Backtest Learning · BT09
How to Model Slippage, Spread and Fees in a Backtest: Cost Sensitivity and Stress Testing
A gross backtest built on idealized fills shrinks sharply once you subtract real commission, spread, slippage and holding costs, and that friction compounds the more often a strategy trades. This guide shows how to subtract costs in a consistent unit to reach a net result, then confirm how robust that conclusion is with sensitivity analysis and stress grids.
- How to classify commission, spread and slippage and keep their units consistent
- How to avoid double counting by separating per side from round trip and per fill from per trade
- How cost drag widens the gap between gross and net equity curves
- How sensitivity analysis and a two-dimensional stress grid test robustness
Key takeaways
- Compare strategies on net P&L after subtracting at least commission, spread and slippage in a consistent unit, not on gross.
- Separate per side from round trip and per fill from per trade so you avoid double counting or undercounting.
- Cost drag accumulates with turnover, so the gap between gross and net equity curves widens the more you trade.
- Run baseline, 1.25x, 1.5x and 2x cost-sensitivity scenarios to see at which multiple you cross break-even.
- Use a two-dimensional stress grid such as slippage by commission to check that a conclusion does not rest on one assumption.
Contents
This guide explains how to move a strategy’s idealized, gross backtest result from a tool such as TradingView toward a realistic net result that reflects commission, spread, slippage and holding costs. It starts with the answer, then works through cost classification, the per-side versus round-trip distinction, how to think about the TradingView settings, spread modeling, a gross-versus-net comparison, sensitivity analysis, stress grids and finally an estimator where you can try your own numbers. If you want the wider context first, the complete TradingView backtesting workflow frames where this lesson fits.
The answer in 30 seconds
The conclusion is simple. Compare strategies on net P&L after costs, not on gross, idealized P&L. At minimum, subtract three items one by one in the same unit: commission, the bid/ask spread and slippage. For high-turnover strategies, small per-trade costs stack up and quietly push expectancy down. A curve that looked attractive on a gross basis can turn flat, or even slope downward, once it is measured net.
Throughout this article we use a single set of fictional, illustrative data: gross average P&L of 5.0 cost units per trade and an assumed round-trip cost total of 3.0 cost units. Here a “cost unit” is a relative value expressed in your account currency; it can stand for an amount, pips or a percentage, as long as every input uses the same unit. In this example, net expectancy per trade is 5.0 − 3.0 = 2.0 units, and this after-cost figure matters more as the number of trades grows. For how to read expectancy and profit factor, see how to read backtest results.
Classifying costs: what to subtract
Managing costs by type prevents both double counting and omissions. Your analysis goal decides how far you go.
- Commission: the explicit fee paid to the broker. Units vary: per fill, as a percentage of trade value, or per contract.
- Bid/ask spread: the gap between the bid and the ask. A known cost that arises structurally whenever you cross with a market order, and it varies by instrument and time of day.
- Slippage: the difference between your assumed price and the actual fill price. An uncertain cost that widens in thin books, on sharp moves and with larger order sizes.
- Swap / financing: a cost incurred by holding a position overnight, including FX and CFD swaps, futures rollover and crypto funding rates.
- Borrow fee: the cost of borrowing stock to sell short, which moves with supply and demand for the symbol.
- Taxes: dependent on the regime and your circumstances. This article does not give tax advice, so manage them separately.
The table below organizes this classification by when the cost occurs and how easy it is to estimate. The minimum three — commission, spread and slippage — occur on almost every fill, so subtract those first.
| Cost type | When it occurs | Ease of estimation | Include as minimum? |
|---|---|---|---|
| Commission | Per fill | High (specified) | Include |
| Spread | Per fill | Medium to high | Include |
| Slippage | Per fill | Low (use a distribution) | Include |
| Swap / financing | While held | Medium | Include if holding |
| Borrow fee | While short is held | Medium | Only when relevant |
| Taxes | On realization, etc. | Regime-dependent | Manage separately |
Per side vs round trip: avoiding unit errors
The most common accident when applying costs is a unit mismatch. Because one trade splits into an entry fill and an exit fill, costs are, as a rule, counted round trip. Use a per-side figure as a round-trip figure and you undercount; layer a round-trip figure onto each fill and you double count.
- Per side vs round trip: if commission is per fill, one trade carries two charges (round trip). In our example, per-side commission 0.4 × 2 = round-trip 0.8 units.
- Per order vs per fill vs per contract: when one order is split into several fills, charges levied per fill rise with the number of fills. Charges proportional to quantity scale with size.
- Percentage of trade value: percentage-type commission is proportional to position value. Do not mix it with a fixed-amount type, and state clearly which unit applies.
The spread works the same way. Estimating 1.2 units round trip and assigning 0.6 units each to entry and exit is consistent; adding the full 1.2 to each fill on top of that double counts. If you want to review this alongside exit timing and entry efficiency, MFE and MAE exit analysis is a useful companion.
TradingView commission and slippage
There are two main places to apply costs in TradingView. One is the commission and slippage fields in the strategy Properties panel; the other is the arguments of the strategy() function in Pine Script. Values entered in the Properties panel are reflected in the backtest immediately, while specifying them in the script fixes the assumptions when you publish or share it.
Commission units
Commission is commonly chosen from units such as a fixed amount, a percentage or per contract. What matters here is understanding whether the chosen unit is per side or round trip. In many cases the value is charged per fill, so one trade carries two charges. The round-trip figure of 0.8 units above is the result of charging 0.4 per side on each fill.
Slippage units
Slippage is commonly added in ticks. The assumed market fill price is shifted by the configured number of ticks in the unfavorable direction. Because real slippage changes with conditions, do not rely on a single fixed value; give it a range in the sensitivity analysis described below.
Modeling the spread
The spread is a known cost, but it is not constant. How precisely you model it depends on the nature of the strategy. Since no single universal setting exists, check whether your conclusion holds across several models.
- Fixed spread: the simplest approximation, using one constant value across the whole period. Manageable for liquid symbols traded in a narrow window, but it diverges from reality when a strategy spans fast markets or thin sessions.
- Session-based spread: vary the spread by session (Tokyo, London, New York and so on) or around the open and close. This improves accuracy for strategies that cross time zones.
- Volatility-linked: widen the spread according to a volatility measure. This prevents underestimating cost for strategies that include news releases or fast-moving conditions.
In practice, first get a sense of net performance with a fixed spread; if the result is thin, refine it to a session-based or volatility-linked model and confirm the conclusion does not change. To read the market regime from an outside vantage point, an environment-awareness tool such as the Macro Research Workbench can also help.
Gross vs net equity curves
The impact of costs can look small per trade, but once it stacks up over the number of trades it is no longer negligible. Here we use the earlier settings (gross average 5.0, round-trip plus holding cost total 3.0 units) over 400 trades of fictional, illustrative data to compare the gross and net equity curves.
Cumulative gross P&L is 400 × 5.0 = 2,000 units, the cumulative round-trip and holding cost is 400 × 3.0 = 1,200 units, and net is the difference, 800 units. Indexed, gross rises from a start of 100 to 180 while net rises from 100 to 132, and the gap widens the more trades accumulate. This is cost drag, and the difference in slope bites harder the more often a high-frequency strategy trades.
A strategy whose after-cost slope is close to flat sinks below expectancy on even a small overshoot in costs. To also read the impact on drawdown depth and recovery time, see maximum drawdown analysis.
Test how costs bite on your own backtest
First estimate a symbol’s spread and fees with the Trade Cost Calculator, then load your Strategy Tester CSV or XLSX into the free Backtest & Robustness Lab to visualize KPIs, equity and drawdown on real data. When you need sensitivity to moving cost assumptions or a deeper cost decomposition, step up to Pro cost sensitivity and cross-sectional analysis.
Cost sensitivity: baseline to 2x
Real costs move day to day and are not captured by an average alone. So set a baseline cost and raise it in stages to observe where net performance breaks down. There is no universally correct number of steps, but increments such as baseline, 1.25x, 1.5x and 2x make the point where you cross break-even easy to see.
The table below applies those multipliers to the round-trip and holding cost (baseline 3.0 units × 400 trades = 1,200 units) on fictional, illustrative data with gross gross profit of 5,000 and gross gross loss of 3,000 (gross profit factor 1.67). Costs are added to the loss side as a simple treatment.
| Scenario | Cost multiplier | Cost per trade | Cumulative cost | Net profit | Net expectancy/trade | Net PF | Status |
|---|---|---|---|---|---|---|---|
| Baseline | 1.00× | 3.0 | 1200 | 800 | 2.0 | 1.19 | Headroom |
| Slightly worse | 1.25× | 3.75 | 1500 | 500 | 1.25 | 1.11 | Headroom |
| Worse | 1.50× | 4.5 | 1800 | 200 | 0.5 | 1.04 | Near break-even |
| Much worse | 2.00× | 6.0 | 2400 | -400 | -1.0 | 0.93 | Below break-even |
In this example, when costs double from baseline the net profit falls to −400 units and net profit factor sinks to 0.93, so expectancy turns negative. Already at 1.5x, net profit thins to 200 units, showing the break-even point is close. It is important not to judge from the baseline alone and conclude there is headroom, but to raise costs to the multiples that could plausibly occur. Choose the multipliers and increments from measurements of your instrument and your broker’s specifications.
Multidimensional stress grids
Costs do not always move on one axis alone. To see compound stress — slippage and commission worsening at once, or a wider spread overlapping with poorer fills — a two-axis grid is effective. Below is a heatmap of fictional, illustrative data that combines a commission multiplier (columns) and a slippage multiplier (rows) and shows net profit (units) with both color and number. Spread 1.2 and swap 0.4 are held fixed.
Across this grid’s range net profit stays positive, but if you widen the stress further — to something like commission 2.0x — it crosses break-even as Table 2 shows. The grid is a tool for seeing the whole surface of which combinations thin the result and by how much, so you can confirm a conclusion does not depend on a single optimistic scenario. Combined with walk-forward methods that reveal regime-by-regime degradation, you can test robustness on both the time axis and the cost axis. For the design, see walk-forward and out-of-sample analysis. The cost impact when several strategies are combined is covered in multi-strategy portfolio backtesting.
Try the cost estimator
Enter trade count, gross average P&L per trade, per-side commission, round-trip spread equivalent and slippage equivalent, and this estimates total cost, net expectancy and break-even cost. Values are calculated only in your browser and are never sent anywhere. Enter everything in the same unit (an amount, a pips equivalent or a percentage). If JavaScript is off, see the static worked example directly below.
Trade cost estimator
Enter values above and press Estimate to see total cost, net expectancy and break-even cost.
- Total cost per trade–
- Total cost (all trades)–
- Net expectancy/trade–
- Net total P&L–
- Break-even cost–
- Headroom to break-even–
This estimate is for illustrating the concept and does not guarantee performance or profit. Mixing units makes the result meaningless, so keep everything in one of an amount, a pips equivalent or a percentage. Add swaps, borrow fees and taxes separately as your goal requires.
Practical checklist
- Are you comparing strategies on net rather than gross P&L, and did you include the minimum three of commission, spread and slippage?
- Did you keep per side vs round trip, per fill vs per trade, and amount vs percentage straight, avoiding double counting and undercounting?
- Did you confirm in the official documentation whether TradingView’s commission and slippage units are per side or round trip?
- Did you test the spread with session-based and volatility-linked models, not just a fixed value, and confirm the conclusion holds?
- For holding strategies, did you include swap, financing and borrow fees, and manage taxes separately?
- Did you run baseline, 1.25x, 1.5x and 2x cost sensitivity and identify at which multiple you cross break-even?
- Did you use a two-dimensional grid such as slippage by commission to check robustness to compound stress across the surface?
- Did you align the included costs and unit assumptions across the strategies you compare?

