Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS2201

error Give name a type, for example: example

#What it means

A variable is declared with na as its starting value, which has no type, so the compiler cannot tell what kind of value it will hold.

#Typical cause

  • state x = na, let x = na or const x = na without a type.

#How to fix it

Write the type after the name, for example state lastHigh: float = na (or let lastHigh: float). See Types.

#Example

ChartScriptError: CS2201
//@chartscript 1
indicator("Last higher high", { overlay: true })
state lastHigh = na
if (high > high[1]) {
    lastHigh = high
}
plot(lastHigh)

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Last higher high", { overlay: true })
state lastHigh: float = na
if (high > high[1]) {
    lastHigh = high
}
plot(lastHigh)
  • CS2203 — Comparing with na is always false; use na(name) instead.
  • CS2204 — A condition cannot be na; write: example

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