Backtest Learning · BT09
Reflect commission, spread, slippage and holding costs in consistent units, then ask whether a backtest’s conclusion survives after costs. Load your own trade history into SG Group’s Backtest & Robustness Lab, starting with free basic analysis and stress checks, then extending to Pro’s cost sensitivity or Premium’s two-dimensional stress table as needed. This guide explains cost deductions and sensitivity comparisons. Avoid counting costs already included in the source result twice; these scenarios do not reproduce future executions.
Key takeaways
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 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.
Managing costs by type prevents both double counting and omissions. Your analysis goal decides how far you go.
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 |
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.
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.
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 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 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.
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.
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.
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.
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.
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.
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.
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.
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.
The full picture of the Strategy Tester, CSV analysis and robustness.
BT03 · MetricsRead profit factor, expectancy, Sharpe, win rate and drawdown.
BT08 · Exit efficiencyVisualize exit efficiency and read it alongside costs.
BT10 · PortfolioIntegrate correlation, allocation and drawdown to test cost impact too.