Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS2002

error name is already declared in this block (line line).

#What it means

A name is declared twice in the same block. The message gives the line of the first declaration.

#Typical cause

  • const x = ... or let x = ... written twice where the second should change the value: write x = ... without let to change a variable.
  • Two parameters, fields or enum items with the same name.
  • A local name that is the same as a name brought in by import { … }.

#How to fix it

Change the existing variable with x = ... (declare it with let so it can change), or pick a different name for the second one. See Variables.

#Example

ChartScriptError: CS2002
//@chartscript 1
indicator("Length")
const len = 14
const len = 20
plot(ta.sma(close, len))

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Length")
let len = 14
len = 20
plot(ta.sma(close, len))
  • CS2402 — This declares a new name that hides the one from line line; did you mean to change it with op ?
  • CS2401 — name is not declared; declare it with decl before assigning to it.

The ChartScript documentation is in English for now; translations will follow.