input.enum() - Pine Script Function
input.enum()
Section titled “input.enum()”Overview
Section titled “Overview”Adds an input to the Inputs tab of your script’s Settings, which allows you to provide configuration options to script users. This function adds a dropdown with options based on the enum fields passed to its defval and options parameters.
Syntax
Section titled “Syntax”input.enum(defval, title, options, tooltip, inline, group, confirm, display, active) → input enumParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| defval | const enum | Determines the default value of the input |
| which | — | users can change in the script’s “Settings/Inputs” tab. When the options parameter has a specified tuple of enum fields |
| the | — | tuple must include the defval. |
Returns
Section titled “Returns”Value of input variable.
Remarks
Section titled “Remarks”- All fields included in the defval and options arguments must belong to the same enum.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("Session highlight", overlay = true)//@enum Contains fields with popular timezones as titles.//@field exch Has an empty string as the title to represent the chart timezone.enum tz utc = "UTC" exch = "" ny = "America/New_York" chi = "America/Chicago" lon = "Europe/London" tok = "Asia/Tokyo"//@variable The session string.selectedSession = input.session("1200-1500", "Session")//@variable The selected timezone. The input's dropdown contains the fields in the `tz` enum.selectedTimezone = input.enum(tz.utc, "Session Timezone")//@variable Is `true`if the current bar's time is in the specified session.bool inSession = falseif notna(time("", selectedSession, str.tostring(selectedTimezone)))inSession := true// Highlight the background when `inSession` is `true`.bgcolor(inSession ? color.new(color.green, 90) : na, title = "Active session highlight")