Skip to content
Algo Trade Analytics Docs

array.sort_indices() - Pine Script Function

Returns an array of indices which, when used to index the original array, will access its elements in their sorted order. It does not modify the original array.

array.sort_indices(id, order) → array<int>
NameTypeDescription
idarray<int/float/string>An array object.
//@version=6
indicator("array.sort_indices")
a = array.from(5, -2, 0, 9, 1)
sortedIndices = array.sort_indices(a) // [1, 2, 4, 0, 3]
indexOfSmallestValue = array.get(sortedIndices, 0) // 1smallestValue = array.get(a, indexOfSmallestValue) // -2
plot(smallestValue)