Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS5105

error A map key cannot be na.

#What it means

A map key cannot be na. Every key must be a real value.

#Typical cause

  • A key variable that is na on some bars, for example a string that was never set.

#How to fix it

Check the key first: only put or get when !na(key). See Collections.

#Example

ChartScriptOpen in editor
//@chartscript 1
indicator("Counts")
const counts = map.new<string, int>()
const key: string = na
counts.put(key, 1)
plot(counts.size())

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Counts")
const counts = map.new<string, int>()
const key: string = close > open ? "up" : "down"
if (!na(key)) {
    counts.put(key, 1)
}
plot(counts.size())

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