Read time … min

Backtest Pine Script strategies on TradingView

Write a Pine Script strategy with Claude or ChatGPT, drop it onto a TradingView chart, and run the built-in Strategy Tester before any real capital touches the strategy. The Strategy Tester is the cheapest, fastest filter you have.

This guide covers the AI-first workflow for writing the strategy, running the backtest, reading the Performance Summary and List of Trades tabs honestly, and promoting the validated strategy to live execution via a TradingView webhook to a TradingHost-hosted broker receiver.

Section 01 · How it fits together

Write, test, ship

Three pieces. You write a strategy. TradingView backtests it. A webhook ships the validated strategy to live execution. The Strategy Tester sits between authoring and execution as a cheap filter; the only thing more expensive than a bad backtest is no backtest at all.

  • What you write

    Pine Script strategy

    A strategy() script that declares entries, exits and sizing. The Strategy Tester only runs strategy() scripts; indicator() scripts cannot be backtested.

  • Where you validate

    Strategy Tester

    TradingView’s built-in panel that runs the strategy across the chart’s available history and surfaces Performance Summary, List of Trades and Properties tabs.

  • How it ships

    Webhook to live

    Once the backtest stands up, the same strategy fires alerts to a webhook URL hosted on TradingHost, which calls the broker API and executes real orders.

From idea to a tested strategy

  1. Describe the strategy in plain English to Claude or ChatGPT; ask for a Pine Script v6 strategy script.
  2. Paste the script into TradingView’s Pine Editor, add it to the chart, and open the Strategy Tester panel.
  3. Read the Performance Summary tab; check the List of Trades tab for shape and frequency of fills; confirm the Properties tab’s commission and slippage assumptions match reality.
  4. Iterate on the script with the AI until the strategy survives an honest backtest on out-of-sample data.
  5. Create a TradingView alert against the strategy with a webhook URL pointing at a TradingHost runtime; promote the validated script to live.

Section 02 · At a glance

At a glance

Workflow
Write a Pine Script strategy with AI, validate in TradingView’s Strategy Tester, then promote to live via a webhook
Language
Pine Script v6 (current TradingView language version)
Script declaration
Must be strategy(), not indicator(); only strategy scripts run in the Strategy Tester
Strategy Tester
Built into every TradingView account; opens as a panel under the chart
Headline tabs
Performance Summary, List of Trades, Properties
Performance metrics
Net profit, gross profit, gross loss, profit factor, max drawdown, percent profitable, average trade
Bar limits
Backtest range is bounded by the chart’s loaded bars; Deep Backtesting on paid plans extends beyond the visible range
AI tools
Claude, ChatGPT, Gemini (any model trained on Pine Script v6 reference)
Editing surface
TradingView Pine Editor; deeper edits in Cursor with Pine v6 in the prompt
Live trading path
TradingView alert with webhook URL pointing at a TradingHost runtime that calls the broker API
TradingHost role
Webhook receiver runtime once the strategy goes live (not used during backtesting itself)
Affiliation
TradingHost is independent and is not affiliated with TradingView

Section 03 · Write the strategy with AI

Describe the strategy, get Pine Script back

Open Claude or ChatGPT and describe what you want the strategy to do in plain English. Be explicit about three things: the timeframe and instrument, the entry and exit rules, and the position sizing. Ask for a Pine Script v6 strategy script (not an indicator) so the result will run in the Strategy Tester and expose the strategy.* placeholders later when you wire alerts.

Read every line. Pine Script’s strategy() function takes parameters that quietly change backtest behaviour (initial_capital, default_qty_type, commission_type, process_orders_on_close) and the AI does not always pick the value you would. Ask the model to explain each parameter it sets and adjust them to match how you would actually trade.

Three Pine Script subtleties worth catching. First, repainting: by default Pine plots intra-bar values that recalculate on every tick, so a strategy that "passed" a live test may have relied on values that did not actually exist at bar close. Repainting indicators show one signal in the backtest and a different signal when the bar closes live; on intraday timeframes the divergence is enough to flip a winning backtest into a losing live strategy. Use barstate.isconfirmed guards in the strategy logic, set the alert to fire "Once per bar close" when you wire the strategy live, and prefer indicators that explicitly do not repaint. Second, lookahead bias is easy to introduce accidentally if a script references future values; ask the model to confirm no historical reference uses future-leaking data. Third, order fill assumptions: by default Pine fills market orders at the next bar’s open, not the signal bar’s close. If your backtest enters at the same bar the signal fires, set process_orders_on_close = true, and accept that this is a tighter assumption than live execution will deliver.

If you prefer an IDE over the TradingView Pine Editor, write the same script in Cursor with Claude or GPT and paste the result into TradingView when ready. The Cursor workflow page covers the IDE side.

Section 04 · Run the Strategy Tester

Add the strategy to a chart and open the Strategy Tester

Open a TradingView chart on the instrument and timeframe your strategy targets. Paste the strategy into the Pine Editor at the bottom of the chart and click Add to chart. If the script declares strategy(), TradingView automatically opens the Strategy Tester panel below the Pine Editor.

The Strategy Tester runs the strategy against the bars currently loaded on the chart. Scroll left to load more history before re-running if you want a longer backtest window. On paid TradingView plans, the Deep Backtesting option extends the tester beyond the chart’s visible bar range; the free tier limits you to what is loaded in the chart.

Adjust the strategy settings (gear icon next to the script name) before reading the results. Initial capital, order size, pyramiding, commission and slippage are the ones that materially change the report; default values are rarely what you want. Match commission and slippage to what the broker you intend to execute on actually charges.

Section 05 · Read the report

The three tabs that matter

The Strategy Tester surfaces a Performance Summary, a List of Trades, and a Properties tab. Read all three. The Performance Summary tells you whether the strategy made money in simulation. The List of Trades tells you whether the strategy fired the trades you actually wanted. The Properties tab tells you whether the assumptions behind those trades are realistic.

A strategy that posts a beautiful net profit on the Performance Summary but only fires four trades a year, against unrealistic commission and slippage, is not a strategy. It is a chart artefact. The three tabs together are the safeguard.

The metrics worth reading

Net profit
Total profit and loss across all simulated trades, in account currency and as a percent of initial capital.
Profit factor
Gross profit divided by gross loss. Above 1 means the strategy made money in simulation; honest live strategies usually sit between 1.2 and 2.
Max drawdown
Largest peak-to-trough equity loss during the test. The single most important risk number.
Percent profitable
Fraction of trades that closed at a profit. High win rates often hide tail risk; pair this with average win vs average loss.
Avg trade P&L
Mean P&L per trade. If this is smaller than your real-world commission plus slippage estimate, the strategy is unprofitable in practice.
Sharpe / Sortino
Risk-adjusted return measures. Surfaced under the Performance Summary tab when enabled.
List of Trades
Every simulated trade with entry, exit, size, P&L and run-up/draw-down. Read this to confirm the strategy fires the way you expect.
Properties
The settings used for the run: initial capital, order size, commission, slippage, pyramiding. Confirms what you tested before you act on the result.

One Pine-specific risk to flag: the Strategy Tester is generous on intra-bar assumptions by default. If your strategy enters and exits within the same bar in the backtest, the live alert needs to use once-per-bar-close frequency or the same intra-bar flips will not reproduce. Match alert frequency to backtest assumptions before going live.

Section 06 · Promote to live trading

When the backtest stands up, ship the strategy

A clean backtest is a permission slip, not a profit guarantee. When the strategy survives a fair test on out-of-sample data with realistic commission and slippage, the next step is a TradingView alert with a webhook URL.

The Pine Script you tested is already the script you ship; you do not rewrite it for live trading. You create an alert against the strategy, paste the webhook URL of a TradingHost runtime into the alert, and write the alert message as JSON using the strategy.* placeholders to encode side and size. The TradingHost container parses the payload and calls the broker REST API.

No MetaTrader. No Windows VPS. No PineConnector license. The same Pine Script that ran your backtest fires your live orders.

Section 08 · FAQ

Frequently asked questions

The Strategy Tester itself is available on every TradingView account. Deep Backtesting and longer historical bar ranges unlock at Plus and above. Webhook URL delivery, the method you will eventually need to fire live alerts at a broker, requires Plus, Premium or Ultimate; Essential and the free tier do not include webhook alerts.

Only Pine Script scripts that declare strategy() participate in the Strategy Tester and expose the strategy.* placeholders you will need later for live alerts. indicator() scripts cannot be backtested.

Pine Script v6. TradingView has stated that future language updates are applied exclusively to v6, so writing anything new in v5 is a slow-motion migration.

Scroll back to load more history before re-running the tester, or use Deep Backtesting if your TradingView plan supports it. Deep Backtesting runs the tester against data beyond the chart’s visible bar range.

It depends on the timeframe. Daily and swing strategies (4-hour bars and above) tend to land between roughly 1.3 and 2.5 in honest backtests with realistic commission and slippage. Intraday strategies (sub-hour) tend to land between 1.5 and 3 because they take more trades. Anything above 3 on intraday data is worth treating with suspicion until you can reproduce it on out-of-sample bars; numbers above 4 almost always indicate look-ahead, repainting or unrealistic fills.

Yes, in the strategy properties. Set commission_type and slippage to match what the broker you intend to execute on actually charges. Default values understate real-world costs and inflate the backtest.

Yes. Backtrader and VectorBT are Python-based backtesters that handle more sophisticated portfolio, position-sizing and statistical analyses than Pine. The trade-off is leaving TradingView’s chart context.

Read every reference to past or future bars. Pine’s history-referencing operator [n] looks back, but accidentally using a value that only exists at bar close (or a repaint-prone calculation) inflates the backtest. Pair the backtest with a paper-trade period before going live.

Create a TradingView alert on the strategy, point the webhook URL at a TradingHost runtime, and write the message as JSON with the strategy.* placeholders for side and size. See the webhook workflow page for the live execution loop.

Trust the workflow, not the output. AI accelerates authoring; the backtest is your safeguard; the live alert is your shipping mechanism. Read every line, run an honest backtest, and paper-trade before sizing up.