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:
| ChatGPT | Claude | |
|---|---|---|
| Writes Pine Script | Yes | Yes |
| Runs code | Python | Python, in a sandbox |
| On what data | Files you upload, or connectors | Files you upload, or connectors |
| Runs your script on TradingView's data | No | No |
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.
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:
| Flagged | Why it matters |
|---|---|
| process_orders_on_close = true | Orders 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 margin | Pine'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:
| Script | Trades | Net after costs |
|---|---|---|
| As ChatGPT wrote it | 34 | +15.3% |
| With margin_long = 0 added | 90 | +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:
| Mistake | What it does |
|---|---|
| Old syntax | Version 4 or 5 calls in a version 6 script, or functions TradingView has removed. The editor rejects some; others change meaning. |
| Reading the future | Higher-timeframe data requested so that a candle sees a value it could not have known when it closed. |
| Acting before the close | Entries and exits on a candle that is still forming, which look different once it closes. |
| Filling at the same close | process_orders_on_close = true fills at a price you could no longer trade by the time you saw the close. |
| Costs left at zero | No commission_value and no slippage, so every result is too kind. |
| 100% of equity at the default margin | Pine'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 fire | A strategy.exit with no stop, limit or trail, which never closes anything by itself. |
| A stop on the wrong side | A 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
- Compile it in TradingViewPaste it into the Pine Editor. TradingView is the compiler of record: the script either adds to the chart or it does not.
- Read it with an auditCheck 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.
- Fix the declarationSet commission and slippage, and margin_long = 0 or an order size under 100%.
- Backtest years, then hold out the last stretchRun it with costs over years of history, choose settings on the earlier part only, and judge it on the later part unchanged.
- Compare it with holding the stockThen 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.
Yes, the same way. Claude can also run Python in a sandbox, so it can test a Python copy of your rules on prices you upload or pull in through a connector, such as TradingView's own MCP server, but it does not run your Pine script on TradingView's data.
Only as a Python copy of your rules. ChatGPT runs Python on prices you upload, or that it pulls through a connector such as TradingView's MCP server, which is in beta with delayed data on the Essential plan and up. Either way it tests its own translation, with whatever costs and fills it chose, not your Pine script in TradingView.
Compile it in TradingView's Pine Editor, read it with an audit for the backtest traps (future data, fills at the triggering candle's close, zero costs, 100% of equity at the default margin), then backtest years of history with costs and judge it on a later period you did not tune on.
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.