Skip to content
Algo Trade Analytics Docs

enum - Pine Script Keyword

This keyword allows the creation of an enumeration, enum for short. Enums are unique constructs that hold groups of predefined constants.

[export ]enum <enumName>
<field_1> [= <title_1>]
<field_2> [= <title_2>]
...
<field_N> [= <title_N>]
//@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))