Pine Script v6 / v5UI Inputs & ControlsDropdown Menus

Pine Script input string options: Dropdown Menus & Value Mapping

Create a Pine Script dropdown with input.string() with the options=[...] parameter and a default that matches one of its choices. Use the returned string in a comparison or map it to a calculation or numeric value with Pine Script switch expressions.

input.string Declaration Fragment

string selected = input.string(defval="EMA", title="MA Type", options=["EMA", "SMA", "RMA", "WMA"], group="Settings", inline="ma1")
Interactive Code Preview

Multi-Mode Moving Average Selector Preview

Change the defaults to generate Pine Script. This preview does not execute Pine Script or calculate chart values.

Generated Script Defaults
Selected Mapping
Selected Option:"EMA"
Mapped Function:ta.ema(src, len)
Weighting Model:Exponential weighting favoring recent bars
Generated Pine Script v6 / EMA Mode
//@version=6
indicator("Dynamic Moving Average Selector", overlay=true)

// Dropdown input with pine script input string options
string ma_type = input.string(
     defval="EMA",
     title="MA Type",
     options=["EMA", "SMA", "RMA", "WMA", "VWMA", "HMA"],
     tooltip="Select calculation algorithm for smoothing line",
     group="Moving Average Settings", inline="ma_row"
 )
int ma_period = input.int(20, "Period", minval=1, group="Moving Average Settings", inline="ma_row")
series float ma_source = input.source(close, "Source", group="Moving Average Settings")

// Map dropdown string option to calculation with switch expression
float ma_calculated = switch ma_type
    "EMA"  => ta.ema(ma_source, ma_period)
    "SMA"  => ta.sma(ma_source, ma_period)
    "RMA"  => ta.rma(ma_source, ma_period)
    "WMA"  => ta.wma(ma_source, ma_period)
    "VWMA" => ta.vwma(ma_source, ma_period)
    "HMA"  => ta.hma(ma_source, ma_period)
    => ta.ema(ma_source, ma_period) // Default fallback

plot(ma_calculated, title="EMA (20)", color=color.blue, linewidth=2)
Pine Script v6 SourceIncludes Default Fallback
Quick Start Guide

Complete Pine Script v6 Dropdown Selector

This example indicator demonstrates declaring dropdown options with input.string() and routing calculations with an exhaustive switch expression:

Pine Script v6 / Moving Average Type Dropdown with Switch Routing
//@version=6
indicator("Moving Average Selector [Pineify]", overlay=true)

// 1. Dropdown input using pine script input string options
string ma_type = input.string(
     defval="EMA",
     title="Calculation Method",
     options=["EMA", "SMA", "RMA", "WMA", "VWMA", "HMA"],
     tooltip="Select the smoothing algorithm used for trend calculations",
     group="Moving Average Configuration",
     inline="ma_row"
 )
int ma_len = input.int(20, "Period", minval=1, maxval=500, group="Moving Average Configuration", inline="ma_row")
series float ma_src = input.source(close, "Source", group="Moving Average Configuration")

// 2. Map dropdown string options to indicator calculations via switch expression
float ma_value = switch ma_type
    "EMA"  => ta.ema(ma_src, ma_len)
    "SMA"  => ta.sma(ma_src, ma_len)
    "RMA"  => ta.rma(ma_src, ma_len)
    "WMA"  => ta.wma(ma_src, ma_len)
    "VWMA" => ta.vwma(ma_src, ma_len)
    "HMA"  => ta.hma(ma_src, ma_len)
    => ta.ema(ma_src, ma_len) // Fallback if the mapping is edited later

// 3. Render output on chart
plot(ma_value, title="Selected MA", color=color.blue, linewidth=2)

1. Fixed String Choices

Pass a tuple of constant choices into options=[...].

2. Strict Default Match

Ensure defval matches one option item with exact case-sensitivity.

3. Exhaustive Routing

An optional default fallback branch (=>) handles unmatched numeric choices; warm-up values can still be na.

Numeric Presets

Mapping Dropdown Strings to Numeric Parameters & Multipliers

TradingView inputs cannot compute arithmetic directly on text. In strategies and indicators requiring risk presets, volatility multipliers, or position size fractions, use a switch expression to map descriptive labels (e.g. "Narrow (1.0x ATR)") to numeric floating-point values:

Pine Script v6 / Mapping String Options to Numeric Float Multipliers
//@version=6
indicator("ATR Multiplier Presets [Pineify]", overlay=true)

// Dropdown input mapping string labels to numeric coefficients
string band_preset = input.string(
     defval="Medium (1.5x ATR)",
     title="Volatility Band Preset",
     options=[
         "Narrow (1.0x ATR)",
         "Medium (1.5x ATR)",
         "Wide (2.5x ATR)",
         "Custom Multiplier"
     ],
     tooltip="Select volatility band width or enter custom factor",
     group="Band Settings"
 )

float custom_mult = input.float(2.0, "Custom ATR Factor", minval=0.1, maxval=10.0, step=0.1, group="Band Settings", active=band_preset == "Custom Multiplier")
int atr_period = input.int(14, "ATR Period", minval=1, group="Band Settings")

// Map human-readable dropdown strings to numeric float values
float atr_multiplier = switch band_preset
    "Narrow (1.0x ATR)" => 1.0
    "Medium (1.5x ATR)"     => 1.5
    "Wide (2.5x ATR)"   => 2.5
    "Custom Multiplier"       => custom_mult
    => 1.5 // Fallback default multiplier

float current_atr = ta.atr(atr_period)
float upper_band = close + (current_atr * atr_multiplier)
float lower_band = close - (current_atr * atr_multiplier)

plot(upper_band, title="Upper Volatility Band", color=color.red, style=plot.style_line)
plot(lower_band, title="Lower Volatility Band", color=color.teal, style=plot.style_line)

Why String-to-Numeric Mapping Matters

  • • Better User Experience:A label such as "Wide (2.5x ATR)" shows both the preset name and its multiplier.
  • • Type Safety:The preset branches return positive numbers; the custom input separately enforces minval=0.1.
  • • Extensible Hybrid Pattern:You can provide standard presets and include a "Custom Multiplier" option whose active condition enables a separate input.float() field.
Strategy Example

Multi-Mode Strategy Execution with Layout Grouping

Combine group and inline attributes to build clean, modular strategy interfaces where the trader toggles between Trend Following, Mean Reversion, and Breakout models from a single dropdown:

This example demonstrates input routing, not a tested trading system. It is educational, not investment advice, and excludes commission and slippage.

Pine Script v6 / Multi-Mode Strategy with Grouped Inputs
//@version=6
strategy("Multi-Mode Execution Strategy [Pineify]", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// Strategy model dropdown selector
string execution_mode = input.string(
     defval="Trend Following",
     title="Strategy Mode",
     options=["Trend Following", "Mean Reversion", "Breakout"],
     group="Model Selection",
     tooltip="Switch the active quantitative model for order triggers"
 )

// Grouped and inlined indicator parameters
int fast_ema_len = input.int(20, "Fast EMA", minval=1, group="Trend Following Setup", inline="ema")
int slow_ema_len = input.int(50, "Slow EMA", minval=1, group="Trend Following Setup", inline="ema")
int rsi_len      = input.int(14, "RSI Period", minval=1, group="Mean Reversion Setup", inline="rsi")
int rsi_ob       = input.int(70, "OB Level", minval=0, maxval=100, group="Mean Reversion Setup", inline="rsi_levels")
int rsi_os       = input.int(30, "OS Level", minval=0, maxval=100, group="Mean Reversion Setup", inline="rsi_levels")
int breakout_len = input.int(20, "High/Low Lookback", minval=1, group="Breakout Setup")

// Technical indicators
float fast_ema = ta.ema(close, fast_ema_len)
float slow_ema = ta.ema(close, slow_ema_len)
float rsi_val  = ta.rsi(close, rsi_len)
float highest_high = ta.highest(high, breakout_len)[1]
float lowest_low   = ta.lowest(low, breakout_len)[1]

bool long_condition  = false
bool close_condition = false

// Switch statement routing execution logic based on string dropdown
switch execution_mode
    "Trend Following" =>
        long_condition  := ta.crossover(fast_ema, slow_ema)
        close_condition := ta.crossunder(fast_ema, slow_ema)
    "Mean Reversion" =>
        long_condition  := ta.crossover(rsi_val, rsi_os)
        close_condition := ta.crossunder(rsi_val, rsi_ob)
    "Breakout" =>
        long_condition  := close > highest_high
        close_condition := close < lowest_low
    =>
        // Default fallback ensures deterministic behavior
        long_condition  := ta.crossover(fast_ema, slow_ema)
        close_condition := ta.crossunder(fast_ema, slow_ema)

if long_condition and strategy.position_size == 0
    strategy.entry("Long Entry", strategy.long)

if close_condition and strategy.position_size > 0
    strategy.close("Long Entry")
API Reference

input.string() Parameters Reference

Common parameters supported by input.string() in Pine Script. Current v6 also supports active to enable or disable a field:

ParameterTypeRequiredDescription
defvalconst stringYesDefault selected value. Must strictly and case-sensitively match one string element inside the options list.
titleconst stringNoDescriptive text label rendered directly to the left of the dropdown selector in the settings dialog.
optionstuple of const stringsYes (for dropdown)Tuple of const string choices (e.g. ["EMA", "SMA", "RMA"]). Transforms open text field into a select menu.
tooltipconst stringNoInformational guidance rendered in the popup tooltip when hovering over the question mark icon. Supports newline (\n) formatting.
inlineconst stringNoGroups inputs with the same inline string identifier onto a single horizontal row for compact layout.
groupconst stringNoSection heading that groups related inputs under a titled section inside the script settings modal.
confirmconst boolNoWhen true, prompts the user to review and confirm input selections before adding the indicator or strategy to the chart.
displaydisplay.*NoControls input value display on the chart header status line and data window (e.g. display.all, display.none, display.status_line).

Version support and official references

String dropdowns and optional explicit type declarations work in both v5 and v6. The examples here use v6; the numeric example uses active to enable the custom multiplier only when Custom Multiplier is selected. Changing a TradingView input reruns the script across the available data.

Troubleshooting & Common Errors

Compiler Errors & Common Dropdown Mistakes

Prevent unexpected compilation halts and silent runtime bugs when creating dropdown inputs:

Default Value Mismatch Error

If defval does not match any element in the options list, the input declaration is invalid. Remember that Pine Script comparisons are strictly case-sensitive.

❌ options=["EMA", "SMA"], defval="ema" (case mismatch)
✅ options=["EMA", "SMA"], defval="EMA"

Attempting Dynamic Arrays in Options

The options parameter strictly demands a tuple of const strings. Passing runtime variables, tickers, or mutable arrays produces a fatal compiler error.

❌ options=[syminfo.ticker, "Index"] (dynamic variable)
✅ options=["SPY", "QQQ", "IWM"] (constants)

Unmatched Numeric Choice

When mapping dropdown choices with a switch expression, a numeric mapping without the fallback branch (=>) returns na only when no case matches. Cover every option; a fallback does not remove indicator warm-up requirements.

Read more in our guide on Pine Script switch Defaults & Return Types.

Branch Return Type Incompatibility

All branches of a switch expression must return compatible types. If one branch returns a float and another returns a string or color, compilation fails.

❌ "EMA" => ta.ema(close, 20), "None" => "off"
✅ "EMA" => ta.ema(close, 20), "None" => float(na)
Related TradingView Coding References

Deepen Your Pine Script Development Knowledge

Explore specialized guides and error diagnostics from our TradingView developer library:

Frequently Asked Questions

Common questions on pine script input string options, dropdown menus, and switch mapping.

Pineify TradingView Suite

Build Indicators with Adjustable Inputs

Describe the settings and calculations you need to the AI Coding Agent, or assemble supported indicators in the Visual Pine Editor.

AI Coding Assistant

Pine Script AI Coding Agent

Describe your multi-mode indicators, moving average selectors, and risk multipliers in natural language. Ask the agent to generate the inputs and mappings, then review the script and test each choice in TradingView.

Visual Builder

Visual Pine Editor

Construct indicators and strategies visually. Combine supported indicators and conditions, adjust their parameters, and export Pine Script for TradingView.