Why do I get an ‘Undeclared identifier’ error in Pine Script?

Pine Script
SOURCE-CHECKED FIX Source checked Aug 12, 2026 TradingView documentation ✓
Short answer

The name is not visible at the point where Pine compiles it. Check spelling and capitalization, confirm that the identifier is declared before use, and make sure it is not confined to another local scope or renamed in the current Pine version.

What you may be seeing

  • The compiler highlights a variable, function or namespace name
  • The identifier exists elsewhere in the script but is still not found
  • The error appeared after copying code or changing Pine versions

Most likely causes

  1. The identifier is misspelled or uses different capitalization
  2. The declaration occurs later or only inside another local scope
  3. An old function or namespace name is being used in a newer Pine version

Try this first

  1. Compare the highlighted name character by character with its declaration
  2. Move or create the declaration before the first use
  3. Check whether the value is declared only inside an if, loop or function
  4. Verify migrated built-ins and namespaces in the current reference

If that didn’t fix it

  1. Pass a local value into a function explicitly
  2. Declare a persistent variable in the appropriate outer scope
  3. Replace an obsolete built-in with its documented current name

Verify the fix

Save the script and confirm the compiler no longer reports the identifier error, then verify the variable still has the intended lifetime and value.

Why this happens

The name is not visible at the point where Pine compiles it. Check spelling and capitalization, confirm that the identifier is declared before use, and make sure it is not confined to another local scope or renamed in the current Pine version.

Pine is case-sensitive and local variables do not automatically exist outside their block. When migrating a script, also verify renamed namespaces and functions against the current reference.

Sources & next steps

Did this fix your problem? Your answer helps us rank fixes by real-world usefulness.
← Back to Resolve