Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS2402

warning This declares a new name that hides the one from line line; did you mean to change it with op ?

#What it means

This is a warning. Inside a block, let name = ... or const name = ... declares a new variable that hides the one with the same name outside the block. The outer variable keeps its old value, which is rarely what you want.

#Typical cause

  • Writing let or const inside an if or a loop when you meant to change the outer variable.

#How to fix it

Drop the let / const and write name = ... to change the existing variable (declared with let or state). If you really want a separate one, give it a different name. See Variables.

#Example

ChartScriptWarning: CS2402
//@chartscript 1
indicator("Trend")
const trend = 0
if (close > open) {
    const trend = 1
}
plot(trend)

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Trend")
let trend = 0
if (close > open) {
    trend = 1
}
plot(trend)
  • CS2401 — name is not declared; declare it with decl before assigning to it.
  • CS2002 — name is already declared in this block (line line).

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