Sidechair

array.fill()

Browse the reference

Sets every item in an array, or in a range of it, to one value.

Try it in the editor

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

Pine Script
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)) -> void

Arguments

NameTypeDefaultDescription
idany array typerequiredThe array to overwrite, all of it or the range chosen by index_from and index_to.
valueseries <type of the array's elements>requiredThe item to store, or the item to look for. It has to match the type of the array's items.
index_fromseries int0Position of the first item to include. Counts from 0.
index_toseries intthe size of the arrayPosition 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

Pine ScriptReset the first half of a bufferOpen in editor
//@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