Sidechair

array.includes()

Browse the reference

Returns true when a value occurs anywhere in an array.

Try it in the editor

The check scans the items from the start and answers as soon as it finds a match. It is a readable replacement for array.indexof(a, x) != -1.

Comparison is exact, so floats rarely match unless they came from the same calculation.

Syntax

Pine Script
array.includes(id: any array type, value: series <type of the array's elements>) -> series bool
array.includes(value: series <type of the array's elements>) -> series bool

Arguments

NameTypeDefaultDescription
idany array typerequiredThe array to look through for the value.
valueseries <type of the array's elements>requiredThe item to look for. It has to match the type of the array's items.

Returns

series bool: true when the value is present, otherwise false.

Example

Pine ScriptHighlight bars whose close was seen beforeOpen in editor
//@version=6
indicator("array.includes: repeated close", overlay = true)
var seen = array.new_float()
repeat = array.includes(seen, close)
array.push(seen, close)
if array.size(seen) > 200
    array.shift(seen)
bgcolor(repeat ? color.new(color.orange, 80) : na)
plot(close)

See also

Runs on Sidechair