Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS2203

error Comparing with na is always false; use na(name) instead.

#What it means

Comparing a value with na using == or != is always false, because any comparison involving na is false. The check you meant needs the na() function.

#Typical cause

  • x == na or x != na.

#How to fix it

Write na(x) to test for "no value", and !na(x) for "has a value". The editor offers this as a quick fix.

#Example

ChartScriptError: CS2203
//@chartscript 1
indicator("Average or close", { overlay: true })
const avg = ta.sma(close, 50)
plot(avg == na ? close : avg)

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Average or close", { overlay: true })
const avg = ta.sma(close, 50)
plot(na(avg) ? close : avg)
  • CS2204 — A condition cannot be na; write: example
  • CS2201 — Give name a type, for example: example

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