Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS2204

error A condition cannot be na; write: example

#What it means

A condition (or any bool value) can only be true or false; it can never be na. Here a number or an na is used where a true/false value is needed.

#Typical cause

  • A number used as a condition, as in if (x).
  • A ternary that gives na on one side where a bool is needed.

#How to fix it

Write the test you mean, such as !na(x) && x != 0, and use false instead of na for bools.

#Example

ChartScriptError: CS2204
//@chartscript 1
indicator("Ready")
const avg = ta.sma(close, 10)
const ready = avg ? 1 : 0
plot(ready)

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Ready")
const avg = ta.sma(close, 10)
const ready = !na(avg) ? 1 : 0
plot(ready)
  • CS2701 — A condition must be a bool, but this is got.
  • CS2203 — Comparing with na is always false; use na(name) instead.

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