Sidechair

array.push()

Browse the reference

Appends a value at the end of an array, so the array grows by one item.

Try it in the editor

The new item becomes the last one, at index size minus one. Existing items keep their positions. Together with array.shift() it builds a queue, and with array.pop() a stack.

The value must have the type of the array's items. Adding past 100,000 items stops the script with an error.

Syntax

Pine Script
array.push(id: any array type, value: series <type of the array's elements>) -> void
array.push(value: series <type of the array's elements>) -> void

Arguments

NameTypeDefaultDescription
idany array typerequiredThe array that receives the new item at its end, so its size grows by one.
valueseries <type of the array's elements>requiredThe item to store, or the item to look for. It has to match the type of the array's items.

Returns

Nothing.

Remarks

  • Pushing onto a var array each bar keeps a growing history; trim it with array.shift() when only the latest items matter.
  • The method form, levels.push(x), calls the same function.

Example

Pine ScriptCollect every bar's closeOpen in editor
//@version=6
indicator("array.push: all closes", overlay = false)
var closes = array.new<float>()
array.push(closes, close)
plot(array.size(closes), "Bars seen")
plot(array.max(closes), "Highest close so far")

See also

Runs on Sidechair