sortData (var* Data, int Length)

Sorts the Data array in increasing order.

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

Does not affect the Data array, but returns a sorted array of numbers, beginning with the number of the smallest Data value and ending with the number of the greatest Data value.


Data Array or series to be sorted
Length Length of the Data array


Temporary pointer to an int array containing the numbers of the Data values sorted in increasing order (sortIdx).



// 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:

optimize, randomize, frechet, series

► latest version online