Explainers / Did ChatGPT or Claude write your Pine Sc
Did ChatGPT or Claude write your Pine Script? Nine checks before you trust the backtest
Can ChatGPT or Claude write Pine Script? Yes. Ask for a strategy and you get code that, after a round or two of pasting errors back, compiles and draws something on the chart. That part is solved. The part that is not solved is that a script which compiles can still test things that could never have happened live. The editor will not warn you, and the chatbot usually will not either, because you asked it to make the script work, and it does.
This page is the list of things to check after the script compiles. Each check says what goes wrong, why a chatbot tends to produce it, and how to see it on your own chart. None of it needs a paid tool.
Why AI-written scripts fail quietly
A language model writes the most likely code for your request. The most likely code for "an RSI strategy on the 4-hour with a daily trend filter" is code that looks like thousands of published scripts, including their mistakes. It is also trained on several versions of Pine at once, so it mixes them. And it optimises for the thing you can see: no red error line. Whether the backtest is honest is not visible in the editor, so it is not what gets fixed.
1. A higher timeframe read with lookahead
Look for request.security() with lookahead = barmerge.lookahead_on. If the value requested is close (or any value of the bar still forming) and it is not offset with [1], then on historical bars the script sees the higher timeframe's final value at the start of that period. A daily filter on an hourly chart knows the day's close at 9:30 in the morning. Live, it cannot.
How to see it: compare the higher-timeframe line on history with the same line on bars that formed while you watched. The safe pattern is request.security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on). The repainting page shows the mechanics.
2. Signals on a bar that has not closed
A condition built on close, high or low of the current bar is true and false many times while the bar forms. On history every bar is closed, so the signal looks clean. Live, a marker can appear and vanish, and an alert can fire for a signal the chart later does not show.
How to check: does the entry or alert require barstate.isconfirmed, or is it built on values from [1]? If neither, watch it live on a short timeframe for a few bars.
3. A backtest with no costs
strategy() defaults to zero commission and zero slippage. A chatbot rarely adds them unless asked. A strategy that trades often can look very different once each round trip pays a spread and a fee.
How to check: read the strategy() line. Add commission_type, commission_value and slippage that match your broker and market, and run it again. If the result changes a lot, the costs were the story.
4. Fills that assume the impossible
By default a strategy's market orders fill at the next bar's open. Code that sets process_orders_on_close = true fills at the close of the very bar whose close produced the signal. Live, by the time that close is known the price is gone, unless you can actually trade the close. Limit and stop prices computed from the current bar's high or low have the same problem.
How to check: in the List of Trades, compare a few entry prices with the bar where the signal printed. If the fill is on the signal bar at a price only known at its close, ask whether you could have been filled there.
5. Pivots drawn in the past
ta.pivothigh() and ta.pivotlow() only confirm a pivot after the number of bars you give on the right. Scripts often draw the pivot with a negative offset so it lines up with the turning bar. On history that looks like the script called the top. Live, the mark appears several bars later.
How to check: count the right-bar setting, then watch where new pivot marks appear on live bars. A strategy that trades a pivot cannot enter before the confirmation bar.
6. Functions called only sometimes
Calling ta.ema(), ta.rsi() or similar inside an if block means the function only sees the bars where the condition was true, so its value is not the indicator you think. The compiler prints a warning for this, not an error, and a chatbot asked to clear errors leaves warnings in place.
How to check: open the Pine Editor's warnings. Move every ta.* call to the top level, assign it to a variable, and use the variable inside the condition.
7. Mixed versions and invented parameters
Models mix v4, v5 and v6: study() next to indicator(), security() next to request.security(), old input() forms. Most of that fails to compile and gets fixed. What survives is quieter: arguments in the wrong order that happen to be the same type. ta.supertrend(factor, atrPeriod) called as ta.supertrend(10, 3) compiles and gives a factor of 10.
How to check: for every built-in function, read its entry in the Pine reference manual and confirm the argument order and defaults. It takes five minutes and catches the errors no message will.
8. Position size and pyramiding left on defaults
The default order size is one contract or share, and pyramiding is off. A chatbot that writes "risk 1% per trade" in a comment has often not written code that does it. The backtest then reports a result for a sizing you never meant to use.
How to check: read default_qty_type, default_qty_value and pyramiding in the strategy() line, and the qty argument of each strategy.entry(). Compare with what the comments claim.
9. A chart type that changes the prices
A strategy run on Heikin Ashi, Renko or other synthetic bars fills at synthetic prices unless told otherwise. The code can be perfect and the backtest still describe a market that did not trade.
How to check: run it on standard candles. If you need Heikin Ashi signals, compute them in the script with ticker.heikinashi() through request.security() and keep the chart on standard candles.
A prompt that helps, and where it stops
Paste your script back to the chatbot with a narrower question than "does it work". For example: "List every place this script could use information that was not available at the time of the bar: request.security lookahead, values of the current unclosed bar, pivot offsets, and same-bar fills. Quote each line and explain." A model is far better at reviewing for a named list of problems than at noticing them unprompted.
Where it stops: the same model that wrote the script tends to defend it, and it cannot run the script on a chart. Some of these checks need the chart: watching live bars, reading the List of Trades, changing the chart type.
The free repaint checker flags several of these patterns in a pasted source, in your browser. If you want one script read line by line against this list, with line numbers and how to see each issue on a chart, that is what the audit below is. It is also written by an AI model, working through a fixed checklist rather than an open chat, and it says plainly what it could not check.
Where it fails
- This is a list of common problems, not every problem. A script can pass all nine checks and still be wrong in a way specific to its logic.
- Passing the checks says nothing about results. An honest backtest of a weak idea is still a weak idea. These checks only make the test describe what could have happened.
- Costs are yours to set. The right commission and slippage depend on your broker, market and order size; a guess can be as misleading as zero.
- Pine changes. Function names, defaults and warnings above are from versions 5 and 6 as published by TradingView. Check the reference manual for the version line in your script.
- Chatbots change. Newer models make fewer of these mistakes, and any of them can still make one. Check the script you have, not the reputation of the tool that wrote it.
- Watching live bars takes time. Checks 2 and 5 need you to watch bars form, which on a daily chart means days.
Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything, and nothing here says that a script which passes these checks is correct or safe to trade. Pine Script and TradingView are products of TradingView, Inc.; ChatGPT and Claude are products of their makers. This page describes them in our own words and is not affiliated with any of them.
Also explained: Repaint checker, VWAP, Supertrend, RSI, UT Bot Alerts, Nadaraya-Watson Envelope, Squeeze Momentum, What is repainting on TradingView?, Is TradingView backtesting accurate?, Chandelier Exit, WaveTrend Oscillator, QQE MOD, Pivot highs and lows, Hull Suite, Range Filter, Twin Range Filter, HalfTrend, ZigZag++, SSL Hybrid, CM MacD Ultimate MTF, Volume Profile / Fixed Range, ADX and DI, Support Resistance Channels, Market Structure Break & Order Block, Order Block Finder, Pivot Point SuperTrend, Trendlines with Breaks [LuxAlgo], Divergence for Many Indicators, TradingView script selling terms, Support and Resistance Levels with Break, Liquidity Swings [LuxAlgo], Pine Script errors, Breakout Probability (Expo), Lorentzian Classification, SuperTrend AI (Clustering), Machine Learning Adaptive SuperTrend, Dynamic Swing Anchored VWAP, Support and Resistance Power Channel by , Support and Resistance (High Volume Boxe, Trendline Breakouts With Targets by Char, Breakout Finder by LonesomeTheBlue
Get the next teardown by email
One short email when a new teardown or free tool goes live, about twice a month. No signals, no hype. Unsubscribe in one click.
Almost done. Check your inbox and click the confirmation link.
Sent with Kit. Your address is used only for these emails. Privacy
No TradingView account yet? This affiliate link gives you a $15 coupon toward a paid plan, and we earn a commission if you buy one. The free plan is enough to follow this page.