Nice code. l would have never thought
about setting pkdetect and trdetect==0; in hindsight makes perfect sense.
However, the Reinsley code computes bars between PK-PK and Trough-Trough rather
than customary bars from PK-PK and Trough-Trough.
I added PK-PK and Trough-Trough and also
PK-Tr and Tr-PK computation. Furthermore a paramtoggle was added to allow for
preference toggling between the two conditions and params to adjust the text displays.
Fluffed it up a little bit.
Still missing is a Text Box displaying
some stats about the peaks and troughs: Avg PK-PK,PK-Tr,,etc, Min.Max,Median, Stand
Dev). Reinsley, any energy left?
//Additons, Changes and Corrections to
Reinsley Code;
//Peak-Peak,Trough-Trough, Peak-Trough
and Trough-Peak Count
pct = Param( "Pivot %", 5, 0.10, 60, 0.10 );
ATRPar = Param ( "ATRPar Text Shift", 0.20, 0, 30, 0.10 );
betweenfromsel = ParamToggle("Betw
Pk/Tr|FromTo Pk/Tr","Betw Pk-Pk and Tr-Tr|From Pk-Pk and Tr-Tr",1);
textoffset=Param("textoffset",0.12,0.001,1,0.001);
//textoffset=Param("textoffset",0.001,0.0001,0.02,0.0001);//Forex
pkdetect = PeakBars( C, pct )
== 0;
trdetect = TroughBars( C, pct )
== 0;
pk = PeakBars( C, pct) ;
tr = TroughBars( C, pct) ;
txtH = pk + ATRPar*ATR( 2 ); //changed to
ATRPar for descriptiveness
txtL = tr + ATRPar*ATR( 2 ); //changed to ATRPar
for descriptiveness
for ( i = 0; i < BarCount;
i++ )
{
if ( pkdetect [i]) //Peak detection
{
PlotText( "" + (pk [i-1]+betweenfromsel)
+ "
Bars(Pk-Pk)", i, H [i] + txtH[i], colorRed ); //bars
"from/between" the peaks
PlotText( "" + (tr [i]-pk
[i]-1+betweenfromsel)
+"
Bars(Tr-Pk)", i, H [i] + txtH[i]+textoffset, colorRed );//bars
"from/between" trough "to" peak
}
if ( trdetect [i]) //Trough
detection
{
PlotText( "" + (tr [i-1]+betweenfromsel)
+ "
Bars(Tr-Tr)", i, L [i] - txtL[i], colorGreen); //bars
"from/between" the troughs
PlotText( "" + (pk [i]-tr
[i]-1+betweenfromsel)
+ "
Bars(Pk-Tr)", i, L [i] - txtL[i]-textoffset, colorGreen); //bars
"from/between" peak "to" trough
}
}
zC = Zig( C, pct );
bcol = IIf( C > O, colorGreen,
IIf( C < O,
colorRed, colorBlack));
Plot( zC, "", 1, 1 | styleNoLabel
);
Plot( C, "Peak-Peak
and Trough-Trough Count", bcol, 64 );
GraphXSpace = 5;
From:
amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of reinsley
Sent: Thursday, January 01, 2009 5:41 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Looping Question for Bar Count
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;
>
>
__._,_.___
**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
*********************
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
*********************************
__,_._,___
|