Skip to content

bool() - Pine Script Function

bool() casts a value to the boolean type. It returns false when the value is na, false, an empty string, or a numeric value equal to 0; any other value becomes true. Use it when you need to convert user input or numeric results to flags for control flow.

bool(x) → const bool
NameTypeDescription
xsimple int/float/bool/stringValue to convert to boolean.

const bool — result of the cast.

  • Strings convert to false if they are empty (""), otherwise true.
  • Casting arrays/objects is not supported; use boolean expressions instead.
  • When working with user inputs (input.bool, input.int, etc.), values are already the correct type—casting is only needed when you consume a generic source (e.g., CSV data).
//@version=5
indicator("bool() example", overlay=false)
floatVal = input.float(0.0, "Float value", step=0.5)
strVal = input.string("", "String value")
isFloatTrue = bool(floatVal)
isStringTrue = bool(strVal)
plot(int(isFloatTrue), "Float cast", color=color.blue)
plot(int(isStringTrue), "String cast", color=color.orange)
label.new(bar_index, close,
text = "bool(float)=" + str.tostring(isFloatTrue) + "\nbool(string)=" + str.tostring(isStringTrue),
style=label.style_label_left,
textcolor=color.white,
bgcolor=color.new(color.blue, 70))