Returns the last item of an array without removing it.
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
array.last(id: any array type) -> series <type>
array.last() -> series <type>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any array type | required | The array to take the last item from. It must hold at least one item. |
Returns
series <type>: The item at the final index.
Example
//@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