Sidechair

array.min()

Browse the reference

Returns the smallest number in an array, or the nth smallest when you pass nth.

Try it in the editor

array.min(a) is the lowest value, array.min(a, 1) the next lowest, counting nth from 0. Repeated values each take a rank of their own.

Items that are na are ignored. An array without numbers, or an nth beyond the number of values, returns na.

Syntax

Pine Script
array.min(id: array<int/float>, nth: series int) -> series float
array.min(id: array<int>, nth: series int) -> series int
array.min(nth: series int) -> series float
array.min(nth: series int) -> series int

Arguments

NameTypeDefaultDescription
idarray<int/float> or array<int>requiredThe numeric array to search. na items are skipped.
nthseries int0Which value to return when the numbers are ranked, starting at 0 for the first.

Returns

series float or series int: The nth smallest number, or na.

Example

Pine ScriptLowest two lows in a windowOpen in editor
//@version=6
indicator("array.min: lowest two", overlay = true)
var lows = array.new_float()
array.push(lows, low)
if array.size(lows) > 20
    array.shift(lows)
plot(array.min(lows), "Lowest", color.red)
plot(array.min(lows, 1), "Next lowest", color.orange)

See also

Runs on Sidechair