Skip to content
Algo Trade Analytics Docs

array.insert() - Pine Script Function

The function changes the contents of an array by adding new elements in place.

array.insert(id, index, value) → void
NameTypeDescription
idany array typeAn array object.
  • If the index is positive, the function counts forwards from the beginning of the array to the end. The index of the first element is 0, and the index of the last element is array.size() - 1. If the index is negative, the function counts backwards from the end of the array to the beginning. In this case, the index of the last element is -1, and the index of the first element is negative array.size(). For example, for an array that contains three elements, all of the following are valid arguments for the index parameter: 0, 1, 2, -1, -2, -3.
//@version=6
indicator("array.insert example")
a = array.new_float(5, close)array.insert(a, 0, open)
plot(array.get(a, 5))