Hello,

Adapted from your code. The count is from peak to peak and from trough 
to trough.
You can easily adapt to see from peak to trough and reverse.
Hope this helps.

Best regards



//Bar count Pk To Pk and Tr to Tr

pct = Param( "Pivot %", 0.1, 0.10, 60, 0.10 );
vs = Param ( "Pivot $ V Shift", 1.50, 0, 30, 0.10 );

pkdetect = PeakBars( C, pct ) == 0;
trdetect = TroughBars( C, pct ) == 0;

pk = PeakBars( C, pct ) ;
tr = TroughBars( C, pct ) ;

txtH = pk + vs * ATR( 2 );
txtL = tr + vs * ATR( 2 );

for ( i = 0; i < BarCount; i++ )
{
    if ( pkdetect [i] )
        PlotText( "" + pk [i-1] + " Bars", i, H [i] + txtH[i], 25 );

    if ( trdetect [i] )
        PlotText( "" + tr [i-1] + " Bars", i, L [i] - txtL[i], 42 );
}

zC = Zig( C, pct );

bcol = IIf( C > O, colorGreen, IIf( C < O, colorRed, colorWhite ) );
Plot( C, "", bcol, 128 );
Plot( zC, "", 45, 1 | styleNoLabel );

GraphXSpace = 15;


wooziwog a écrit :
>
> I am trying to label the barcounts between each peak and trough using
> a loop. The problem I have is that the most recent bar count between
> the peak and trough appears as the bar count between all peaks and
> troughs. I have tried a number of ways to fix the problem but have
> not had any success. Any help in solving this puzzle will be greatly
> appreciated.
>
> Thanks,
>
> David K.
>
> ///Bar Count
>
> bi = SelectedValue(BarIndex());
> sbi = BarIndex();
> x1=BarCount-1;
> bcol=IIf(C>O,colorLime,IIf(C<O,colorRed,colorWhite));
> Plot(C,"",bcol,128);
> dec = (Param("Decimals",2,0,7,1)/10)+1;
> ////////////////////
> _SECTION_BEGIN("Bar Count");
> pct=Param("Pivot %",0.80,0.10,60,0.10);
> Zigl = ParamToggle("Zig Line","Off|On",1);
> hLb=Param("High Look Back",1,1,30,1);
> lLb=Param("Low Look Back",1,1,30,1);
> vs = Param ("Pivot $ V Shift",1.50,0,30,0.10);
> ////////////////////
> SetBarsRequired( 999999,999999);
> pk=PeakBars(H,pct)==0; tr=TroughBars(L,pct)==0;
> zHi=Zig(H,pct); zLo=Zig(L,pct); HLAvg=(zHi+zLo)/2;
> zp=IIf(pk,zHi,IIf(tr,zLo,IIf(HLAvg>Ref(HLAvg,-1),H,L)));
> za=Zig(zp,pct);
> if(Zigl==1)Plot(za,"",45,1|styleNoLabel);
> ////////////////////
> SetBarsRequired( 999999,999999);
> pk=PeakBars(H,pct)==0;
> tr=TroughBars(L,pct)==0;
> zH=Zig(H,pct); zL=Zig(L,pct); HLAvg=(zH+zL)/2;
> zp=IIf(pk,zH,IIf(tr,zL,IIf(HLAvg>Ref(HLAvg,-1),H,L)));
> za=Zig(zp,pct);
> ////////////////////
> if(Zigl==1)Plot(za,"",45,1|styleNoLabel);
> PlotShapes(shapeDownArrow*pk,colorBrightGreen,0,H,-15);
> PlotShapes(shapeUpArrow*tr,colorYellow,0,L,-15);
> ////////////////////
> pR=Ref(za,-1)<za AND za>Ref(za,1);
> xr0=SelectedValue(ValueWhen(pR,sbi,hLb));
> yr0=SelectedValue(ValueWhen(pR,zp,hLb));
> ////////////////////
> pS=Ref(za,-1)>za AND za<Ref(za,1);
> xs0=SelectedValue(ValueWhen(pS,sbi,lLb));
> ys0=SelectedValue(ValueWhen(pS,zp,lLb));
> ////////////////////
> bcount = abs(xr0-xs0);
> bc=LastValue(bcount,1);
> txtH = pk + vs*ATR(2);
> txtL = tr + vs*ATR(2);
> ////////////////////
> for( i = 0; i < BarCount; i++ )
> {
> if(pR [i]) PlotText("" + bc[i] +" Bars", i, H [i] + txtH[i], 25);
> if(pS [i]) PlotText("" + bc[i] +" Bars", i, L [i] - txtL[i], 42);
> }
> _SECTION_END();
>
> Title = EncodeColor(55)+ Title = Name() + " " + EncodeColor(55)
> + Date() + " " + EncodeColor(3) + "{{INTERVAL}} " +
> EncodeColor(55)+ " Open = "+ EncodeColor(10)+ NumToStr(O,dec) +
> EncodeColor(55)+ " High = "+ EncodeColor(43)+ NumToStr(H,dec) +
> EncodeColor(55)+ " Low = "+ EncodeColor(32)+ NumToStr(L,dec) +
> EncodeColor(55)+ " Close = "+ EncodeColor(55)+ NumToStr(L,dec) +
> EncodeColor(55)+ " xs0 = "+ EncodeColor(43)+ NumToStr(xs0,1.0) +
> EncodeColor(32)+ " xr0 = "+ EncodeColor(32)+ NumToStr(xr0,1.0) +
> EncodeColor(55)+ " ys0 = "+ EncodeColor(43) + NumToStr(ys0,1.2) +
> EncodeColor(32)+ " yr0 = "+ EncodeColor(32)+ NumToStr(yr0,1.2);
> GraphXSpace=10;
>
>  


Reply via email to