TradingView Backtesting

Transaction Cost Analysis: Benchmark Each Trading Decision

Transaction cost analysis (TCA) compares an executed order with a defined price benchmark and accounts for explicit fees. A useful ledger connects the trading decision, order arrival, quotes and individual fills. It separates price movement during delays from execution relative to the quote, without adding the same spread or slippage twice. A TradingView backtest export contains simulated trades; it cannot establish live execution quality without broker and quote records.

See the decision guide

Record the decision, arrival and each execution

Choose the arrival event before comparing orders. It might be broker submission or venue receipt; those are different timestamps. IBKR defines its arrival benchmark using the NBBO midpoint when the order is submitted. This ledger uses submission as arrival, and a synchronized quote immediately before each fill. Midpoint means (bid + ask) / 2, not the last traded price.

  • Use an explicit time zone and timestamp precision. Record quote age and clock offsets; a minute-level execution time cannot support a millisecond latency claim.
  • Long entry and short exit are buys; long exit and short entry are sells. Position direction and execution side are different fields.
  • Use raw execution prices and a separate fee ledger. If a price already includes fees, remove that adjustment before adding F.
RecordFields to retainReason
Parent orderOrder ID, instrument, side s, intended quantity Q, currency, unit or contract multiplierKeep all child fills and cancellations attached to the original decision.
DecisionDecision time tD and decision benchmark PDDefine when the intended position was chosen and which price was then observable.
ArrivalSubmission time tA, bid, ask and midpoint MAMeasure the price change before the order began working. Store receipt time separately if available.
Fill iFill ID, execution time ti, positive quantity qi, fill price Pi, pre-fill bid/ask and midpoint MiMatch executions to quotes without using a quote that arrived after the fill.
Explicit chargesCommission, exchange and regulatory fees, transaction taxes, rebates, currency and posting timeUse net charges F once; a rebate reduces F. Allocate parent fees without duplicating them across fills.
Unfilled remainderCancel/expiry time, remaining quantity and a preselected evaluation price PT at time TMake the opportunity-cost convention visible rather than silently dropping missed trades.

An additive attribution for the filled quantity

For cash shares in one currency, let q = sum(qi), with qi > 0. Set s = +1 for buys and s = -1 for sells. The filled decision cost is C = sum[s × qi × (Pi - PD)] + F. The following decomposition is an arithmetic identity, so its components must sum to C. Negative components represent price improvement or favorable movement.

  • C in basis points = 10,000 × C / (q × PD), for PD > 0. Convert each component using that same denominator if the displayed bps must add up.
  • Arrival cost uses MA instead of PD: sum[s × qi × (Pi - MA)] + F = W + E + F. An arrival-based bps figure uses q × MA and therefore cannot be directly added to decision-based bps.
  • W can contain market movement, information effects and the effects of your own trading. The identity does not identify causal market impact or prove a broker caused the change.
  • For linear contracts, multiply each price difference by the contract multiplier. Inverse contracts and currency conversion require their actual payoff and conversion rules; the cash-share formula is not universal.
ComponentDollar formulaInterpretation
Pre-arrival delayD = s × q × (MA - PD)Movement from the decision benchmark to submission.
Movement while workingW = sum[s × qi × (Mi - MA)]Movement from arrival to the quote before each fill.
Execution versus midpointE = sum[s × qi × (Pi - Mi)]The one-way signed execution concession relative to contemporaneous quotes.
Explicit feesF = total charges - rebatesAmounts paid outside the raw execution prices.
ReconciliationC = D + W + E + FThe same result as comparing every fill directly with PD.

A timestamped buy order costs $16, or 16 basis points

Assume a hypothetical purchase of 100 shares, quoted in USD, with a one-share unit multiplier and $2 in total fees. All timestamps below are UTC on 2026-10-01, and each quote is observable just before its stated event. These are illustrative records, not a measured trade or a claim about typical trading costs.

  • The quantity-weighted fill price is (40 × 100.08 + 60 × 100.18) / 100 = $100.14.
  • D = 100 × (100.04 - 100.00) = $4. W = 40 × 0.02 + 60 × 0.12 = $8. E = 40 × 0.02 + 60 × 0.02 = $2.
  • C = $4 + $8 + $2 + $2 = $16, or 16 bps on the $10,000 decision notional. Direct check: 100 × (100.14 - 100.00) + 2 = $16.
  • The decision-to-submission delay is 500 ms. The two fills occur 200 ms and 600 ms after submission. Time alone is not a dollar cost: D and W depend on the observed price changes.
  • Arrival cost is $8 + $2 + $2 = $12, or about 12.00 bps on $10,004. It excludes the $4 movement before submission.
Event and timeQuantityBid / askBenchmark or fill
Decision 14:30:00.000100 intended$99.99 / $100.01PD = $100.00
Submission 14:30:00.500100 submitted$100.02 / $100.06MA = $100.04
Fill 1 14:30:00.70040 bought$100.04 / $100.08M1 = $100.06; P1 = $100.08
Fill 2 14:30:01.10060 bought$100.14 / $100.18M2 = $100.16; P2 = $100.18

Avoid counting the spread twice

Execution versus midpoint already includes the spread paid in the fill. In the buy example, each $0.04 quoted spread contributes a $0.02 one-way concession because the order fills at the ask. Adding another half-spread to E would count the same price difference again. Effective spread is commonly reported as twice the signed fill-minus-midpoint difference; that doubled statistic is not an additional one-way cash expense.

  • If a separate spread attribution is needed, define Xi as the pre-fill ask for a buy or bid for a sell. Then E = sum[s × qi × (Xi - Mi)] + sum[s × qi × (Pi - Xi)]. The first term is the quoted half-spread; the second is execution beyond that quote or price improvement.
  • This split requires valid quotes at every fill. A midpoint fill has E = 0; its negative residual offsets the quoted half-spread. Do not force both parts to be positive.
  • Do not add arrival slippage, W and E together: arrival slippage already contains W + E. Use the total or its components.
  • For a simulated P&L that already includes commission and an adverse fill adjustment, retain those costs in the result. Apply only an explicitly calculated incremental scenario change; do not subtract the entire TCA total again.

Check the sell sign and include unfilled orders

For a hypothetical sale of 100 shares, use PD = $50.00, MA = $49.98, pre-fill midpoint M = $49.95, fill P = $49.94 and F = $1. With s = -1, D = $2, W = $3 and E = $1. Total cost is $7, or 14 bps on $5,000. The lower sale price is a cost; using the buy sign would incorrectly classify it as a benefit.

  • A sell at $50.02 against PD = $50.00 has a price cost of -$2 for 100 shares. After $1 in fees, total cost is -$1, or -2 bps. Keep favorable costs negative.
  • For a parent order with unfilled quantity U = Q - q, define opportunity cost O = s × U × (PT - PD). Total implementation shortfall in this cash-share convention is C + O, divided by Q × PD for bps. Choose the evaluation horizon before inspecting the outcome.
  • Partial-fill example: intend to buy 100 shares at PD = $100, fill 60 at $100.10, pay $1, and leave 40 unfilled when PT = $100.30. Filled cost is $7; opportunity cost is $12; total is $19, or 19 bps on $10,000.
  • If nothing fills, the fill-price average is undefined. Retain the parent order and calculate opportunity cost from the chosen horizon, plus any actual charges. Cancelling an order does not justify erasing it from the decision sample.

Reject incomplete records before comparing brokers or strategies

A ledger can reconcile numerically and still use the wrong observations. Validate order identity, timestamps and units first. A stale midpoint or a mixed currency can overwhelm the price differences being measured.

  • Flag missing quotes, crossed bid/ask data and quotes outside the allowed age tolerance. Missing cost is not zero cost. Do not silently replace a missing quote with the bar close.
  • Deduplicate fills by execution ID; require positive fill sizes and q ≤ Q, or explain order amendments and reversals. Preserve a decision history when the intended quantity changes.
  • Use one denominator and one currency per aggregation. Across orders, sum costs and benchmark notionals before calculating aggregate bps; do not take an unweighted average of unequal-size orders.
  • Compare similar instruments, order sizes, urgency, sessions and order types. A lower observed cost can result from a different order mix rather than superior execution.
  • Borrow charges, financing and multi-day holding costs belong in a broader net-performance ledger when relevant. State whether they are included; do not relabel them as a bid-ask spread.

Use TradingView exports for the part they can support

TradingView lets you export trade data separately from summary metrics. Its strategy trades come from a broker emulator. Export the trade list CSV and retain the simulation settings, including commission and slippage. To analyze live execution, join actual broker fills with your decision log and synchronized quotes in a separate ledger.

  • Backtest Deep Report analyzes supported CSV fields for performance and risk. The TCA ledger and decompositions on this page are independent calculations; the report does not currently expose these as a built-in TCA method.
  • Use Pine Script AI Coding Agent to help revise explicit simulation-cost assumptions after you define them. Generated code requires review and validation; code changes cannot reconstruct missing live order or quote records.
Available evidenceWhat it supportsWhat remains missing
TradingView simulated trade CSVEntry/exit prices, times, quantities and the exported performance fieldsActual order receipt, broker fills and contemporaneous executable quotes.
Pineify Backtest Deep Report parserTrade direction, signal, entry/exit time and price, quantity, net P&L and excursionsDecision and arrival quotes, child execution IDs, and a separate itemized fee ledger.
Broker executions plus quote and decision logsThe independent TCA calculations defined on this pageCausal market-impact estimates still require additional assumptions and analysis.
Where Pineify fits

Backtest Deep Report

Inspect supported performance and risk fields from a TradingView trade CSV. Keep the decision, quote and fee ledger separate for transaction cost attribution.

Also useful: Pine Script AI Coding Agent. Turn documented simulation assumptions into a strategy revision, then review the code and rerun the backtest with the changed settings.

Explore Backtest Deep Report

Frequently asked questions

Educational information, not investment advice. All numerical records are hypothetical. Benchmark choices and data quality affect measured costs; simulated fills and past execution results do not guarantee future outcomes.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.