Sidechair

map.get()

Browse the reference

Returns the value stored under a key, or na when the key is not in the map.

Try it in the editor

The lookup does not change the map. A missing key gives na, so pair it with nz() or with map.contains() when na would be confused with a stored value.

For a bool map a missing key reads as false, and for a string map as na.

Syntax

Pine Script
map.get(id: any map type, key: series <type of the map's elements>) -> <value_type>
map.get(key: series <type of the map's elements>) -> <value_type>

Arguments

NameTypeDefaultDescription
idany map typerequiredThe map to read a value from. The map itself is not changed.
keyseries <type of the map's elements>requiredThe key whose value is returned. It has to match the key type of the map.

Returns

<value_type>: The stored value, or na.

Example

Pine ScriptRead a threshold by nameOpen in editor
//@version=6
indicator("map.get: thresholds", overlay = false)
var limits = map.new<string, float>()
if barstate.isfirst
    map.put(limits, "high", 70.0)
    map.put(limits, "low", 30.0)
r = ta.rsi(close, 14)
plot(r, "RSI")
hline(map.get(limits, "high"))
hline(map.get(limits, "low"))

See also

Runs on Sidechair