◆ New — Strategy Validator, Code Fixer & Prop Compliance Checker are live. Try one free →
Home / Pine errors / Scope
Pine Script v6 error · Scope

Pine Script v6 "Undeclared identifier" error — cause & fix

The error
Undeclared identifier '<name>'

Pine v6 raises "Undeclared identifier" when you reference a variable or function name the compiler has never seen at that point — usually a typo, a wrong namespace, or use-before-declaration. Educational content only; nothing here is financial advice or a promise of profitability.

Why it happens

The compiler reached a name that was never declared in the current or an enclosing scope before this line. The three common triggers are: (1) a misspelling or wrong casing (rsiValeu vs rsiValue), (2) using a built-in without its v6 namespace so the bare name is unknown (rsi instead of ta.rsi), and (3) referencing a variable earlier in the file than the line that declares it, since Pine reads top-to-bottom. Names declared inside an if/for block are also local and are undeclared at the main scope.

How to fix it

Declare the identifier before you use it and spell it exactly the same way everywhere, including case. If it is a built-in, add the correct v6 namespace (ta.*, math.*, str.*, request.*). If the value is computed inside a conditional block but read at the main scope, declare the variable at the main scope first (e.g. with var or a plain assignment) and only assign to it inside the block.

What triggers it

//@version=6
indicator("Undeclared demo", overlay=true)
plot(rsiValue)
rsiValue = ta.rsi(close, 14)

The fix, in code

✓ Validated clean by our own engine

//@version=6
indicator("Undeclared demo", overlay=false)
rsiValue = ta.rsi(close, 14)
plot(rsiValue, title="RSI")

Related errors

Educational, code-correctness reference only — not financial advice. Trading involves substantial risk of loss.

Catch the bug that compiles.Run auditGet Pro