GUIDE · TESTING A STRATEGY

Data and methodology

What a backtest here is made of: the prices and how they are adjusted, the list of stocks and what it leaves out, how a trade fills and what it costs, how the result is judged, and how to check it somewhere else. Where the engine does not do something, this page says so.

The data

WhatWhere it comes fromDetail
HistoryAlpaca, the consolidated US tapeEvery US exchange's trades, regular session 09:30 to 16:00 New York by default; the extended day 04:00 to 20:00 on request.
Live pricesIEX, through AlpacaThe newest 15 minutes of a session come from IEX alone, so their volume is IEX's share; everything older is the full tape.
Daily barsFrom 2016About ten years of sessions for any US-listed stock or ETF.
One-minute barsThe last 120 sessionsAbout six months.
Five-minute barsThe last 600 sessionsAbout two and a half years; hourly and longer intraday bars are folded from them.
AdjustmentSplits onlyPrices are split-adjusted. Dividends are not folded in, so every result is a price return, not a total return.
Missing barsNone inventedA run uses the bars the tape has. A session the provider is missing is simply absent; no bar is interpolated.

A finished month of bars is cached once and re-read only when a split has changed the adjusted prices, so two runs of the same script on the same range see the same bars.

The universe, and the bias it carries

The tester runs any US-listed stock or ETF you name, and NQ, MNQ, ES and MES futures for signed-in accounts. The screener and the market scan run across a fixed list: about 1,400 US stocks today, chosen by dollar volume, of which about 1,180 are scanned on a given day (the rest are skipped when their data is incomplete). The list is today's. Companies that were delisted, taken over or fell out of it over the last ten years are not in it.

That is survivorship bias, and it is real in any rule applied across the list: the names that failed are missing, so the list flatters. A backtest of one symbol you choose is a different question. It tests that symbol's own history, and the result card says so.

Fills and costs

RuleWhat happens
A rule fires on a closeThe trade fills at the next bar's open. The script never sees a bar it has not reached.
Stops and limitsFill at the prices the Pine runtime reports inside the bar; a limit the price gaps through fills at the open of that bar.
GapsThe move from one close to the next open is counted while a position is held, for and against you.
Position sizeOne position at a time, long or short, the whole account; the script's initial capital is the account.
Commission0.05% of each fill's value by default, or the commission the script declares, which wins.
Slippage0.025% against you on each fill by default; a script's own slippage setting is applied by the runtime in its fills.
Not modelledPartial fills, spread changes, market impact, borrow fees on shorts, margin interest and taxes.

The default costs come to 0.15% for a round trip, a conservative figure for a liquid US stock and too little for a thin one. How to set your own.

How a result is judged

Every run reports net return against buying and holding the symbol, both after costs, with Sharpe, Sortino, a t-statistic on the mean trade, profit factor, win rate, worst drawdown, the yearly returns and the full list of trades, each marked on the chart.

CheckThe rule
Enough tradesFewer than 20 trades or less than a year of bars: too few trades to judge, whatever the return.
Lost moneyNet return at or below zero, profit factor under 1 or Sharpe at or below zero.
Could be luckMade money, but the mean trade is not far enough from zero (t-statistic about 2 is the bar).
Real edge so farSharpe at least 0.5, t-statistic at least 1.5, worst drawdown under 45%.
StrongSharpe at least 1, t-statistic at least 2, profit factor at least 1.5, drawdown under 35%, and more than buy and hold.

Then the held-out test. The last 33% of the bars is kept apart and judged on its own, with its dates: with fewer than five trades there, too few trades to judge; a Sharpe ratio at or below zero, did not survive; positive and at least half the fitted period's, survived; anything in between, decayed. The optimiser, on the Pro and Max plans, fits a script's inputs on the first part only, judges them on the held-out part, and shows the winner next to the best of the same number of random tries, so a result that random settings would also have found is not called an edge.

Before a script runs, the audit reads it line by line for 38 known failure modes: lookahead through request.security, entries inside an unconfirmed bar, alerts fired mid-bar, costs left at zero, dead version 4 syntax and others. A script can pass every check and still be a poor strategy; the audit rules out mechanics, not ideas.

Testing many ideas raises the odds that one looks good by chance. The held-out verdict and the random-tries comparison are the guards here; the number of ideas you have tried is the one thing the page cannot know.

Checking a result elsewhere

The same script, symbol, timeframe and date range give the same result on a later run; only new bars, or a split that re-adjusts history, change it. The script and every input are visible with the result. The signed-in tester exports the trade list as CSV: side, entry and exit dates and prices, and the return of each trade after costs, so the fills can be recomputed in a spreadsheet, or the same script run in TradingView's Strategy Tester with the same commission and slippage declared.

Expect small differences against TradingView: this tester runs Pine v6 on its own runtime and its own data, and TradingView charges no costs unless the script sets them. The two side by side.

What a result does not prove

A strategy that survived its held-out period held up on one later stretch of one symbol's history after modelled costs. That is not a forecast and not evidence of a live edge: the market changes, the costs you pay may differ, dividends are not in the return, the list of stocks flatters, and the strategy may have been tuned more often than the page can see. These are research tools, not investment advice.

Questions

From Alpaca's market data: the consolidated US tape for history, and IEX for the newest 15 minutes of a live session. Daily bars reach back to 2016, one-minute bars cover the last 120 sessions and five-minute bars the last 600, regular session by default.

Facts on this page come from the tester's own code and data (the bars function, the backtest engine, the Pine audit and the scan feed), read on 24 October 2026; the live scan feed listed a universe of 1,423 names with 1,183 scanned that day. Alpaca and IEX are the data providers named in our data agreements; TradingView and Pine Script belong to TradingView, Inc., and Alpha Charts is not affiliated with it.