Returns the first item of an array without removing it.
It is the same as array.get(a, 0) and reads clearly in queue-style code where the oldest item sits at the front.
An empty array stops the script with an error that says index 0 is outside an array of 0 items.
Syntax
array.first(id: any array type) -> series <type>
array.first() -> series <type>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any array type | required | The array to take the first item from. It must hold at least one item. |
Returns
series <type>: The item at index 0.
Example
//@version=6
indicator("array.first: oldest close", overlay = true)
var q = array.new_float()
array.push(q, close)
if array.size(q) > 10
array.shift(q)
plot(array.first(q), "Oldest of 10", color.orange)
plot(array.last(q), "Newest", color.blue)See also
Runs on Sidechair