Lipi Reference
Lipi

Functions

array.binary_search_leftmost()

Searches an array sorted in ascending order. When `value` is found, returns the index of its first occurrence; otherwise returns the index of the largest element smaller than `value`. The array must already be sorted.

Syntax

                array.binary_search_leftmost(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_leftmost Example", overlay=false)
levels = array.from(10.0, 20.0, 30.0, 40.0)
// 25 is not in the array: the result points at 20 (index 1)
plot(array.binary_search_leftmost(levels, 25.0), title="Leftmost Index", color=color.blue)