Returns the largest number in an array, or the nth largest when you pass nth.
array.max(a) is the biggest value. array.max(a, 1) is the second biggest, array.max(a, 2) the third, counting from 0. Duplicates count separately, so two equal maxima give the same value for nth 0 and nth 1.
na items are skipped. If the array has no numbers, or nth is past the last ranked value, the result is na.
Syntax
array.max(id: array<int/float>, nth: series int) -> series float
array.max(id: array<int>, nth: series int) -> series int
array.max(nth: series int) -> series float
array.max(nth: series int) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | array<int/ | required | The numeric array to search. na items are skipped. |
| nth | series int | 0 | Which value to return when the numbers are ranked, starting at 0 for the first. |
Returns
series float or series int: The nth largest number, or na.
Example
//@version=6
indicator("array.max: top two", overlay = true)
var win = array.new_float()
array.push(win, close)
if array.size(win) > 20
array.shift(win)
plot(array.max(win), "Highest", color.green)
plot(array.max(win, 1), "Second highest", color.lime)See also
Runs on Sidechair