Lipi Reference
Lipi

Functions

array.binary_search()

Searches an array sorted in ascending order for `value` and returns its index, or -1 when it is not there. The array must already be sorted.

Syntax

                array.binary_search(series array id, series <type of the array's elements> value) → series int
              

Arguments

id required series array
value required series

Return Type

series int

Example


          //@lipi=2
indicator("array.binary_search Example", overlay=false)
levels = array.from(10.0, 20.0, 30.0, 40.0)
plot(array.binary_search(levels, 30.0), title="Index of 30 (2)", color=color.blue)