Percentile
- calculate percentile

Statistical functions
(AmiBroker 4.50)


SYNTAX Percentile( array, period, rank )
RETURNS ARRAY
FUNCTION The Percentile function gives rank percentile value of the array over last period bars.

rank is 0..100 - defines percentile rank in the array

Performance note: the implementation of percentile function involves sorting that is relatively slow process even though that quicksort algorithm is used.

Since version 5.92 Percentile supports variable period.

Note that Percentile is very computation intensive function (it involves re-sorting arrays every bar) and variable-period version (if you call it with period being ARRAY) runs slower than scalar version

EXAMPLE // Example 1:
// show bars when 'current' Day Volume ranks within
// TOP 30% of volumes of last 100 bars (is above 70th Percentile)
Filter = Volume > Percentile( Volume, 100, 70 );

// Example 2:
// show bars when 'current' Day Volume ranks within
// BOTTOM 30% of volumes of last 100 bars (is below 30th percentile)
Filter = Volume < Percentile( Volume, 100, 30 );

// variable period version
bi = BarIndex();
x = Percentile( Close, bi, 50 );
Plot( x, "Cumulative 50% Percentile", colorRed );
Plot( Close, "Price", colorDefault, styleCandle );

SEE ALSO Median() function

References:

The Percentile function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.