Sidechair

array.clear()

Browse the reference

Removes every item from an array, leaving it empty.

Try it in the editor

The size drops to 0 but the array itself stays valid and can be filled again. Variables that point at the same array see it empty too.

Clearing is the cheap way to reuse one var array for each new session or signal instead of creating a new array.

Syntax

Pine Script
array.clear(id: any array type) -> void
array.clear() -> void

Arguments

NameTypeDefaultDescription
idany array typerequiredThe array to empty. Its type stays; only the items are removed.

Returns

Nothing.

Remarks

Example

Pine ScriptRestart the window each dayOpen in editor
//@version=6
indicator("array.clear: daily reset", overlay = false)
var day = array.new_float()
if timeframe.change("D")
    array.clear(day)
array.push(day, close)
plot(array.size(day), "Bars today")

See also

Runs on Sidechair