GUIDE · TESTING A STRATEGY

Can ChatGPT or Claude write and backtest a Pine Script strategy?

Both can write Pine Script, and neither can run it on TradingView's data. ChatGPT and Claude run Python, so a backtest in the chat is a Python copy of your rules on prices you upload or a connector fetches, not your script in TradingView. Asked on 20 October 2026 for an RSI(2) strategy on SPY, ChatGPT wrote one in seconds, then said it could not verify how it had performed.

What each one can do

From each company's own help pages:

ChatGPTClaude
Writes Pine ScriptYesYes
Runs codePythonPython, in a sandbox
On what dataFiles you upload, or connectorsFiles you upload, or connectors
Runs your script on TradingView's dataNoNo

One of those connectors is TradingView's own MCP server, in public beta: on the Essential plan and up, ChatGPT, Claude and other assistants can read TradingView's market data through it, delayed. It does not run Pine Script yet; TradingView lists that as the next addition.

So a chat can draft the script and explain it, and it can test a translation of the rules on prices it is given or fetches. What it cannot tell you is what your Pine script did on the chart: that takes TradingView's Strategy Tester or a tester that runs Pine itself.

Worked example: a ChatGPT-written strategy, checked

On 20 October 2026 we asked ChatGPT, logged out, for a Pine v6 strategy with the rules from the how-to: SPY daily, long when the 2-day RSI is under 10 and the close is above its 200-day average, out on a close above the 5-day average, and how it performed from 2016 to 2026. It wrote a 56-line strategy with costs and a date window. On performance it was candid: it could not verify a run of this exact script, and pointed to two published RSI(2) backtests with other dates and rules.

The declaration ChatGPT wrote
strategy(
     "SPY RSI(2) Pullback — Long Only",
     overlay=true,
     initial_capital=100000,
     default_qty_type=strategy.percent_of_equity,
     default_qty_value=100,
     commission_type=strategy.commission.percent,
     commission_value=0.01,
     slippage=1,
     pyramiding=0,
     process_orders_on_close=true
)

Our audit passed most of the script and flagged two of these lines:

FlaggedWhy it matters
process_orders_on_close = trueOrders fill at the close of the candle that triggered them, a price no one could still trade once the candle had closed.
100% of equity, default marginPine's margin of 100 lets a long spend only the strategy's own cash, so an entry that costs a little more at the fill is skipped.

Our tester fills every order at the next open and charges 0.05% commission and 0.025% slippage each side. Run that way, from 4 January 2016 to 19 October 2026:

ScriptTradesNet after costs
As ChatGPT wrote it34+15.3%
With margin_long = 0 added90+24.8%

Same rules, same data: as written, the script skipped 56 of the 90 entries, and one added line brings it to the same 90 trades as our own build. Nothing in the chat could have shown that, because the chat never ran the script.

What to check for in AI-written Pine

These are among the checks our audit runs on every script. Each is a mistake that can survive the compiler:

MistakeWhat it does
Old syntaxVersion 4 or 5 calls in a version 6 script, or functions TradingView has removed. The editor rejects some; others change meaning.
Reading the futureHigher-timeframe data requested so that a candle sees a value it could not have known when it closed.
Acting before the closeEntries and exits on a candle that is still forming, which look different once it closes.
Filling at the same closeprocess_orders_on_close = true fills at a price you could no longer trade by the time you saw the close.
Costs left at zeroNo commission_value and no slippage, so every result is too kind.
100% of equity at the default marginPine's margin of 100 lets a long spend only its own cash, so an entry that costs a little more at the fill is skipped.
Exits that never fireA strategy.exit with no stop, limit or trail, which never closes anything by itself.
A stop on the wrong sideA long's stop above the entry, or a short's below, which closes the trade at once.

How to check a script a chat wrote

  1. Compile it in TradingView
    Paste it into the Pine Editor. TradingView is the compiler of record: the script either adds to the chart or it does not.
  2. Read it with an audit
    Check it for the traps above before you look at any result: future data, fills at the triggering candle's close, zero costs, the default margin.
  3. Fix the declaration
    Set commission and slippage, and margin_long = 0 or an order size under 100%.
  4. Backtest years, then hold out the last stretch
    Run it with costs over years of history, choose settings on the earlier part only, and judge it on the later part unchanged.
  5. Compare it with holding the stock
    Then run it on other symbols. A rule that only worked on the one chart it was written for has not shown much.

Our free Pine Script audit reads a pasted script line by line, and the free tester runs it with costs and a held-out verdict. Inside Alpha Charts, the Pine Copilot writes the script, runs the same audit before you see it, and draws it on our data beside the chat. It does not place trades.

Questions

Yes. It writes Pine v6 from a plain description of the rules. It cannot run the script on TradingView's data, so whether the script compiles and trades the way you meant is yours to check, in TradingView's Pine Editor or a tester.

Sources, read on 20 October 2026: OpenAI's help page “Data analysis with ChatGPT”, Claude's help page “Create and edit files with Claude”, TradingView's help pages “MCP Server: connect your AI assistant to TradingView” and “MCP Server FAQ”, and the Pine Script v6 reference for strategy() (default order size and margin). ChatGPT's answer is one logged-out conversation on 20 October 2026; answers vary between runs. The numbers are our engine's, on our daily data. ChatGPT, Claude and TradingView belong to their owners, and Alpha Charts is not affiliated with them.