Function of Nth highest function in AFL

  1. Your code is wrong as it returns wrong values (see table below).
  2. And yes, there is simpler way by just using Percentile function outputting correct values
function NthHV( array, period, nth ) {
    return Percentile( array, period, (period-nth) / (period-1) * 100 );
}

Period = 30;
HighestValue = HHV(H, Period);
NthHighest = NthHV(H, period, nth=2 );

Filter = 1;
format = 1.2;
AddColumn(H, "High", format );
AddColumn(HighestValue, "HighestValue", format );
AddColumn(NthHighest, "NthHighestValue("+nth+")", format );

16 Likes