Skip to content
Algo Trade Analytics Docs

array.slice() - Pine Script Function

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.

array.slice(id, index_from, index_to) → array<type>
NameTypeDescription
idany array typeAn array object.

A shallow copy of an array’s slice.

//@version=6
indicator("array.slice example")
a = array.new_float(0)
for i = 0 to 9
array.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)