Reverses the order of the items in an array, in place.
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
array.reverse(id: any array type) -> void
array.reverse() -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any array type | required | The array to turn around in place. The last item becomes the first. |
Returns
Nothing.
Example
//@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