Thanks Progster - I have just started working with looping and I have your information provides a important building block. I know how to identify pivots but my question is how do I reference the price of the past trough when a new peak is reached or vice versa? It seems it should be simple but I am struggling with it. Any help is appreciated.
TIA, David K. --- In [email protected], "progster01" <progs...@...> wrote: > > David, > > SelectedValue returns a Number. > > So, xr0 and xs0 are Numbers. > > When Abs() operates on a Number, it returns a Number. > > Hence > > bc = abs(xr0-xs0); > > is a Number. > > When you plot: > > 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); > } > > bc[i] is constant, as you see on the chart. > > I'm not sure why bc[i] is an acceptable expression when bc is a > Number, but I imagine there is some reason for it. > > Anyway, I think that's why you are not seeing the bar counts you are > aiming for. > > - Progster > > --- In [email protected], "wooziwog" <xcitemint@> wrote: > > > > Barry, > > > > I have changed from "Last Value" to simply subtracting the bar index > > count at xR0 and xS0. Does this not provide the barcount? Even > > though I have not used "Last Value" the same bar count appears at all > > Peak and Trough pivots. What am I missing? > > > > Thanks, > > > > David K. > > > > Changes made to remove LastValue > > bc = abs(xr0-xs0);//Changed to calculate BarIndex difference > > //bc=LastValue(bcount,1);//Removed to use current value > > > > > > 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)); > > //////////////////// > > bc = abs(xr0-xs0);//Changed to calculate BarIndex difference > > //bc=LastValue(bcount,1);//Removed to use current value > > 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; > > >
