Sidechair

input.enum()

Browse the reference

Adds a dropdown setting built from an enum type and returns the chosen enum member.

Try it in the editor

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

Pine Script
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 enum

Arguments

NameTypeDefaultDescription
defvalconst enumrequiredDefault enum member, written Type.member.
titleconst stringnaName shown in the Settings dialog, the legend and the Data Window.
optionstuple of enum fields: [enumName.field1, enumName.field2, ...]naA list of allowed members. Leave it out to offer the whole enum.
tooltipconst stringnaText shown in a tooltip beside the input in the Settings dialog.
inlineconst stringnaEntries sharing the same inline text sit on one row of the Settings dialog.
groupconst stringnaHeading the input is listed under in the Settings dialog.
confirmconst boolfalseWhen true, the script asks for this value when it is first added to the chart.
displayconst plot_displaydisplay.allWhere the value appears: a display.* constant or a combination of them.
activeinput booltrueWhen 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

Pine ScriptEnum-driven averageOpen in editor
//@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