Sidechair

map.contains()

Browse the reference

Returns true when a key is present in a map.

Try it in the editor

It checks the keys only, so a pair whose value is na still counts as present. Use it before map.get() when na is a real value in your data.

The check does not change the map or its order.

Syntax

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

Arguments

NameTypeDefaultDescription
idany map typerequiredThe map to look in for the key. The map is not changed.
keyseries <type of the map's elements>requiredThe key to look for. It has to match the key type of the map.

Returns

series bool: true when the key exists, otherwise false.

Example

Pine ScriptFirst visit per price levelOpen in editor
//@version=6
indicator("map.contains: first touch", overlay = true)
var seen = map.new<float, bool>()
lvl = math.round(close)
first = not map.contains(seen, lvl)
map.put(seen, lvl, true)
plotshape(first, "New level", shape.circle, location.belowbar, color.blue, size = size.tiny)

See also

Runs on Sidechair