_SECTION_BEGIN("123");
z=Param("zig",0.4,0.01,3,0.01);
Plot(C,"",colorLightGrey,styleBar);
Plot( Zig(C, z), _DEFAULT_NAME(), colorYellow, styleLine );
p=Peak(C,z,1);
t=Trough(C,z,1);
Buy=Cross(C,p)AND TimeNum()>100000 ;
stop=ValueWhen(Buy,t,1);
Entry=ValueWhen(Buy,p,1);
Target=(Entry+(Entry-stop));
Sell=Cross(stop,C) OR Cross(t,C) OR Cross(C,Target) OR TimeNum()>152500 ;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
PlotShapes(shapeUpArrow*Buy,colorGreen,0, L,-5 );
PlotShapes(shapeDownArrow*Sell,colorRed,0, H,-5 );
Short=Cross(t,C)AND TimeNum()>100000;
stop1=ValueWhen(Short,p,1);
Entry1=ValueWhen(Short,t,1);
Target1=(Entry1-(stop1-Entry1));
Cover=Cross(C,stop1) OR Cross(C,p) OR Cross(Target1,C) OR TimeNum()>152500;
Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );
PlotShapes(shapeSmallUpTriangle*Cover,colorRed,0,L,-30 );
PlotShapes(shapeSmallDownTriangle*Short,colorGreen,0,H,-30 );
finalb = Flip( Buy, Sell );
finals = Flip( Short, Cover );
Plot(IIf(finalb==1,Ref(Entry,1),IIf(finals==1,Entry1,Null)),"",colorGreen,styleDashed);
Plot(IIf(finalb==1,stop,IIf(finals==1,stop1,Null)),"",colorRed,styleDashed);
Plot(IIf(finalb==1,Target,IIf(finals==1,Target1,Null)),"",colorBlue,styleDashed);
z=Param("zig",0.4,0.01,3,0.01);
Plot(C,"",colorLightGrey,styleBar);
Plot( Zig(C, z), _DEFAULT_NAME(), colorYellow, styleLine );
p=Peak(C,z,1);
t=Trough(C,z,1);
Buy=Cross(C,p)AND TimeNum()>100000 ;
stop=ValueWhen(Buy,t,1);
Entry=ValueWhen(Buy,p,1);
Target=(Entry+(Entry-stop));
Sell=Cross(stop,C) OR Cross(t,C) OR Cross(C,Target) OR TimeNum()>152500 ;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
PlotShapes(shapeUpArrow*Buy,colorGreen,0, L,-5 );
PlotShapes(shapeDownArrow*Sell,colorRed,0, H,-5 );
Short=Cross(t,C)AND TimeNum()>100000;
stop1=ValueWhen(Short,p,1);
Entry1=ValueWhen(Short,t,1);
Target1=(Entry1-(stop1-Entry1));
Cover=Cross(C,stop1) OR Cross(C,p) OR Cross(Target1,C) OR TimeNum()>152500;
Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );
PlotShapes(shapeSmallUpTriangle*Cover,colorRed,0,L,-30 );
PlotShapes(shapeSmallDownTriangle*Short,colorGreen,0,H,-30 );
finalb = Flip( Buy, Sell );
finals = Flip( Short, Cover );
Plot(IIf(finalb==1,Ref(Entry,1),IIf(finals==1,Entry1,Null)),"",colorGreen,styleDashed);
Plot(IIf(finalb==1,stop,IIf(finals==1,stop1,Null)),"",colorRed,styleDashed);
Plot(IIf(finalb==1,Target,IIf(finals==1,Target1,Null)),"",colorBlue,styleDashed);
_SECTION_END();
_SECTION_BEGIN("ZeroLag MACD");
/*Xero Lag MACD(p,q,r)*/
//based on ZeroLag EMA - see Technical Analysis of Stocks and Commodities, April 2000
p = Param("P",12,3,36,2);
q = Param("Q",26,3,52,2);
r = Param("R",9,3,15,1);
EMA1= EMA(Close,p);
EMA2= EMA(EMA1,p);
Difference= EMA1 - EMA2;
ZeroLagEMAp= EMA1 + Difference;
//---------------------------------------
EMA1= EMA(Close,q);
EMA2= EMA(EMA1,q);
Difference= EMA1 - EMA2;
ZeroLagEMAq= EMA1 + Difference;
//---------------------------------------
ZeroLagMACD=ZeroLagEMAp - ZeroLagEMAq;
//---------------------------------------
// Signal line
EMA1= EMA(ZeroLagMACD,r);
EMA2= EMA(EMA1,r);
Difference= EMA1 - EMA2;
ZeroLagTRIG= EMA1 + Difference;
Plot(zerolagMACD,"",colorRed,styleThick+styleDots);
Plot(zerolagtrig,"",colorBlue,styleDashed);
a = round (zerolagMACD*100)/100;
a1 = Ref(a,-1);
diff1 = round((a - a1)*10)/10;
diff2 = round((a1 - Ref(a,-2))*10)/10;
Title =
EncodeColor(colorYellow)+"MACD : "+ WriteIf(a > 0, EncodeColor(colorGreen)+a,EncodeColor(colorRed)+a)
+ WriteIf(diff1 > 0, EncodeColor(colorGreen)+" Up by "+diff1,EncodeColor(colorRed)+" Dn by "+diff1)
+"\n"
+EncodeColor(colorYellow)+ "One bar ago : "+ WriteIf(a1 > 0, EncodeColor(colorGreen)+a1,EncodeColor(colorRed)+a1)
+ WriteIf(diff2 > 0, EncodeColor(colorGreen)+" Up by "+diff2,EncodeColor(colorRed)+" Dn by "+diff2)
;
//===========================end zeroLagMACD
_SECTION_END();
TimeFrameSet( inDaily ); // switch now to daily
P1= Param("Daily P", 8, 3, 100,1);
mah_13D = MA( C, P1 ); // moving average from daily data
Plot( TimeFrameExpand( mah_13D, inDaily), " EMA Daily",ParamColor( "Daily EMA", colorCycle ), ParamStyle("Daily style",styleLine | styleThick| styleNoRescale));
TimeFrameRestore(); // restore time frame to original