Macd "One Bar Ago"

#1
This afl is good...I dont write the code.I just found it in internet.I hope everytime is use...


_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;
em_macd = EMA(zerolagMACD,5);

Plot(em_MACD,"ema",IIf(em_MACD > Ref(em_MACD,-1),colorBrightGreen,colorRed),styleThick);
Plot(zerolagMACD,"zmacd",IIf(zerolagMACD > Ref(zerolagMACD,-1),colorBrightGreen,colorRed),styleThick+styleDots);
//diff_1 = ZeroLagMACD - em_macd;
//Plot(diff_1,"hist",IIf(diff_1 > 0, colorBrightGreen, colorRed),styleHistogram);
//Plot(diff_1,"hist",IIf(diff_1 > Ref(diff_1,-1), colorBrightGreen, colorRed),styleLine);

Buy = Cover = Cross(zerolagmacd,em_macd);

Sell = Short = Cross(em_macd,zerolagmacd);
PlotShapes(Buy*shapeUpTriangle,colorYellow);
PlotShapes(Sell*shapeDownTriangle,colorYellow);
Plot(zerolagtrig,"",IIf(zerolagtrig > Ref(zerolagtrig,-1),colorAqua,colorBlue),styleDashed);

Plot(0,"",colorWhite,styleNoLabel);
a = round (zerolagMACD*100)/100;
a1 = Ref(a,-1);
diff1 = round((a - a1)*10)/10;
diff2 = round((a1 - Ref(a,-2))*10)/10;
ST33= ZeroLagMACD;
bars=50;
TR1= LLVBars(ST33,5);
COND1=TR1> 0 AND Ref(TR1,-1)==0 AND Ref(ST33,-1)<0;
TR2= IIf(COND1,Ref(ST33,-1),0);
M1= ValueWhen(COND1,ST33);
P1= ValueWhen(COND1,LLV(L,3));
DM1=M1- Ref(M1,-1);DP1=P1-Ref(P1,-1);
DT= Ref(BarsSince(COND1),-1);
POSDIV=DM1> 0 AND DP1<0 AND DT<BARS;
TR11= HHVBars(ST33,5);
COND11=TR11> 0 AND Ref(TR11,-1)==0 AND Ref(ST33,-1)>0;
TR21= IIf(COND11,Ref(ST33,-1),0);
M11= ValueWhen(COND11,ST33);
P11= ValueWhen(COND11,HHV(H,3));
DM11=M11- Ref(M11,-1);DP11=P11-Ref(P11,-1);
DT1= Ref(BarsSince(COND11),-1);
NEGDIV=DM11< 0 AND DP11>0 AND DT1<BARS;
PlotShapes(shapeDigit3*POSDIV,colorBrightGreen);
PlotShapes(shapeDigit3*NEGDIV,colorRed);


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();
 

Similar threads