Sidechair

array.indexof()

Browse the reference

Finds the first position holding a value and returns it, or -1 when the value is not in the array.

Try it in the editor

The search runs from index 0 upward and stops at the first match. Compare the result with -1 to know whether the value was found; 0 is a valid position.

Values are compared exactly, so a float must match to the last digit.

Syntax

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

Arguments

NameTypeDefaultDescription
idany array typerequiredThe array to search from the front 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 int: The index of the first match, or -1.

Remarks

Example

Pine ScriptWhere did the highest value sitOpen in editor
//@version=6
indicator("array.indexof: peak position", overlay = false)
var win = array.new_float()
array.push(win, close)
if array.size(win) > 12
    array.shift(win)
plot(array.indexof(win, array.max(win)), "Peak position (0 = oldest)")

See also

Runs on Sidechair