Sidechair

array.last()

Browse the reference

Returns the last item of an array without removing it.

Try it in the editor

It equals array.get(a, -1) and gives the most recent item of an array that is filled with array.push().

An empty array stops the script with an error, so test array.size(a) > 0 when the array may not have been filled yet.

Syntax

Pine Script
array.last(id: any array type) -> series <type>
array.last() -> series <type>

Arguments

NameTypeDefaultDescription
idany array typerequiredThe array to take the last item from. It must hold at least one item.

Returns

series <type>: The item at the final index.

Example

Pine ScriptPlot the latest swing highOpen in editor
//@version=6
indicator("array.last: swing high", overlay = true)
var highs = array.new_float()
ph = ta.pivothigh(high, 3, 3)
if not na(ph)
    array.push(highs, ph)
plot(array.size(highs) > 0 ? array.last(highs) : na, "Latest swing high", color.red, 2, plot.style_stepline)

See also

Runs on Sidechair