Lipi Reference
Lipi

Functions

array.binary_search_rightmost()

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

Syntax

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