Replaces the item at a position in an array with a new value.
array.set(levels, 0, close) overwrites the first item. A negative index counts back from the end in v6, so array.set(levels, -1, close) changes the last item.
The index must point at an item that exists; set cannot grow an array. Use array.push() or array.insert() to add items.
Syntax
array.set(id: any array type, index: series int, value: series <type of the array's elements>) -> void
array.set(index: series int, value: series <type of the array's elements>) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any array type | required | The array to write into. Only the item at the chosen index is replaced. |
| index | series int | required | Position of the item. Counts from 0; a negative index counts back from the end, so -1 is the last item. |
| 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
- The value must have the type of the array's items.
- The method form, levels.set(i, x), calls the same function.
Example
//@version=6
indicator("array.set: running extremes", overlay = true)
var ext = array.from(0.0, 0.0)
if bar_index == 0
array.set(ext, 0, low)
array.set(ext, 1, high)
array.set(ext, 0, math.min(array.get(ext, 0), low))
array.set(ext, 1, math.max(array.get(ext, 1), high))
plot(array.get(ext, 0), "Lowest low", color.red)
plot(array.get(ext, 1), "Highest high", color.green)See also
Runs on Sidechair