Returns true when a value occurs anywhere in an array.
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
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 boolArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any array type | required | The array to look through for the value. |
| value | series <type of the array's elements> | required | The 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
//@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