Sets every item in an array, or in a range of it, to one value.
array.fill(a, 0.0) overwrites all items with 0.0. Pass index_from and index_to to fill only the items from index_from up to, but not including, index_to.
A range that falls outside the array, or whose end is before its start, stops the script with an error that quotes the bad index.
Syntax
array.fill(id: any array type, value: series <type of the array's elements>, index_from: series int (optional), index_to: series int (optional)) -> void
array.fill(value: series <type of the array's elements>, index_from: series int (optional), index_to: series int (optional)) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any array type | required | The array to overwrite, all of it or the range chosen by index_from and index_to. |
| 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. |
| index_from | series int | 0 | Position of the first item to include. Counts from 0. |
| index_to | series int | the size of the array | Position just after the last item to include. |
Returns
Nothing.
Remarks
- Filling a drawing array with one line or label stores that single object in every slot; it does not create copies.
Example
//@version=6
indicator("array.fill: partial reset", overlay = false)
var buf = array.new_float(6, 1.0)
if bar_index % 10 == 0
array.fill(buf, 0.0, 0, 3)
array.set(buf, bar_index % 6, close)
plot(array.sum(buf), "Buffer total")See also
Runs on Sidechair