Sidechair

map.new()

Browse the reference

Creates an empty map for the key type and value type given in angle brackets.

Try it in the editor

Write both types after the name: map.new<string, float>() maps text keys to decimals, and map.new<int, label>() maps integers to labels. The map starts with no pairs.

Create it with var to keep its contents from one bar to the next. A map made on every bar without var starts empty each time.

Syntax

Pine Script
map.new() -> map<keyType, valueType>

Returns

map<keyType, valueType>: A new, empty map.

Remarks

  • On Sidechair: when the angle brackets are left out, the map defaults to string keys and float values.

Example

Pine ScriptVolume by weekdayOpen in editor
//@version=6
indicator("map.new: volume by weekday", overlay = false)
var byDay = map.new<int, float>()
d = dayofweek
map.put(byDay, d, nz(map.get(byDay, d)) + volume)
plot(nz(map.get(byDay, d)), "Total volume on this weekday")

See also

Runs on Sidechair