Adds a text setting to the script, either free text or a dropdown of fixed choices.
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
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 stringArguments
| Name | Type | Default | Description |
|---|---|---|---|
| defval | const string | required | Default text. With options, it should be one of them. |
| title | const string | na | Name shown in the Settings dialog, the legend and the Data Window. |
| options | tuple of const string values: [val1, val2, ...] | na | A list of allowed strings, written ["SMA", "EMA", "WMA"]. When given, the setting is a dropdown. |
| tooltip | const string | na | Text shown in a tooltip beside the input in the Settings dialog. |
| inline | const string | na | Entries sharing the same inline text sit on one row of the Settings dialog. |
| group | const string | na | Heading the input is listed under in the Settings dialog. |
| confirm | const bool | false | When true, the script asks for this value when it is first added to the chart. |
| display | const plot_display | display. | Where the value appears: a display.* constant or a combination of them. |
| active | input bool | true | When 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
//@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