Adds a checkbox setting to the script and returns true or false.
input.bool shows a checkbox in the settings, labelled with title. It returns true when it is ticked and false when it is not, starting at defval.
Use it to switch features on and off, for example a plot, a label or an alternate calculation. Because the value is fixed for the whole run, it works as a plain condition: plot(show ? x : na).
Syntax
input.bool(defval: const bool, title: const string (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 boolArguments
| Name | Type | Default | Description |
|---|---|---|---|
| defval | const bool | required | Default state of the checkbox. |
| title | const string | na | Name shown in the Settings dialog, the legend and the Data Window. |
| 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 bool: true when the box is ticked, otherwise false.
Remarks
- On Sidechair: a saved value that is not a bool falls back to defval.
- On Sidechair: confirm, display and active are accepted and ignored.
Example
//@version=6
indicator("Toggle", overlay = true)
showSlow = input.bool(true, "Show slow average")
plot(ta.sma(close, 10), "Fast", color = color.green)
plot(showSlow ? ta.sma(close, 40) : na, "Slow", color = color.red)See also
Runs on Sidechair