HI all
pack_Per = 30 ;
cciPer = 5 ;
levelup = 100 ;
leveldn = -100 ;
Zig_pram = Param ( " A_W" , cciPer , 2 , 50 , 1 ) ;
// using fxShart cci loop code for test ( link )
/// https://forum.amibroker.com/t/help-with-calculation-of-cci-using-loops/25087/10?u=needhelp
tp = Avg; // (High+Low+Close)/3;
cciMA = MA( tp, cciPer);
for ( j = 0, zum = 0; j < cciPer; j++) {
zum += abs(cciMA - Ref(tp,-j));
}
md2 = zum / cciPer;
cciLp = (tp - cciMA) / (.015 * md2);
fff= cciLp ;
cciLp_bar= Prec ( fff , 2 ) != Ref ( Prec ( fff , 2 ) ,-1 );
Total_cciLp_bars = Cum ( cciLp_bar ) ;
ttt = Zig ( cciLp , Zig_pram ) ;
function NthHV( array, period, nth ) {
return Percentile( array, period, (period-nth) / (period-1) * 100 );
}
////////// BarsSince (NthHV (cciLp, period, nth=2 ) ) > Ref ( cciLp , - 1)
//ValueWhen(is_almost_there, C)
Period = 30;
vale_a = BarsSince ( cciLp == HHV(cciLp, Period) ) ;
vale_b = BarsSince ( cciLp == NthHV(cciLp, period, nth=2 ) ) ;
vale_c = BarsSince ( cciLp == NthHV(cciLp, period, nth=3 ) ) ;
vale_d = BarsSince ( cciLp == NthHV(cciLp, period, nth=4 ) ) ;
vale_e = BarsSince ( cciLp == NthHV(cciLp, period, nth=5 ) ) ;
bi = BarIndex();
NthHighest_H1 = IIf ( cciLp > levelup AND cciLp > Ref ( cciLp , - 1) , HHV(cciLp, Period) , 0 ) ;
NthHighest_H2 = IIf ( cciLp > levelup AND cciLp > Ref ( cciLp , - 1) , NthHV(cciLp, period, nth=2 ) , 0 ) ;
NthHighest_H3 = IIf ( cciLp > levelup AND cciLp > Ref ( cciLp , - 1) , NthHV(cciLp, period, nth=3 ) , 0 ) ;
NthHighest_H4 = IIf ( cciLp > levelup AND cciLp > Ref ( cciLp , - 1) , NthHV(cciLp, period, nth=4 ) , 0 ) ;
NthHighest_H5 = IIf ( cciLp > levelup AND cciLp > Ref ( cciLp , - 1) , NthHV(cciLp, period, nth=5 ) , 0 ) ;
Plot(cciLp,"cciLp",colorBlack,styleLine);
Plot(ttt,"ttt",colorBlack,styleLine);
Filter = 1 ;
AddColumn( NthHighest_H2 , "NthHighest_H2 " , 1.2 ) ;
AddColumn( vale_b , "vale_b" , 1.2 ) ;
AddColumn( NthHighest_H3 , "NthHighest_H3 " , 1.2 ) ;
AddColumn( vale_c , "vale_c" , 1.2 ) ;
AddColumn( NthHighest_H4 , "NthHighest_H4" , 1.2 ) ;
AddColumn( vale_d , "vale_d" , 1.2 ) ;
AddColumn( NthHighest_H5 , "NthHighest_H5 " , 1.2 ) ;
AddColumn( vale_e , "vale_e" , 1.2 ) ;
how to use BarsSince() with nth ?
thank you