dif:100*(Ema(CLOSE,12)-ema(CLOSE,26)),COLORRED,LINETHICK1;
DEA:EMA(DIF,9),COLORBLUE,LINETHICK1;
MacD:(DIF-DEA)*2,COLORSTICK;
金叉:=crOSS(DIF,DEA);
M1:=BArslAST(金叉),NODRAW;
M2:=REF(BARSLAST(金叉),M1+1),NODRAW;
M3:=REF(BARSLAST(金叉),M2+M1+2),NODRAW;
CH1:=HHV(C,M1+1),NODRAW;
DIFH1:=HHV(DIF,M1+1),NODRAW;
CH2:=REF(CH1,M1+1),NODRAW;
DIFH2:=REF(DIFH1,M1+1),NODRAW;
CH3:=REF(CH2,M1+1),NODRAW;
DIFH3:=REF(DIFH2,M1+1),NODRAW;
pdiFH2:=IF(DIFH2>0,INTPART(LOG(DIFH2))-1,INTPART(LOG(-DIFH2))-1);
mdiFH2:=INTPART(DIFH2/POW(10,PDIFH2));
PDIFH3:=IF(DIFH3>0,INTPART(LOG(DIFH3))-1,INTPART(LOG(-DIFH3))-1);
MDIFH3:=INTPART(DIFH3/POW(10,PDIFH3));
MDIFT2:=INTPART(DIF/POW(10,PDIFH2));
MDIFT3:=INTPART(DIF/POW(10,PDIFH3));
直接顶背离:=(CH1>CH2 ) AND (MDIFT2<MDIFH2) AND (macd>0 AND REF(MACD,1)>0) AND MDIFT2>=REF(MDIFT2,1);
隔峰顶背离:=(CH1>CH3 AND CH3>CH2 ) AND (MDIFT3<MDIFH3) AND (MACD>0 AND REF(MACD,1)>0) AND MDIFT3>=REF(MDIFT3,1);
顶部钝化:直接顶背离 OR 隔峰顶背离,NODRAW;
顶背离:((MDIFT2<REF(MDIFT2,1))*REF(直接顶背离,1)) OR ((MDIFT3<REF(MDIFT3,1))*REF(隔峰顶背离,1)),NODRAW;
STICKLINE(顶部钝化,DIF,DEA,1,0),COLORCYAN;
DRAWTEXT(TFILTER(顶背离,C>REF(CH1,1),1),DIF*1.12,'结构形成'),COLORCYAN;
DRAWICON(CROSS(DIF,DEA),DEA,36);
DRAWICON(CROSS(DEA,DIF),DEA,37);
MACddiF:=IF(Abs(MACD)>ABS(DIF),MACD,DIF);
DRAWICON(REF(DIF,1)>REF(DIF,2) AND DIF<REF(DIF,1) AND DIF>0 AND DIF>DEA,MACDDIF*1.1,39),COLORCYAN;
DRAWICON(REF(DIF,1)<REF(DIF,2) AND DIF>REF(DIF,1) AND DIF<0 AND DIF<DEA,MACDDIF*1.1,38),COLORWHITE;