Free: indicator teardowns, a repaint checker and open-source scripts. No buy/sell signals, ever.

Taught to TradeSystems over signals.

Explainers / Pine Script errors

Pine Script errors: what the common messages mean and how to fix them

The Pine Editor stops at the first problem it finds and prints one line, in the editor's own words, with a line number. The words are precise but not friendly. This page lists the messages people search for most, what each one is actually saying, and the fix that usually works. Everything here is free. The last section is about the scripts that compile and still behave wrong, which no error message will ever tell you about.

First, three things that solve most of it

"Syntax error at input 'end of line without line continuation'"

The parser reached the end of a line and was still expecting more. Three causes cover nearly every case:

"Mismatched input 'X' expecting 'end of line without line continuation'"

The same family. The parser found something where it expected the line to end. "X" is the thing it found. If X is ) or ], there is one closing bracket too many. If X is =, you probably wrote = where the language wanted := (reassignment of an existing variable) or wrote a comparison with one = instead of two. If X is else, the else is on a line of its own but not aligned with its if, or the body between them is indented wrongly.

"Undeclared identifier 'X'"

The script uses a name it has never seen defined. Four causes, in order of how often they come up:

"Could not find function or function reference 'study'"

The script says study(...) but the version line is 5 or 6, where the declaration is indicator(...). Change the word, and check the arguments: study(title, shorttitle, overlay) maps onto indicator(title, shorttitle, overlay) directly. The same message with ta.sum means the function is in the wrong namespace: it is math.sum(). With security it is request.security(). With input.resolution it is input.timeframe().

"Cannot use 'plot' in local scope"

plot(), plotshape(), plotchar(), hline(), fill(), bgcolor() and alertcondition() can only sit at the top level of the script, never inside an if, for or a function. The compiler is not being difficult: a plot is a fixed output of the script, so it has to exist on every bar. The fix is to move the plot to global scope and put the condition inside it:

// not allowed
if longCondition
    plotshape(true, style=shape.triangleup)

// allowed
plotshape(longCondition ? true : na, style=shape.triangleup)

For colours, plot(x, color = cond ? color.green : color.red) does the same job. Drawings (label.new, line.new, box.new) are different: they are allowed inside blocks, which is why people reach for them when a plot is refused.

"Cannot call 'na' with argument 'x'=... (series bool)"

From version 5 a bool can only be true or false, never na, so na(someBoolean) is rejected. The script, usually converted from v4, is testing whether a condition "has no value yet". Replace the test with what it meant: not someBoolean, or test the number that feeds the condition (na(close[20])) instead of the condition itself.

"The script must have one indicator(), strategy() or library() function call"

Either the declaration line is missing, there are two of them (a copied script pasted under another one), or it is misspelled. Exactly one, near the top. A script with strategy() cannot also call indicator().

"Cannot assign a tuple to a variable" and "Tuple size mismatch"

Some functions return several values at once, for example ta.macd() returns three and ta.supertrend() returns two. They have to be unpacked into the same number of names: [macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9). Assigning the result to one name, or to the wrong number of names, gives these two messages.

"Pine cannot determine the referencing length of a series. Try using max_bars_back"

The script reads a past value with a bracket, x[n], where n is itself computed and the compiler cannot work out the deepest n it will ever need, so it cannot reserve history. Fixes, from cheap to blunt: use a fixed number instead of a computed one where you can; wrap the series with max_bars_back(x, 500); or set max_bars_back = 500 in the indicator() call, which costs memory on every series in the script. The related runtime message, "The requested historical offset (N) is beyond the historical buffer's limit", means the same thing happened while running: the script asked for more history than was reserved.

"Script requesting too many securities"

Each request.security() call with a different symbol, timeframe or expression counts toward a fixed limit per script (40 in recent versions). Multi-timeframe scripts hit it by requesting one value at a time. Request a tuple in one call instead of several calls, [o, h, l, c] = request.security(syminfo.tickerid, "D", [open, high, low, close]), and reuse the result.

Runtime errors: "Loop is too long" and "Memory limits exceeded"

These appear after the script compiles, as a red mark on the chart. A for or while loop ran past the time the engine allows on one bar, or the script holds too many drawings and array elements. Reduce the loop bound, exit early, cap arrays with array.shift() when they grow, and delete old labels and lines instead of letting them pile up. If the script was copied from a published one that works, the difference is usually the chart: a one-second chart with years of history runs the same loop many more times.

Fixing the error is not fixing the script

Every message above is about whether the script can run. None of them is about whether it is right. The problems that matter compile without a word:

For those there is no error line. The free repaint checker runs in your browser and flags the known patterns in a pasted source. When a script compiles and still behaves differently live from how it looked in history, that is what the audit below reads for, line by line.

Where it fails

Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything, and nothing here says that a script which compiles, or passes a checker, is correct or safe to trade. Pine Script and TradingView are products of TradingView, Inc.; this page describes their published language and editor in our own words and is not affiliated with 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], Breakout Probability (Expo), Did ChatGPT or Claude write your Pine Sc, 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

Next steps

  • Get a script fixed. Compiles but behaves differently live, or changes after a reload? In a Pine Script Audit, an AI model reads every line and writes a report on what to fix for $49, or also fixes those problems for $149. It cannot prove a script is safe.
  • Check your own script. Paste its source into the free repaint checker. It runs in your browser and flags known patterns.
Subscribe to the Teardown Letter: $19/moBack to Taught to Trade

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.