Sidechair

array.reverse()

Browse the reference

Reverses the order of the items in an array, in place.

Try it in the editor

The first item becomes the last and the other way around. The array keeps its size, and there is no new array to assign.

Reversing twice restores the original order. Use it to flip a list that was built newest-last when you want to walk it newest-first.

Syntax

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

Arguments

NameTypeDefaultDescription
idany array typerequiredThe array to turn around in place. The last item becomes the first.

Returns

Nothing.

Example

Pine ScriptNewest-first view of a windowOpen in editor
//@version=6
indicator("array.reverse: newest first", overlay = true)
var win = array.new_float()
array.push(win, close)
if array.size(win) > 4
    array.shift(win)
view = array.copy(win)
array.reverse(view)
plot(array.get(view, 0), "Newest", color.blue)
plot(array.get(view, -1), "Oldest", color.gray)

See also

Runs on Sidechair