DIF:EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:EMA(DIF,9);
MACD:(DIF-DEA)*2,COLORSTICK;
{背离}
金叉:=CROSS(DIF,DEA);
死叉:=CROSS(DEA,DIF);
A1:=SUMBARS(金叉,2);
A2:=SUMBARS(死叉,2);
B1:=BARSLAST(DIF=LLV(DIF,A2));
B2:=BARSLAST(DIF=HHV(DIF,A1));
底背离:=REF(L,B1)>L AND DIF>REF(DIF,B1);
DRAWLINE(B1=0,DIF,底背离 AND BARSLAST(死叉)<BARSLAST(金叉) AND DIF=LLV(DIF,BARSLAST(死叉)),DIF,0),LINETHICK2,COLORMAGENTA;
顶背离:=REF(H,B2)<H AND DIF<REF(DIF,B2);
DRAWLINE(B2=0,DIF,顶背离 AND BARSLAST(死叉)>BARSLAST(金叉) AND DIF=HHV(DIF,BARSLAST(金叉)),DIF,0),LINETHICK2,COLORBLUE;