array.insert() - Pine Script Function
array.insert()
Section titled “array.insert()”Overview
Section titled “Overview”The function changes the contents of an array by adding new elements in place.
Syntax
Section titled “Syntax”array.insert(id, index, value) → voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | any array type | An array object. |
Remarks
Section titled “Remarks”- 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.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("array.insert example")a = array.new_float(5, close)array.insert(a, 0, open)plot(array.get(a, 5))