Appends a value at the end of an array, so the array grows by one item.
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
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>) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any array type | required | The array that receives the new item at its end, so its size grows by one. |
| value | series <type of the array's elements> | required | The 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
//@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