enum - Pine Script Keyword
Overview
Section titled “Overview”This keyword allows the creation of an enumeration, enum for short. Enums are unique constructs that hold groups of predefined constants.
Syntax
Section titled “Syntax”[export ]enum <enumName><field_1> [= <title_1>]<field_2> [= <title_2>]...<field_N> [= <title_N>]Example
Section titled “Example”//@version=6indicator("Map with enum keys")//@enum Contains fields with titles representing ticker IDs.//@field aapl Has an Apple ticker ID as its title.//@field tsla Has a Tesla ticker ID as its title.//@field amzn Has an Amazon ticker ID as its title.enum symbols aapl = "NASDAQ:AAPL" tsla = "NASDAQ:TSLA" amzn = "NASDAQ:AMZN"//@variable A map that accepts fields from the `symbols` enum as keys and "float" values.map<symbols, float> data = map.new<symbols, float>()// Put key-value pairs into the `data` map.data.put(symbols.aapl, request.security(str.tostring(symbols.aapl), timeframe.period, close))data.put(symbols.tsla, request.security(str.tostring(symbols.tsla), timeframe.period, close))data.put(symbols.amzn, request.security(str.tostring(symbols.amzn), timeframe.period, close))// Plot the value from the `data` map accessed by the `symbols.aapl` key.plot(data.get(symbols.aapl))