Sidechair

input.bool()

Browse the reference

Adds a checkbox setting to the script and returns true or false.

Try it in the editor

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

Pine Script
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 bool

Arguments

NameTypeDefaultDescription
defvalconst boolrequiredDefault state of the checkbox.
titleconst stringnaName shown in the Settings dialog, the legend and the Data Window.
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 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

Pine ScriptSwitch a plot on and offOpen in editor
//@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