Adds a dropdown setting built from an enum type and returns the chosen enum member.
input.enum takes one member of a user-defined enum as defval and shows a dropdown of all members of that enum. The result is a member of the same enum, which a switch statement can branch on.
Each member's title string is what the user sees in the dropdown, so declare readable titles on the members.
Syntax
input.enum(defval: const enum, title: const string (optional), options: tuple of enum fields: [enumName.field1, enumName.field2, ...] (optional), tooltip: const string (optional), inline: const string (optional), group: const string (optional), confirm: const bool (optional), display: const plot_display (optional), active: input bool (optional)) -> input enumArguments
| Name | Type | Default | Description |
|---|---|---|---|
| defval | const enum | required | Default enum member, written Type.member. |
| title | const string | na | Name shown in the Settings dialog, the legend and the Data Window. |
| options | tuple of enum fields: [enumName. | na | A list of allowed members. Leave it out to offer the whole enum. |
| tooltip | const string | na | Text shown in a tooltip beside the input in the Settings dialog. |
| inline | const string | na | Entries sharing the same inline text sit on one row of the Settings dialog. |
| group | const string | na | Heading the input is listed under in the Settings dialog. |
| confirm | const bool | false | When true, the script asks for this value when it is first added to the chart. |
| display | const plot_display | display. | Where the value appears: a display.* constant or a combination of them. |
| active | input bool | true | When false, the input is greyed out and cannot be edited. |
Returns
input enum: the chosen enum member.
Remarks
- Enums replace string options when the set of choices is fixed, since a mistyped member name fails at compile time.
- On Sidechair: confirm, display and active are accepted and ignored.
Example
//@version=6
indicator("Enum input", overlay = true)
enum Kind
sma = "SMA"
ema = "EMA"
kind = input.enum(Kind.ema, "Average")
avg = kind == Kind.sma ? ta.sma(close, 20) : ta.ema(close, 20)
plot(avg, "Average", color = color.blue, linewidth = 2)See also
Runs on Sidechair