sortData (var* Data, int Length)

Sorts the Data array in ascending (Length > 0) or descending (Length < 0) order.

sortIdx (var* Data, int Length): int*

Does not affect the Data array, but returns a sorted array of the indices from the smallest to the greatest Data value.

sortPattern (var* Ranks, var* Data, int Length): int*

Stores the normalized rank of any Data element in 0..1 range in the Ranks array, for passing them to a machine learning algorithm.

findIdx (var* Data, int Length, var Value): int

Return the index of the Data element closest to Value.




Data var / double array or series to be sorted
Length Length of the Data array; negative for sorting in descending order.
Value Value to be found in the Data array.,


Temporary pointer to an int array containing the numbers of the Data values after sorting (sortIdx). The array will be overwriten by the next sortIdx call.



// Spearman trend indicator
var Spearman(var* Data,int Period)
Period = clamp(Period,2,g->nLookBack);
int* Idx = sortIdx(Data,Period);
var sum = 0; int i,n;
for(i=0,n=Period-1; i<Period; i++,n--)
sum += (n-Idx[i])*(n-Idx[i]);
return 1. - 6.*sum/(Period*(Period*Period-1.));

See also:

randomize, frechet, series, dataSort

► latest version online