The type of a collection of key-value pairs, such as map<string, float>, where each key appears once.
A map looks up a value by key instead of by position. Declare it with the generic form: map<string, float> prices = map.new<string, float>(). Keys can be int, float, bool, string or color; values can be any type, including user-defined types.
Pairs keep the order in which their keys were first added. Putting a value under a key that exists replaces the value and leaves the order alone. A map can hold at most 50,000 pairs.
Remarks
- Maps are reference types, like arrays: a second variable assigned from a map shares the same pairs, and
map.copy()makes an independent one. - A value that is itself a collection has to be wrapped in a user-defined type.
Example
//@version=6
indicator("map type: counts", overlay = false)
var counts = map.new<string, int>()
key = close >= open ? "up" : "down"
map.put(counts, key, nz(map.get(counts, key)) + 1)
plot(nz(map.get(counts, "up")), "Up bars", color.green)
plot(nz(map.get(counts, "down")), "Down bars", color.red)See also
Runs on Sidechair