array.sort_indices() - Pine Script Function
array.sort_indices()
Section titled “array.sort_indices()”Overview
Section titled “Overview”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.
Syntax
Section titled “Syntax”array.sort_indices(id, order) → array<int>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | array<int/float/string> | An array object. |
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("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) // -2plot(smallestValue)