Sidechair

array.new_bool()

Browse the reference

Builds an array of true and false flags, with every slot off unless a starting value says otherwise.

Try it in the editor

array.new_bool(3, false) is three flags, all off. Pass true as the second argument to start with every flag on, for example when each rule has to be switched off explicitly.

A bool is never na in v6, so an unfilled slot reads as false. The array feeds array.every() and array.some() directly, and array.includes(flags, true) asks whether any flag is on.

Syntax

Pine Script
array.new_bool(size: series int (optional), initial_value: series bool (optional)) -> array<bool>

Arguments

NameTypeDefaultDescription
sizeseries int0How many flag slots to start with: 0 or more, up to 100,000. One slot per rule or per level keeps the indexes meaningful.
initial_valueseries boolnaThe true or false written into every slot. Left out, every flag starts as false, since a bool cannot hold na.

Returns

array<bool>: A new array of true and false flags with the requested size, all false unless initial_value says true.

Example

Pine ScriptGate a signal on three rulesOpen in editor
//@version=6
indicator("array.new_bool: three-rule gate", overlay = true)
var rules = array.new_bool(3, false)
array.set(rules, 0, close > ta.sma(close, 20))
array.set(rules, 1, ta.rsi(close, 14) > 50)
array.set(rules, 2, volume > ta.sma(volume, 20))
bgcolor(array.every(rules) ? color.new(color.green, 85) : na)
plot(array.includes(rules, true) ? 1 : 0, "Any rule passes", display = display.data_window)

See also

Runs on Sidechair