Sidechair

array.first()

Browse the reference

Returns the first item of an array without removing it.

Try it in the editor

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

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

Arguments

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

Returns

series <type>: The item at index 0.

Example

Pine ScriptOldest close in a 10-bar queueOpen in editor
//@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