ChatGPT and Claude write Pine Script in seconds, but the code can mix in older versions, repaint on live bars or peek at data it couldn’t have had. Here is a prompt that asks for v6, a short strategy checked against TradingView’s v6 manual, the mistakes to look for, how to test the result in TradingView and what to do when it won’t compile.
November 16, 2026
18
min to read
The short answer
Yes, if you ask for version 6 by name: //@version=6 on line 1, strategy() for a backtest, every ta.* call on its own line, and request.security() with [1] and lookahead on. Then compile it in TradingView’s Pine Editor, set costs, check a few trades by hand in the Strategy Tester and reload the chart to catch repainting.
Yes, and quickly. Pine Script is the language TradingView uses for custom indicators and strategies, the scripts that simulate trades on a chart. Both assistants write and explain code, and both can read a web page when search is on: ChatGPT shows search results and citations in the chat, and Claude can fetch the full content of a page you give it the address of. That last part is useful here, because you can point either one at TradingView’s own manual. How the two compare on other trading jobs is in Claude vs ChatGPT for trading.
The catch is the version. Pine has had six versions, and TradingView’s release notes file version 6 under November 2024, with the line “Starting today, future Pine updates will apply exclusively to this version.” Older code doesn’t disappear from forums and tutorials, so an assistant can blend v4, v5 and v6 in one script. Its training also stops at a date. OpenAI’s model page lists knowledge cutoffs from April 30 to June 1, 2026 for its current flagship models, and Anthropic’s models overview gives June 2026 for its current Claude models. TradingView kept changing things after that: in July 2026 it reworked the strategy report, the panel it used to call the Strategy Tester, and replaced the Bar Magnifier checkbox with a Bar detalization menu, and in August 2026 it added a new once keyword. An assistant can describe buttons that have moved, or miss a feature that is new.
TradingView also has its own assistant. AI Copilot, a paid add-on since September 28, 2026, lives in the side panel of the chart, “sees what’s on your chart,” and writes indicators and strategies that it applies to the chart right away. Since November 9, 2026 you can pick its model: DeepSeek V4.1 Flash by default, GPT-6 Luna or Claude Sonnet 5.5. It isn’t in TradingView’s mobile apps yet. This guide is for the case where you use ChatGPT or Claude directly, and the checks below apply to any Pine code, whoever wrote it.
Vague requests get vague code. “Write me a TradingView RSI strategy” leaves the model to choose the version, the script type, the timeframe logic and the costs, and those are exactly the choices that break. The prompt below makes each one for it. It is plain instructions, so it pastes into ChatGPT or Claude as written; we wrote it for this guide and haven’t benchmarked it.
Write a TradingView Pine Script v6 strategy for this rule: [the market and timeframe, the entry, the exit, the stop and the position size]. Requirements: 1. Line 1 is //@version=6. Declare the script with strategy(), not indicator(), so it appears in the Strategy Tester. 2. Use v6 syntax only: ta.* for indicators, input.int() and input.float() for settings, request.security() for other timeframes, if blocks around strategy.entry() (no when = argument), color.new() instead of transp, and true/false conditions instead of numbers. 3. Call every ta.* function on its own line in the global scope, never inside an if block or an and/or condition. 4. No repainting: don’t set calc_on_every_tick and act only on closed bars. For a higher timeframe, request the value with [1] and lookahead = barmerge.lookahead_on, and never use lookahead_on without the [1]. 5. Set initial_capital, default_qty_type, default_qty_value, commission and slippage in strategy(). 6. Comment each block in plain English. After the code, list every built-in function you used with its v6 signature and say which lines place orders. If you aren’t sure something exists in v6, say so instead of guessing. If you can read web pages, check TradingView’s v6 migration guide first: https://www.tradingview.com/pine-script-docs/migration-guides/to-pine-version-6/
Each line closes a door the model would otherwise leave open. The version line stops it from falling back to old syntax, and naming strategy() matters because only a strategy gets the order commands and a strategy report. Point 3 guards against a v6 change covered below, and point 4 against the two faults that make a backtest look better than trading. Point 5 is there because TradingView’s backtests apply no commission and no slippage unless you set them. The list at the end gives you something to check against the reference instead of trusting the code on sight. For prompts beyond code, such as turning an idea into an exact rule first, see our trading prompts.
Here is the kind of script that prompt should return, for a simple rule: buy when the RSI, the relative strength index, a 0 to 100 gauge of momentum, crosses under 30 while yesterday’s daily close sits above its 50-day average; set a stop 5% under the fill; exit when the RSI crosses back over 55. We checked every line against the v6 examples in TradingView’s User Manual on November 15, 2026. Compile it yourself before you rely on it: paste it into the Pine Editor, save, and add it to a chart.
//@version=6
strategy(
"RSI dip with a daily trend filter", overlay = true, initial_capital = 10000,
default_qty_type = strategy.percent_of_equity, default_qty_value = 10,
commission_type = strategy.commission.percent, commission_value = 0.1, slippage = 2
)
// Settings you can change in the script's Inputs tab.
int rsiLength = input.int(14, "RSI length", minval = 2)
float buyLevel = input.float(30.0, "Buy when RSI crosses under")
float exitLevel = input.float(55.0, "Exit when RSI crosses over")
float stopPercent = input.float(5.0, "Stop loss %", minval = 0.1) / 100.0
// History-based calls run on every bar, outside any condition.
float rsi = ta.rsi(close, rsiLength)
bool rsiDip = ta.crossunder(rsi, buyLevel)
bool rsiExit = ta.crossover(rsi, exitLevel)
// Yesterday's confirmed daily close and 50-day average: no repainting, no lookahead.
float dailyClose = request.security(syminfo.tickerid, "1D", close[1], lookahead = barmerge.lookahead_on)
float dailyAverage = request.security(syminfo.tickerid, "1D", ta.sma(close, 50)[1], lookahead = barmerge.lookahead_on)
bool upTrend = dailyClose > dailyAverage
bool entrySignal = rsiDip and upTrend and strategy.opentrades == 0
// Enter on a dip in an uptrend, set the stop on the bar where the entry fills, exit on the rebound.
if entrySignal
strategy.entry("Long", strategy.long)
if entrySignal[1]
strategy.exit("Stop", "Long", stop = strategy.position_avg_price * (1.0 - stopPercent))
if rsiExit
strategy.close("Long")
plot(dailyAverage, "Daily 50-day average", color.orange)
What each part does, and where the manual backs it:
[1] and lookahead = barmerge.lookahead_on, the pattern TradingView’s manual on other timeframes calls “the only recommended method to avoid repainting.” Use it on charts of one day or shorter.strategy.position_avg_price holds the fill price. This is the same pattern as an example in TradingView’s Strategies page.The rule itself is only an example of the mechanics. It is not a strategy we recommend, and how it performs depends on the market and the dates you test.
The problems to look for fall into two groups: syntax from an older version, and logic that works on past bars but not on live ones. The first kind usually stops the script from compiling, which is the lucky case. The second kind compiles, runs and lies.
| Mistake | What you see | The v6 fix |
|---|---|---|
No //@version line | Errors all over modern code, because the compiler reads it as version 1 | Put //@version=6 on line 1 |
| Version 4 names: study(), security(), rsi() without ta., input(type = input.integer), transp = | Errors on each old name | indicator(), request.security(), ta.rsi(), input.int(), and color.new() for transparency |
| Version 5 habits that v6 rejects: when = inside strategy.entry(), a number used as a condition such as if bar_index, na() on a true/false value | Compile errors, such as CE10101, which says a condition must evaluate to a “bool” value | if blocks around orders, bool(x) or x != 0, and plain true/false values |
timeframe.period == "D" | No error, but the test is never true: v6 writes the daily timeframe as "1D" | Compare with "1D", "1W" and "1M" |
| An indicator() when you wanted a backtest | Nothing in the strategy report; only strategy() scripts get the strategy.* commands | Declare strategy(); keep alertcondition() for indicators, where it works |
A ta.* call inside a condition, such as if close > open and ta.rsi(close, 14) > 50 | Warning CW10003, and RSI values that drift, because v6 stops evaluating an and as soon as one side is false | Compute the RSI on its own line first, then use the variable |
calc_on_every_tick = true, or signals read from the bar still forming | Live signals that move or vanish after a reload | Leave it off and act on closed bars |
| request.security() with lookahead on and no [1] | A higher-timeframe line that knows the day’s high before it happens, and a backtest that looks too good | Use the expression with [1] and lookahead on; lookahead off avoids the leak but can repaint on live bars |
The first rows come from TradingView’s version 5 and version 6 migration guides. Version 5 renamed study() to indicator() and moved most functions into namespaces, such as ta.sma() and request.security(); version 6 removed the transp and when parameters, stopped treating numbers as true or false, and made and and or lazy, meaning the second half of a condition is skipped when the first half already decides the answer. That last change is why a history-based call such as ta.rsi() must run on every bar, outside the condition: as the CW10003 page explains, a call that skips bars builds an inconsistent history.
TradingView defines repainting as “script behavior causing historical vs realtime calculations or plots to behave differently,” and estimates that more than 95% of indicators repaint in some form. Much of that is harmless: an RSI on the bar still forming moves with the price until the bar closes. It becomes a problem when signals or orders depend on it, because a backtest only ever sees finished bars. Three patterns cause most of the damage.
On a live bar, the high, low and close keep changing until the bar closes. A cross that shows at mid-bar can be gone at the close. The manual’s fixes all trade speed for honesty: add barstate.isconfirmed to the condition, use the previous bar’s values, or compare with the open, which doesn’t change. A strategy has a version of this too: TradingView warns that strategies using calc_on_every_tick = true “will most probably not generate the same order executions” on live and past bars, which “also invalidates backtesting results.”
This is the one to check in every AI-written script that uses another timeframe. The default, lookahead = barmerge.lookahead_off, doesn’t leak on past bars, though it can still repaint on live ones. Turning lookahead on without offsetting the expression by one bar makes the function return values from the future on historical bars. TradingView’s own example is labeled “FUTURE LEAK! DO NOT USE!”: a daily high requested with lookahead on, which shows the day’s high before the day has made it. The fix is the pair in the example above, close[1] with lookahead_on; the manual notes the two “are interdependent. Neither can be removed without compromising the integrity of the function.” Scripts that leak the future this way are not allowed as public publications on TradingView.
Pivot scripts often detect a high five bars after it happens, then draw the label back on the pivot bar. On a past chart it looks as if the signal came on time; live, it arrives five bars late. Ask the assistant to plot signals on the bar where they are detected.
Review this Pine Script v6 code for repainting and lookahead bias: [paste the script]. Check every request.security() call (does it use [1] with lookahead_on, or lookahead off?), calc_on_every_tick, signals read on the bar still forming, labels or plots drawn into the past, varip, timenow, and ta.* calls inside conditions or if blocks. For each problem, quote the line, explain what it does on past bars and on live bars, and give the fixed line.
Then test it the way the manual describes: let the script run on live bars for a while, reload the chart, and see whether any past signal moved. When a script restarts, bars that were live become historical, and a repainting script redraws them.
A strategy that compiles has passed the easy test. These checks tell you whether its results mean anything. TradingView now calls the Strategy Tester the strategy report; it opens in a tab below the chart as soon as a strategy is on it.
Add the strategy to regular candles. TradingView warns that strategies on Heikin Ashi, Renko and other non-standard charts trade synthetic prices and typically produce unrealistic results.
In the strategy’s Settings, on the Properties tab, check the initial capital, the order size, the commission and the slippage. Commission and slippage are zero unless the script or you set them. Since July 2026 the old margin inputs are called Long leverage and Short leverage.
The Metrics tab shows net profit, drawdown and trade counts, and its Return details section compares the strategy with buying and holding. The Trades tab lists every simulated trade with its entry and exit prices.
Pick three trades from the list, find each signal bar on the chart and confirm the signal was really there. On past bars, TradingView’s broker emulator fills a market order at the open of the bar after the signal.
On Premium and Ultimate plans, the High setting in the Bar detalization menu uses lower-timeframe data to place fills inside each bar, which matters for stops and limits. Choosing a different testing period switches on Deep Backtesting.
Let it run on live bars, then reload the chart. If past signals moved, the script repaints.
If an assistant tells you to tick “Bar Magnifier” or to set “Margin for long positions,” it is describing the old interface; the July 2026 release notes list both changes. A clean report is still a report on the past. Few trades, a single favorable stretch of dates or a setting tuned on the same data can make any strategy look good, which is why the next step is a test on data the rule has never seen. Our guide to backtesting a trading strategy covers that step and the other traps. Our quantitative trading guide walks through a rule that looked fine on its fitting data and failed on the months it never saw.
TradingView’s errors overview sorts problems into three kinds. Compilation errors stop the script before it runs, and the Pine Editor marks the code in red with a message. Warnings, in orange, let it compile but point to code that may misbehave. Runtime errors happen while it runs on the chart and show as a red exclamation point in the script’s status line; click it to see the message and the bar where it happened. Work through them in this order:
Note the line number and the exact wording. Fix that one first and save again, because one mistake can trigger several messages.
It should read //@version=6, normally on line 1. If it says 5 or 4, the rest of the code may be fine for that version and wrong for v6, or the reverse.
For a v5 script, open the Manage script menu in the Pine Editor and choose “Convert code to v6.” It works only if the v5 code compiles. A v4 script goes to v5 first: TradingView converts one version at a time.
In the Pine Editor, Ctrl-click or Cmd-click a built-in to open its entry in the v6 Reference Manual, and check its parameters against what the assistant wrote.
Paste the message, the line and the full script into the assistant with the prompt below, and ask for the smallest fix.
Add log.info() calls and open Pine Logs from the Pine Editor’s More menu to see what the script computes on each bar.
This Pine Script v6 script doesn’t compile. The Pine Editor shows this error: [paste the exact message and the line number]. Here is the full script: [paste it]. Explain the cause in one sentence, fix only what the error requires, keep //@version=6 on line 1 and return the full corrected script. Don’t rename variables or change the strategy’s rules. If the error comes from v4 or v5 syntax, name the old form and its v6 replacement.
Two messages come up again and again in code written for older versions. CE10101 means a condition is a number, not true or false; wrap it in bool() or write the comparison out, such as x != 0. CW10003, a warning rather than an error, means a history-based function sits inside a condition or loop; move the call to its own line in the global scope.
Yes, if what you want is the test rather than the code. Ethy, an AI trading agent, backtests a rule you describe in plain words, so the steps above, from the version line to the lookahead check, never come up:
To be clear about what Ethy doesn’t do: it doesn’t read Pine Script, import TradingView strategies or act on TradingView alerts. Its charts are drawn with TradingView’s charting library, fed with Ethy’s own market data, and that is the only link. Pine remains the more flexible tool, with custom indicators, several symbols in one script, drawings, and TradingView’s community library of more than 150,000 scripts; Ethy’s builder, for example, can’t compare two markets in one condition. Ethy presents backtests as estimates on past data, not a promise. If you want Claude to work with TradingView itself, see how to connect Claude to TradingView with MCP.
We haven’t benchmarked them on Pine, and a precise prompt and a careful check matter more than the choice. Give either one the v6 prompt in this guide and test the result the same way. TradingView’s own AI Copilot, a paid add-on, writes Pine inside the chart; since November 9, 2026 you can run it on Claude Sonnet 5.5, GPT-6 Luna or DeepSeek V4.1 Flash.
Start with TradingView’s converter: in the Pine Editor, open Manage script and choose “Convert code to v6.” It needs a v5 script that compiles, and a v4 script goes to v5 first. Then ask the assistant to fix what is left, one exact error at a time, and compile after each change.
Check five things: commission and slippage left at zero, lookahead in request.security() without [1], calc_on_every_tick turned on, a Heikin Ashi or Renko chart, and too few trades. Any one of them can flatter a backtest. Fix them, run it again and check a few trades by hand against the chart.
Not by itself. A strategy simulates its orders with TradingView’s broker emulator and shows the results in the strategy report. It is a test of a rule, not an order to a broker, and a good test is still a result on past data.
No. Ethy doesn’t import Pine Script or act on TradingView alerts. Describe the rule in plain words instead and Ethy backtests it on Hyperliquid markets or spot tokens, marks every entry and exit, and can run a tested strategy in paper mode on live prices.
It tells TradingView’s compiler which version of Pine Script the code is written in. TradingView’s manual says it is most useful at the top of the script and strongly recommends the latest version. If the line is missing, the compiler assumes version 1, so modern code fails to compile.
Trading involves risk, including the loss of your money. Ethy AI is a research and trading tool and does not give investment advice or recommendations. Backtests are simulations on historical data and do not predict future results.
Deploy your AI trading agent in one click.
