DIFF:EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:EMA(DIFF,9);
MACD:2* (DIFF-DEA), COLORSTICK,LINETHICK2;
Zero : 0;
A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
Bottom divergence:=REF(CLOSE,A1+1)>CLOSE AND DIFF>REF(DIFF,A1+1) AND CROSS(DIFF,DEA);
STICKLINE(bottom divergence,0, 0.03,6,0),COLOR00FF00;
Bottom divergence: DRAWLINE(A1=0,DEA,bottom divergence,DEA,0),COLORFF00FF;
DRAWTEXT(bottom divergence,- 0.2,'Bottom divergence'),COLORFF00FF;
A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));
Top divergence:=REF(CLOSE, A2+1)
Top and back: DRAWLINE(A2=0,DEA,top and back,DEA,0) ,colorgreen;
DRAWTEXT(Top divergence,DEA*1.15,'Top divergence'),colorwhite;
DRAWICON(CROSS(DIFF,DEA),DEA,'BUY');
DRAWICON(CROSS(DEA,DIFF),DEA,'SELL');