Returns true when a key is present in a map.
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
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 boolArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any map type | required | The map to look in for the key. The map is not changed. |
| key | series <type of the map's elements> | required | The 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
//@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