array.slice() - Pine Script Function
array.slice()
Section titled “array.slice()”Overview
Section titled “Overview”The function creates a slice from an existing array. If an object from the slice changes, the changes are applied to both the new and the original arrays.
Syntax
Section titled “Syntax”array.slice(id, index_from, index_to) → array<type>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | any array type | An array object. |
Returns
Section titled “Returns”A shallow copy of an array’s slice.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("array.slice example")a = array.new_float(0)for i = 0 to 9array.push(a, close[i])// take elements from 0 to 4// *note that changes in slice also modify original arrayslice = array.slice(a, 0, 5)plot(array.sum(a) / 10)plot(array.sum(slice) / 5)