SuperCharting
Sign in Get started Account Open charts

Learn / Pine Script errors

Pine Script errors: a list of common errors and how to fix each one

A list of the most common Pine Script errors, what each message means and how to fix it, with a free online checker that finds the line with the error.

Most Pine Script errors come from a small set of causes: a name Pine cannot see, a function from an older version, an indent that breaks a block, or something that is only allowed at the top level of the script. This page lists the common error messages, says in one or two lines what each means, and links to a full guide for each. To find which error your own script has, paste it into the free Pine Script checker; it names the line and links the matching guide.

Pine Script is TradingView's language, and the messages below are the ones TradingView shows. SuperCharting runs Pine-compatible scripts in its own engine. Its messages are worded differently, and it accepts some code that TradingView rejects. TradingView is a trademark of TradingView, Inc.; SuperCharting is not affiliated with it.

Errors when the script is compiled

These stop the script before it runs on any candle. The message names a line, and the cause is usually on that line or the one above it.

Mismatched input ... expecting ...

Pine expected one thing next and found another. The word after "input" is what it found. Most of the time the cause is indentation: a single stray space at the start of a line, or an else that does not line up with its if. Fix "Mismatched input".

End of line without line continuation

A long statement was wrapped onto the next line and Pine could not tell that the new line carries on. Indent each continuation line by a number of spaces that is not a multiple of 4, such as 2 or 5. Fix "End of line without line continuation".

Undeclared identifier

The script uses a name Pine cannot see at that point. Usually the variable was created inside an if or for block and used after the block ended, or its spelling or case is different. Declare it once at the top level, for example float up = na, and assign it inside the block with :=. Fix "Undeclared identifier".

Could not find function or function reference

The script calls a function Pine does not know. This is almost always old version 4 code: sma() became ta.sma(), security() became request.security(). Fix "Could not find function".

Cannot use 'plot' in local scope

plot() sits inside an if block, a loop or a function. Pine needs every plot to exist on every bar, so keep plot() at the top level and make the value conditional: plot(cond ? v : na). Fix "Cannot use plot in local scope".

Cannot modify global variable in function

A function you wrote uses := on a variable declared outside it. Return the new value from the function and do the := at the top level instead. Fix "Cannot modify global variable in function".

'series int' was used but a 'simple int' is expected

A length that can change from bar to bar was passed to a function that needs a fixed length, such as some ta.* functions. Take the length from input.int(). Fix the series and simple int error.

Script must have at least one output function call

The indicator works out values but never shows or sends anything. Add an output, usually a plot() of the value you calculated. Fix "at least one output function".

Errors while the script runs

These appear only after the script starts running on the chart's candles, so a script can compile and still stop with one of them.

Loop is too long (> 500 ms)

One for or while loop took too long on one bar. Make the loop do less: use a built-in such as math.sum() or keep a running value instead of recounting history on every bar. Fix "Loop is too long".

Pine cannot determine the referencing length of a series

The script reads history with [] inside a conditional branch, so Pine cannot tell how many past bars to keep. Add max_bars_back = N to indicator() or strategy(), or move the history reference out of the branch. Fix the max_bars_back error.

How to find and fix errors in SuperCharting

  1. Paste the script into the free Pine Script checker and press Check script. It compiles the code, runs it on sample candles, and shows the first error with its line number.
  2. Open the guide it links, fix that line, and check again. Fix errors one at a time: the first one often causes the ones after it.
  3. To have common errors repaired for you, open the script in the Script Editor with a free account and press Auto-fix. It lists every change it made, and Undo Auto-fix in the More menu brings your original back.
  4. When the script is clean, add it to a chart, for example NSE:NIFTY on the 15-minute timeframe, and look at the result on real candles.

Reading an error message

Every message has three useful parts. The line number tells you where Pine stopped, but the real mistake is often on the line above, especially for indentation and bracket errors. The quoted name, such as 'foo' in "Undeclared identifier 'foo'", is the exact text Pine could not use, so search the script for it. The type words (series, simple, const, input) say how fixed a value is: const never changes, input is set in the settings, simple is known before the first bar, and series can change on every bar. A function asking for a more fixed type than you gave it is the cause of the "simple int expected" family of errors.

Errors from old scripts

Many scripts on the web were written for Pine version 4 or 5. Compiled as version 6, they fail with "Could not find function" (functions moved under ta., math., request. and others), "Undeclared identifier" (colour names such as red became color.red), or type errors where version 6 is stricter. Changing //@version= alone does not convert a script. Auto-fix in the Script Editor updates the common old names for you and lists each change. The Pine Script v6 basics guide covers the current syntax.

Frequently asked questions

Why does my script work on SuperCharting but not on TradingView?

SuperCharting runs scripts in its own engine, which accepts some code TradingView rejects, such as a plot() inside an if block. A clean result in the SuperCharting checker does not guarantee the script compiles on TradingView.

Is the Pine Script checker free?

Yes, it is free for now and needs no account. It allows 20 checks an hour from one connection; the Script Editor with a free account has no such limit on checking as you type.

Why does fixing one error show another?

Pine reports the first error it reaches. After you fix it, the checker gets further through the script and can find the next one. Keep checking until it says the script compiles and runs.

Can the checker tell me if my strategy is profitable?

No. It only checks that the code compiles and runs. Whether a strategy is any good is a separate question; test it in the Strategy Tester, and remember that past results do not guarantee future results.

Try it on a live chart

SuperCharting is an AI-enabled charting and coding platform in your browser: charts, Pine-compatible scripts with AI Auto-fix, the Strategy Tester, alerts and the screener.

Create a free account More guides