Sidechair

input.string()

Browse the reference

Adds a text setting to the script, either free text or a dropdown of fixed choices.

Try it in the editor

input.string returns the text the user entered, or defval until it is changed. With options, the setting is a dropdown and the result is always one of the listed strings.

It suits mode switches such as an averaging type, written as an options list and handled with a switch statement.

Syntax

Pine Script
input.string(defval: const string, title: const string (optional), options: tuple of const string values: [val1, val2, ...] (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 string

Arguments

NameTypeDefaultDescription
defvalconst stringrequiredDefault text. With options, it should be one of them.
titleconst stringnaName shown in the Settings dialog, the legend and the Data Window.
optionstuple of const string values: [val1, val2, ...]naA list of allowed strings, written ["SMA", "EMA", "WMA"]. When given, the setting is a dropdown.
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 string: the chosen text.

Remarks

  • On Sidechair: a saved value outside options falls back to defval.
  • On Sidechair: confirm, display and active are accepted and ignored.

Example

Pine ScriptChoose the average typeOpen in editor
//@version=6
indicator("Average type", overlay = true)
kind = input.string("EMA", "Type", options = ["SMA", "EMA", "WMA"])
len = input.int(20, "Length", minval = 1)
avg = switch kind
    "SMA" => ta.sma(close, len)
    "WMA" => ta.wma(close, len)
    => ta.ema(close, len)
plot(avg, "Average", color = color.blue, linewidth = 2)

See also

Runs on Sidechair