Backtesting guide

Cost Model Realism Backtesting

Cost model realism backtesting means representing the fees, slippage, spread, financing, fill rules, and turnover that a strategy is likely to face. The model should match the intended market and execution workflow instead of using one optimistic percentage for every trade.

Read the practical guide

Key Takeaways

  • List every cost channel before deciding how to encode it.
  • Match commission and fill assumptions to the instrument and order workflow.
  • Inspect gross and net results because turnover can dominate a small edge.
  • Stress-test worse cost assumptions instead of relying on one estimate.

Create a cost inventory

Map explicit commissions, bid-ask spread, slippage, exchange and regulatory fees, borrow or financing costs, and market impact. Not every component can be modeled precisely in a bar-based backtest. State which items are included, approximated, or omitted so the net result remains interpretable.

  • Separate fixed, percentage, per-contract, and time-dependent costs.
  • Use instrument-specific assumptions when tick size and liquidity differ.
  • Estimate costs at the expected order size, not an unrelated account size.

Encode TradingView assumptions explicitly

Pine Script strategies can set commission type and value, slippage in ticks, and limit-order fill verification through strategy declaration properties. These inputs affect simulated orders but do not reproduce an order book or guarantee live fills. Spread may need to be represented through price or fee assumptions, depending on the strategy design.

  • Set commission_type and commission_value to match the fee convention.
  • Use slippage as an explicit stress input rather than an unrecorded adjustment.
  • Review backtest_fill_limits_assumption when limit fills drive the result.

Stress-test the net edge

Run a small grid from the base estimate to adverse but plausible costs. Compare net profit, drawdown, trade count, turnover, and profit factor. A strategy that changes sign after a minor cost increase has little historical margin for error. The stress range should be set from execution evidence when available, not from the level the backtest can tolerate.

  • Test higher slippage during volatile periods or at larger order sizes.
  • Check whether small gross winners become net losers after costs.
  • Repeat the test when the broker, venue, instrument, or order type changes.

Direct Pineify workflow

Put explicit cost assumptions into the strategy

Pineify Pine Script AI Coding Agent can help add or revise commission, slippage, and fill assumptions in strategy code. Strategy Optimizer can then compare the result across a declared cost range.

Pine Script AI Coding Agent

Generate or revise Pine Script strategy properties for explicit simulation assumptions.

Edit the strategy
Strategy Optimizer

Compare performance across cost or execution-related input scenarios.

Test cost scenarios

Boundary: Pineify cannot infer a broker fee schedule, predict market impact, or reproduce every live fill. The user must supply defensible execution assumptions.

This page is educational and does not provide investment advice. Backtests are hypothetical, depend on their data and assumptions, and do not guarantee future results. Trading can result in substantial loss.

Frequently Asked Questions