ch=Param("% change",0.25,0.25,2,0.01);
zz=Zig(C,Ch);
az=C;
Plot(ZZ," ", 2,32|styleNoLabel);
Buy_valid=Sell_valid=0;
percentchange=Optimize("Pk-Tr Conf %",Param("P-T Conf %",0.5,0.3,4,0.1),0.3,4,0.1);
PivotHigh = Ref(IIf(Ref(ROC(ZZ,1),-1) > 0 AND ROC(ZZ,1) < 0, 1, 0),1);
PivotLow = Ref(IIf(Ref(ROC(ZZ,1),-1) < 0 AND ROC(ZZ,1) > 0, 1, 0),1);
Buy_Valid = IIf(az>(1+(LastValue(PercentChange)/100))*(ValueWhen(PivotLow, az, 1)) AND ROC(ZZ,1) > 0,1,0);
Sell_Valid = IIf(az<(1-(LastValue(PercentChange)/100))*(ValueWhen(PivotHigh, az, 1)) AND ROC(ZZ,1) < 0,1,0);
Buy_Valid = ExRem(Buy_Valid,Sell_Valid);
Sell_Valid = ExRem(Sell_Valid,Buy_Valid);
Candlecol=IIf(BarsSince(Buy_Valid)<BarsSince(Sell_Valid) AND BarsSince(Buy_Valid)!=0,5,
IIf(BarsSince(Buy_Valid)>BarsSince(Sell_Valid) AND BarsSince(Sell_Valid)!=0,4,1));
cc1=IIf(Buy_valid,colorYellow,IIf(Sell_valid,colorBlack,Candlecol));
SetBarFillColor(Cc1);
Plot(C,"cas-zig-VW_Pri [ "+ch+" ]",cc1,64,0,0,0,0);
pk=Zz>Ref(zz,-1);
tr=Zz<Ref(zz,-1);
z=Cum(1);
BLa = ValueWhen( pk, z, 1);
BLb = ValueWhen( pk,High, 1 );
SLa = ValueWhen( tr, z, 1 );
SLb = ValueWhen( tr, Low, 1 );
Plot(IIf(z>BLa,BLb,Null),"",31,1);
Plot(IIf(z>SLa,SLb,Null),"",31,1);
strWeekday = StrMid("SunMonTueWedThuFriSat", SelectedValue(DayOfWeek())*3,3);
Title = EncodeColor(colorWhite)+ "Valid Zz : " + EncodeColor(colorTan)+
"[ Zig % "+ch+" ]" +" "+ "[ Pk-Tr Conf % "+percentchange+" ]"+ EncodeColor(colorGold)+
"\n"+ Name() + " - " + EncodeColor(colorAqua)+ Interval(2) + EncodeColor(colorWhite) +
" #"+strWeekday +" , "+ Date()+ "\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorPaleGreen)+WriteIf(Buy_valid, "Bottom confirmed :"+(SLb),"")+
EncodeColor(colorLightOrange)+WriteIf(Sell_valid, "Peak confirmed :"+(BLb),"");
GfxSetOverlayMode(0);GfxSetTextColor(10);
GfxSelectFont("Old English Text MT", 12, 300, False, False, 0);
GfxTextOut(" Casoni ", Status("pxwidth")-60 , Status("pxheight")-20 );