DIF:= EMA(CLOSE,S) - EMA(CLOSE,P);
DEA:= EMA(DIF,M);
MACD:= 2*(DIF-DEA), COLORSTICK;
A1:=CROSS(MACD,0) AND DIF<0 AND DEA<0;
B1:=CROSS(0,MACD) AND DIF>0 AND DEA>0;
N1:=BARSLAST(B1);
N2:=LLVBARS(L,N1);
C1:=BACKSET(A1,N2+1);
F1:=C1>REF(C1,1);
N3:=BARSLAST(A1);
N4:=HHVBARS(H,N3);
D1:=BACKSET(B1,N4+1);
F2:=D1>REF(D1,1);
E1:=BARSLAST(F2);
E2:=BARSLAST(F1);
G1:=FILTERX(F1,E1);
G2:=FILTERX(F2,E2);
DRAWLINE(G1,L,G2,H,0),COLORGREEN,LINETHICK2;
DRAWLINE(G2,H,G1,L,0),COLORGREEN,LINETHICK2;