Find Close of previous HHV

hi all, need your help to find "Close of previous HHV", the result of Close2 is wrong. Here is my code

function NthHV( array, period, nth ) {
return Percentile( array, period, (period-nth) / (period-1) * 100 );
}

criteria = C>O;
vol1 = IIf(criteria,V,0);
volhigh1 = HHV(vol1,5);
close1 = nthHV(C,5,nth=1);

volhigh2 = Ref(HHV(vol1,5),-5);
close2 = nthHV(C,5,nth=2);

Filter = 1;

AddColumn(volhigh1,"volhigh1");
AddColumn(close1,"close1");
AddColumn(volhigh2,"volhigh2");
AddColumn(close2,"close2");

@gani,

You need to get "Verified Badge" before you can ask questions.

Also see,