Pine Script errors: causes and fixes
The messages TradingView prints in the Pine Editor console, what each one means, and the change that fixes it. Every page has a short script that triggers the error and the corrected Pine Script v6 version.
Syntax and indentation
The compiler can't read the code: indentation, wrapped lines, stray characters, names it doesn't know.
Undeclared identifier
Undeclared identifier "lenght"
Mismatched input
Mismatched input "label" expecting set "end of line without line continuation"
End of line without line continuation
Syntax error at input "end of line without line continuation"
Syntax error at input
Syntax error at input "upBars"
No viable alternative at character
no viable alternative at character "“"
Variable is already defined
"signal" is already defined
Inline inputs might not align
The inputs with the inline argument "bb" might not align correctly in the "Settings/Inputs" tab
Types and qualifiers
A value of the wrong type, or a value that changes on every bar where Pine needs one that stays fixed (series, simple, input, const).
series int used but simple int expected
Cannot call "ta.ema" with argument "length"="len". An argument of "series int" type was used but a "simple int" is expected.
hline(): series float used but input float expected
Cannot call "hline" with argument "price"="call "ta.sma" (series float)". An argument of "series float" type was used but a "input float" is expected.
series string used but const string expected
Cannot call "plotshape" with argument "text"="call "str.tostring" (series string)". An argument of "series string" type was used but a "const string" is expected.
Value with NA type cannot be assigned
Value with NA type cannot be assigned to a variable that was defined without type keyword
Return type of if/switch blocks not compatible
Return type of one of the "if" or "switch" blocks is not compatible with return type of other block(s) (literal string; literal int)
Cannot assign a value of another type
Cannot assign a value of the "string" type to the "level" variable. The variable is declared with the "float" type.
simple variable cannot accept a series value
A variable declared with the "simple" keyword cannot accept values of the "series int" form. Assign a "simple" value to this variable or remove the "simple" keyword from its declaration.
Cannot call operator + with a string and a number
Cannot call "operator +" with argument "expr0"="Close: ". An argument of "literal string" type was used but a "series float" is expected.
Scope
Code in the wrong place: plots inside blocks, functions that change globals, calls that skip bars.
Cannot use plot in local scope
Cannot use "plot" in local scope
Cannot modify global variable in function
Cannot modify global variable "count" in function
Should be called on each calculation for consistency
The function "ta.highest" should be called on each calculation for consistency. It is recommended to extract the call from this scope
Shadowing variable which exists in parent scope
Shadowing variable "stopLevel" which exists in parent scope. Did you want to use the ":=" operator instead of "=" ?
Old code in v6 (v4 and v5 to v6)
Functions and arguments that were renamed or removed, and the stricter bool rules of Pine Script v6.
Could not find function 'study'
Could not find function or function reference 'study'
Could not find function 'security'
Could not find function or function reference 'security'
Could not find function or function reference
Could not find function or function reference 'rsi'
No argument named transp
The "bgcolor" function does not have an argument with the name "transp"
No argument named when
The "strategy.entry" function does not have an argument with the name "when"
na() on a bool
Cannot call "na" with argument "x"="prevBullish". An argument of "series bool" type was used but a "simple float" is expected.
A bool can't be na
Cannot call "operator ?:" with argument "expr2"="na". An argument of "simple na" type was used but a "simple bool" is expected.
if condition must be a bool
The condition of the "if" statement must evaluate to a "bool" value.
Runtime limits
The script compiles but stops on the chart: loop time, history buffers, data requests, array bounds.
Loop is too long
Loop is too long (> 500 ms)
Historical offset beyond the buffer limit (max_bars_back)
The requested historical offset (X) is beyond the historical buffer’s limit (Y)
Too many securities (request.* limit)
Script requesting too many securities
Array index is out of bounds
Index xx is out of bounds. Array size is yy
Memory limits exceeded
Memory limits exceeded
Compile errors and warnings were reproduced with TradingView's Pine Script compiler, and every fixed script compiles in Pine Script v6. Runtime errors only appear on the chart; those pages follow TradingView's documentation.
Error not listed here?
Paste your script and the message into the free error fixer, or describe the indicator in plain English and let Edgoro write working Pine Script v6.