Sidechair

map.size()

Browse the reference

Counts the key and value pairs a map holds at this moment.

Try it in the editor

A new map has size 0. Each new key adds one; replacing the value of an existing key does not change the count.

It is the number to compare against a limit when a map should not grow without bound.

Syntax

Pine Script
map.size(id: any map type) -> series int
map.size() -> series int

Arguments

NameTypeDefaultDescription
idany map typerequiredThe map to count. Returns the number of key and value pairs it holds right now.

Returns

series int: The number of pairs, as an integer.

Example

Pine ScriptDistinct rounded closesOpen in editor
//@version=6
indicator("map.size: distinct levels", overlay = false)
var levels = map.new<float, int>()
map.put(levels, math.round(close), bar_index)
plot(map.size(levels), "Distinct whole-number closes")

See also

Runs on Sidechair