Pine Script input.string Options: How to Create Dropdown Menus
In TradingView Pine Script, adding dropdown selection menus to an indicator or strategy is done via input.string() with the options=[...] parameter. By passing a fixed list of allowed string choices, TradingView automatically replaces the free-form text field with a clean select dropdown.
Direct Syntax Pattern
string selected = input.string(defval="EMA", title="MA Type", options=["EMA", "SMA", "RMA", "WMA"])Complete Pine Script v6 Dropdown Example
This indicator demonstrates how to create a Moving Average selector dropdown and use a switch expression to route the chosen calculation.
//@version=6
indicator("Moving Average Selector [Pineify]", overlay=true)
// 1. Dropdown input using input.string with options
string ma_type = input.string(
defval="EMA",
title="Moving Average Type",
options=["EMA", "SMA", "RMA", "WMA"],
tooltip="Select calculation method for the moving average"
)
int ma_len = input.int(20, "Length", minval=1)
// 2. Switch expression to calculate the selected MA
float ma_value = switch ma_type
"EMA" => ta.ema(close, ma_len)
"SMA" => ta.sma(close, ma_len)
"RMA" => ta.rma(close, ma_len)
"WMA" => ta.wma(close, ma_len)
=> ta.ema(close, ma_len)
// 3. Plot the result
plot(ma_value, title="Selected MA", color=color.blue, linewidth=2)1. Define Options
Provide a string array of choice names in options=[...].
2. Match Default
Ensure defval matches one option exactly.
3. Switch Logic
Use switch to execute the corresponding calculation.
input.string() Parameters Breakdown
Understanding every argument supported by input.string() in Pine Script v6:
| Parameter | Type | Required | Description |
|---|---|---|---|
| defval | const string | Yes | Default selected value. Must strictly match one of the string items in the options array. |
| title | const string | No | Label displayed next to the dropdown menu in the settings dialog. |
| options | const string[] | Yes (for dropdown) | List of string literals that populate the dropdown menu (e.g. ["EMA", "SMA", "RMA"]). |
| tooltip | const string | No | Informational text displayed when hovering over the question mark icon in settings. |
| inline | const string | No | Joins multiple inputs onto the same horizontal line sharing the same inline identifier. |
| group | const string | No | Organizes inputs under a collapsible titled section inside the script settings dialog. |
| confirm | const bool | No | When true, prompts the user to verify input values before applying the indicator to the chart. |
| display | display.* | No | Controls whether input values appear in the status line and data window (e.g. display.all, display.none). |
Multi-Mode Strategy with Grouped Inputs
Combine group and inline parameters with dropdown choices to build polished, customizable strategy interfaces.
//@version=6
strategy("Mode Switcher Strategy [Pineify]", overlay=true, initial_capital=10000)
// Dropdown input organized with group and inline parameters
string mode = input.string(
defval="Trend Following",
title="Strategy Mode",
options=["Trend Following", "Mean Reversion", "Breakout"],
group="Execution Settings",
tooltip="Choose trading model to execute"
)
int rsi_len = input.int(14, "RSI Length", group="Indicator Settings", inline="rsi")
int rsi_ob = input.int(70, "Overbought", group="Indicator Settings", inline="rsi")
int rsi_os = input.int(30, "Oversold", group="Indicator Settings", inline="rsi")
rsi_val = ta.rsi(close, rsi_len)
fast_ema = ta.ema(close, 20)
slow_ema = ta.ema(close, 50)
highest_high = ta.highest(high, 20)[1]
bool long_condition = false
bool close_condition = false
switch 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 < ta.lowest(low, 10)[1]
if long_condition and strategy.position_size == 0
strategy.entry("Long", strategy.long)
if close_condition and strategy.position_size > 0
strategy.close("Long")Common Pitfalls with input.string Options
Avoid these common compiler errors and interface pitfalls when building dropdowns:
Default Value Mismatch
If defval is not present inside the options array (or has different letter casing), Pine Script halts compilation with an error.
✅ options=["Long", "Short", "Both"], defval="Both"
Dynamic Variables in Options
The options list must be compile-time string constants. You cannot pass calculated variables, arrays, or series strings into it.
✅ options=["AAPL", "TSLA", "NVDA"]
Always Provide a Fallback
When matching dropdown selections in a switch block, always provide a default fallback branch (=> defaultValue) to guard against unexpected states.
Informative Tooltips
Adding the tooltip parameter provides immediate guidance to users directly in the TradingView settings dialog without cluttering title labels.
Frequently Asked Questions
Essential questions about input dropdowns in Pine Script v6.
Build Complete Pine Script Strategies in Seconds
Need to create complex Pine Script indicators with custom dropdown selectors, multi-timeframe filters, and automated webhook alerts? Let Pineify AI Coding Agent generate clean, error-free Pine Script v6 code for TradingView.