DIF:EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:EMA(DIF,9);
MACD:2*(DIF-DEA), COLORSTICK,LINETHICK2;
A1:=BARSLAST(REF(CROSS(DIF,DEA),1));
底背離:=REF(CLOSE,A1+1)>CLOSE AND DIF>REF(DIF,A1+1) AND CROSS(DIF,DEA);
STICKLINE(底背離,0,0.03,6,0),COLOR00FF00;
底背:DRAWLINE(A1=0,DEA,底背離,DEA,0),COLORRED,LINETHICK4;
DRAWTEXT(底背離,0.12,' 底背離'),COLORFF00FF;
A2:=BARSLAST(REF(CROSS(DEA,DIF),1));
頂背離:=REF(CLOSE,A2+1)<CLOSE AND REF(DIF,A2+1)>DIF AND CROSS(DEA,DIF);
頂背:DRAWLINE(A2=0,DEA,頂背離,DEA,0),COLORGREEN,LINETHICK4;
DRAWICON(CROSS(DIF,DEA),DEA,1);
DRAWICON(CROSS(DEA,DIF),DEA,2);
STICKLINE(MACD>REF(MACD,1)AND MACD>0,0,MACD,0.2,0),COLORRED;
STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,0.2,0),COLORRED;
STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,0.2,0),COLORBLUE;
STICKLINE(MACD<REF(MACD,1)AND MACD<0,0,MACD,0.2,0),COLORBLUE;
{底部結(jié)構(gòu)預(yù)警}
死叉:=CROSS(DEA,DIF);
N1:=BARSLAST(死叉),NODRAW;{最近一次死叉的位置}
N2:=REF(BARSLAST(死叉),N1+1),NODRAW;{倒數(shù)第二次死叉與倒數(shù)第一次死叉的區(qū)間}
N3:=REF(BARSLAST(死叉),N2+N1+2),NODRAW;{倒數(shù)第三次死叉與倒數(shù)第二次死叉的區(qū)間}
CL1:=LLV(C,N1+1),NODRAW;{最近一次死叉后,最低收盤價(jià)}
DIFL1:=LLV(DIF,N1+1),NODRAW;
CL2:=REF(CL1,N1+1),NODRAW;{倒數(shù)第二次死叉與倒數(shù)第一次死叉之間的最低收盤價(jià)}
DIFL2:=REF(DIFL1,N1+1),NODRAW;
CL3:=REF(CL2,N1+1),NODRAW;{倒數(shù)第三次死叉與倒數(shù)第二次死叉之間的最低收盤價(jià)}
DIFL3:=REF(DIFL2,N1+1),NODRAW;
PDIFL2:=IF(DIFL2>0,INTPART(LOG(DIFL2))-1,INTPART(LOG(-DIFL2))-1);
MDIFL2:=INTPART(DIFL2/POW(10,PDIFL2));
PDIFL3:=IF(DIFL3>0,INTPART(LOG(DIFL3))-1,INTPART(LOG(-DIFL3))-1);
MDIFL3:=INTPART(DIFL3/POW(10,PDIFL3));
MDIFB2:=INTPART(DIF/POW(10,PDIFL2));
MDIFB3:=INTPART(DIF/POW(10,PDIFL3));
直接底背離:=(CL1<CL2 ) AND (MDIFB2>MDIFL2) AND (MACD<0 AND REF(MACD,1)<0) AND MDIFB2<=REF(MDIFB2,1);
隔峰底背離:=(CL1<CL3 AND CL3<CL2 ) AND (MDIFB3>MDIFL3) AND (MACD<0 AND REF(MACD,1)<0) AND MDIFB3<=REF(MDIFB3,1);
B:直接底背離 OR 隔峰底背離,NODRAW;
BG:((MDIFB2>REF(MDIFB2,1))*REF(直接底背離,1)) OR ((MDIFB3>REF(MDIFB3,1))*REF(隔峰底背離,1)),NODRAW;
底背離消失:=(REF(直接底背離,1) AND DIFL1<=DIFL2 ) OR (REF(隔峰底背離,1) AND DIFL1<=DIFL3);
DRAWTEXT(TFILTER(B,MACD>0,1),(DIF+MACD),'鈍化'),COLORRED;
STICKLINE(B OR BG,DIF,DEA,1,0),COLORRED;
DRAWTEXT(TFILTER(底背離消失,B,1),(DIF+MACD),'消失'),COLORYELLOW;
DRAWTEXT(TFILTER(BG,MACD>0,1),DIF*1.1,'結(jié)構(gòu)形成'),COLORGREEN;
{頂部結(jié)構(gòu)預(yù)警}
金叉:=CROSS(DIF,DEA);
M1:=BARSLAST(金叉),NODRAW;{最近一次金叉的位置}
M2:=REF(BARSLAST(金叉),M1+1),NODRAW;{倒數(shù)第二次金叉與倒數(shù)第一次金叉的區(qū)間}
M3:=REF(BARSLAST(金叉),M2+M1+2),NODRAW;{倒數(shù)第三次金叉與倒數(shù)第二次金叉的區(qū)間}
CH1:=HHV(C,M1+1),NODRAW;{最近一次金叉后,最高收盤價(jià)}
DIFH1:=HHV(DIF,M1+1),NODRAW;
CH2:=REF(CH1,M1+1),NODRAW;{倒數(shù)第二次金叉與倒數(shù)第一次金叉之間的最高收盤價(jià)}
DIFH2:=REF(DIFH1,M1+1),NODRAW;
CH3:=REF(CH2,M1+1),NODRAW;{倒數(shù)第三次金叉與倒數(shù)第二次金叉之間的最高收盤價(jià)}
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);
T:直接頂背離 OR 隔峰頂背離,NODRAW;
TG:((MDIFT2<REF(MDIFT2,1))*REF(直接頂背離,1)) OR ((MDIFT3<REF(MDIFT3,1))*REF(隔峰頂背離,1)),NODRAW;
頂背離消失:=(REF(直接頂背離,1) AND DIFH1>=DIFH2 ) OR (REF(隔峰頂背離,1) AND DIFH1>=DIFH3);
DRAWTEXT(TFILTER(T,MACD<0,1),(DIF+MACD),'鈍化'),COLORGREEN;
DRAWTEXT(TFILTER(頂背離消失,T,1),(DIF+MACD),'消失'),COLORYELLOW;
STICKLINE(T OR TG,DIF,DEA,1,0),COLORGREEN;
DRAWTEXT(TFILTER(TG,MACD<0,1),DIF*1.02,'結(jié)構(gòu)形成'),COLORMAGENTA;
|