Declares an enumeration: a fixed set of named values whose titles can drive input.enum dropdowns.
enum Name followed by an indented list of fields declares a type whose only values are those fields, reached as Name.field. Each field can carry a title string, as in fast = "Fast average". The title is what a dropdown shows, and what str.tostring prints.
Pass an enum field to input.enum to get a dropdown the user can change, and compare the result with == or a switch. An enum cannot be mixed with strings or numbers, which removes typos that string comparisons allow. export enum shares one from a library.
Syntax
[export ]enum <enumName> <field_1> [= <title_1>] <field_2> [= <title_2>] ... <field_N> [= <title_N>]Remarks
- Fields of an enum are not ints. You cannot do arithmetic on them or use them as array indexes.
- On Sidechair: enums with titles work, and
input.enumuses them.
Example
//@version=6
indicator("Enum", overlay = true)
enum AvgKind
sma = "SMA"
ema = "EMA"
kind = input.enum(AvgKind.ema, "Average type")
avg = switch kind
AvgKind.sma => ta.sma(close, 20)
AvgKind.ema => ta.ema(close, 20)
plot(avg, "Average", color.blue, 2)See also
Runs on Sidechair