PureBytes Links
Trading Reference Links
|
Thanks Reinsley - I worked with what you provided and was able to get
HH - LL and H-L bar counts. I see someone else has expanded the code
so I am adding to their improvements. Now I am trying to figure out
how to calculate the percentage price change between pk and tr. The
final part will be to properly place the text labels so they do not
stack on top of each other.
Thanks again for your code savvy.
David K.
//Addition Price Selection (H, L, C,or pk H and tr L)
//added Pivot Prices
//Additons, Changes and Corrections to Reinsley Code;
//Peak-Peak,Trough-Trough, Peak-Trough and Trough-Peak Count
Price = ParamList("Price to follow:", "Close|High|Low|zHiLo", 3);
pct = Param( "Pivot %", 5, 0.10, 60, 0.10 );
ATRPar = Param ( "ATRPar Text Shift", 0.20, 0, 30, 0.10 );
ppr = ParamToggle("Pivot Price Labels","Off|On",0);
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,5,0.001);
//textoffset=Param("textoffset",0.001,0.0001,0.02,0.0001);//Forex
////////////////////
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)));
////////////////////
if(Price=="Close") P=Zig(C,pct);
else if(Price=="High")P=Zig(H,pct);
else if(Price=="Low") P=Zig(L,pct);
else P=Zig(zp,pct);
pR=Ref(P,-1)<P AND P>Ref(P,1);
pS=Ref(P,-1)>P AND P<Ref(P,1);
////////////////////////////////////////////////
pkdetect = PeakBars(P, pct) == 0;
trdetect = TroughBars(P, pct) == 0;
pk = PeakBars(P, pct) ;
tr = TroughBars(P, 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
}
if(ppr==1)
{
if(pR [i]) PlotText("" + H [i] + " Hi", i, H [i] + txtH[i]-
textoffset, colorRed);
if(pS [i]) PlotText("" + L [i] + " Lo", i, L [i] - txtL[i]
+textoffset, colorGreen);
}
}
zC = Zig(P, pct);
bcol = IIf( C > O, colorGreen, IIf( C < O, colorRed, colorBlack));
Plot( zC, "", 2, 1 | styleNoLabel );
Plot( C, "Peak-Peak and Trough-Trough Count", bcol, 64 );
GraphXSpace = 5;
--- In amibroker@xxxxxxxxxxxxxxx, reinsley <reinsley@xxx> wrote:
>
> 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
*********************************
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|