What it is

A backtest runs your recipe over past candles of one market and one timeframe, takes every trade the rules allow, and charges the trading costs you set. It answers one question: how would these exact rules have traded this history?

You can start a backtest from the Lab yourself, or TES runs one when you describe a strategy (see Building a strategy with TES).

What you can do

  • Pick the market and timeframe
  • Choose the period: a number of days back, or exact start and end dates
  • Set the account: position size (fixed size or % risk per trade), leverage, and daily limits
  • Set trading costs: commission, slippage, spread and overnight swap
  • Re-run with one change at a time and compare backtests

How it works

Markets

The Lab tests forex, metals, crypto, stocks and ETFs on historical market data. Futures and index CFDs are tested on a tracking ETF instead; see Markets and stand-ins.

Timeframes

1m, 5m, 15m, 30m, 1h, 4h and 1d. Every plan, Free included, can use every timeframe. Plans differ in how far back they test.

History per plan

The longest period one backtest can cover:

TimeframeFreeStandardPlus and Pro
1m30 days6 monthsAll available data
5m90 days2 yearsAll available data
15m1 yearabout 6.5 yearsAll available data
30m, 1h, 4h2 years10 yearsAll available data
1d5 years20 yearsAll available data

These are ceilings. A market with less history available gets what exists.

When TES runs a backtest and you have not asked for a period, it picks a window long enough for a meaningful number of candles, within your plan's ceiling. If you ask TES for a longer period than your plan allows, it runs the part your plan covers and tells you.

The account

  • Position size: a fixed size, or risk % of the account per trade, sized from the distance between entry and stop. With risk %, the account grows and shrinks with closed trades.
  • Leverage: each trade's margin must fit the free margin. If the account runs out of margin, part of a position is closed, as TradingView would, and the result shows a margin-call warning.
  • Daily limits (UTC day): a maximum number of trades per day and a maximum number of losing trades per day. A signal past a limit is skipped.

Trading costs

Lab candles are mid prices, halfway between bid and ask. Real orders fill at the bid or ask, so the Lab charges costs on top of the chart. TES backtests include typical trading costs by default. You can change them, or set your own broker's figures, in the backtest settings.

CostHow it is charged
SpreadEvery fill (entry and exit, stops, targets and limits alike) pays half the spread. Set it in price units or as a % of price.
CommissionA % of each fill's value, on entry and on exit, as TradingView's percent commission.
SlippageA number of ticks against you on market entries and stop exits. Limit fills (targets, limit entries) get none.
Swap (overnight financing)A % of the position's value for every broker rollover the trade is open through, at 17:00 New York time, Monday to Friday. Wednesday counts three nights for forex, metals, indices and commodities (the weekend is booked mid-week). Crypto rolls every day, one night each. A positive rate is a cost; a negative rate is a credit.

If a backtest runs with no costs, the result says so and shows how the return would change with typical costs, with a button to use them. A result without costs is optimistic, most of all for short-term strategies.

Fills

  • When a stop and a target are both inside one candle, candle data alone cannot say which was hit first. The Lab reads the candle the way TradingView does (its bar path). The robustness check also re-runs these trades with the stop first, to show how much the result depends on them.
  • Trades still open when the data ends are shown as open, with no profit or loss.

Limitations

  • Results are only as good as the cost assumptions. Typical costs are averages; your broker's spread, commission and swap can be higher, especially around news and at the daily rollover.
  • Forex and metals weekend and daily-break candles are removed (New York time). Public holidays are not.
  • A backtest uses one market and one timeframe. To see whether the idea works elsewhere, run a markets test (see Reading backtest results).
  • Each run counts as one Lab backtest on your plan. See Plan limits for the Lab and Launchpad.