注意:本指标源码用于文华财经赢顺wh6、睿期wh7软件。目录8 MACD新高低背离9 MACD均线背离10 MACD结构背离11 特殊MACD背离12 MACD连线背离08MACD新高低背离M:=20;DIFF:EMA(CLOSE,12) - EMA(CLOSE,26);DEA :EMA(DIFF,9),COLORGREEN;MACD:2*(DIFF-DEA), COLORSTICK;AA2000:=CLOSE>REF(HHV(HIGH,M),1) AND MACD<REF(HHV(MACD,M),1) ;BB2000:=CLOSE<REF(LLV(LOW,M),1) AND MACD>REF(LLV(MACD,M),1) ;DRAWTEXT(AA2000,MACD,'▲顶背离'),COLORYELLOW;DRAWTEXT(BB2000,MACD,'▼低背离'),COLORGREEN;09MACD均线背离DIF:EMA(CLOSE,12)-EMA(CLOSE,26),COLORWHITE;DEA:EMA(DIF,9),COLORYELLOW;MACD:(DIF-DEA)*2,COLORSTICK;A1:=BARSLAST(REF(CROSS(DEA,DIF),1));A2:=BARSLAST(REF(CROSS(DIF,DEA),1));DD2022:=HHV(MA(C,2),9)>REF(HHV(MA(C,2),9),A1) AND HHV(DIF,5)<REF(HHV(DIF,5),A1) AND CROSS(DEA,DIF);KK2022:=LLV(MA(C,2),9)<REF(LLV(MA(C,2),9),A2) AND LLV(DIF,5)>REF(LLV(DIF,5),A2) AND CROSS(DIF,DEA);DRAWTEXT(DD2022,DEA+0.1,'顶背离'),COLORGREEN ;DRAWTEXT(KK2022,DEA-0.1,'底背离'),COLORYELLOW;DRAWICON(CROSS(DEA,DIF),DEA,5);DRAWICON(CROSS(DIF,DEA),DEA,4);10MACD结构背离DIF:100*(EMA(CLOSE,12)-EMA(CLOSE,26));DEA:EMA(DIF,9);MACD:(DIF-DEA)*2,COLORSTICK;KKK2022:=CROSS(DEA,DIF);N1:=BARSLAST(KKK2022),NODRAW;N2:=REF(BARSLAST(KKK2022),N1+1),NODRAW;N3:=REF(BARSLAST(KKK2022),N2+N1+2),NODRAW;CL1:=LLV(C,N1+1),NODRAW;DIFL1:=LLV(DIF,N1+1),NODRAW;CL2:=REF(CL1,N1+1),NODRAW;DIFL2:=REF(DIFL1,N1+1),NODRAW;CL3:=REF(CL2,N1+1),NODRAW;DIFL3:=REF(DIFL2,N1+1),NODRAW;PDIFL2:=IF(DIFL2>0,INTPART(LOG(DIFL2,10))-1,INTPART(LOG(-(DIFL2),10))-1);MDIFL2:=INTPART(DIFL2/POW(10,PDIFL2));PDIFL3:=IF(DIFL3>0,INTPART(LOG(DIFL3,10))-1,INTPART(LOG(-(DIFL3),10))-1);MDIFL3:=INTPART(DIFL3/POW(10,PDIFL3));MDIFB2:=INTPART(DIF/POW(10,PDIFL2));MDIFB3:=INTPART(DIF/POW(10,PDIFL3));ZJDBL26:=(CL1<CL2 ) AND (MDIFB2>MDIFL2) AND (MACD<0 AND REF(MACD,1)<0) AND MDIFB2<=REF(MDIFB2,1);GFDBL26:=(CL1<CL3 AND CL3<CL2 ) AND (MDIFB3>MDIFL3) AND (MACD<0 AND REF(MACD,1)<0) AND MDIFB3<=REF(MDIFB3,1);B:ZJDBL26 OR GFDBL26,NODRAW;BG:((MDIFB2>REF(MDIFB2,1))*REF(ZJDBL26,1)) OR ((MDIFB3>REF(MDIFB3,1))*REF(GFDBL26,1)),NODRAW;DBJLX03:=(REF(ZJDBL26,1) AND DIFL1<=DIFL2 ) OR (REF(GFDBL26,1) AND DIFL1<=DIFL3);TT1:=BARSLAST(MACD>0);DRAWTEXT(COUNT(B,TT1)=1 AND NOT(REF(COUNT(B,TT1)=1 ,1)),(DIF+MACD),'钝化'),COLORRED;STICKLINE1(B OR BG,DIF,DEA,1,0),COLORRED;TT2:=BARSLAST(B);DRAWTEXT(DBJLX03,(MACD),'消失'),COLORYELLOW;TT3:=BARSLAST(MACD>0);DRAWTEXT(COUNT(BG,TT3)=1 AND NOT(REF(COUNT(BG,TT3)=1,1)),DIF*1.1,'结构形成'),COLORMAGENTA;DDJ2022:=CROSS(DIF,DEA);M1:=BARSLAST(DDJ2022),NODRAW;M2:=REF(BARSLAST(DDJ2022),M1+1),NODRAW;M3:=REF(BARSLAST(DDJ2022),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,10))-1,INTPART(LOG(-(DIFH2),10))-1);MDIFH2:=INTPART(DIFH2/POW(10,PDIFH2));PDIFH3:=IF(DIFH3>0,INTPART(LOG(DIFH3,10))-1,INTPART(LOG(-(DIFH3),10))-1);MDIFH3:=INTPART(DIFH3/POW(10,PDIFH3));MDIFT2:=INTPART(DIF/POW(10,PDIFH2));MDIFT3:=INTPART(DIF/POW(10,PDIFH3));JLDBL26:=(CH1>CH2 ) AND (MDIFT2<MDIFH2) AND (MACD>0 AND REF(MACD,1)>0) AND MDIFT2>=REF(MDIFT2,1);PHDBL26:=(CH1>CH3 AND CH3>CH2 ) AND (MDIFT3<MDIFH3) AND (MACD>0 AND REF(MACD,1)>0) AND MDIFT3>=REF(MDIFT3,1);T:JLDBL26 OR PHDBL26,NODRAW;TG:((MDIFT2<REF(MDIFT2,1))*REF(JLDBL26,1)) OR ((MDIFT3<REF(MDIFT3,1))*REF(PHDBL26,1)),NODRAW;XSDBL26:=(REF(JLDBL26,1) AND DIFH1>=DIFH2 ) OR (REF(PHDBL26,1) AND DIFH1>=DIFH3);TT4:=BARSLAST(MACD<0);DRAWTEXT(COUNT(T,TT4)=1 AND REF(COUNT(T,TT4),1)<1,(DIF+MACD),'钝化'),COLORGREEN;TT5:=BARSLAST(T);DRAWTEXT(XSDBL26,(MACD),'消失'),COLORYELLOW;STICKLINE1(T OR TG,DIF,DEA,1,0),COLORGREEN;DRAWTEXT(COUNT(TG,TT4)=1 AND REF(COUNT(TG,TT4),1)<1,DIF*1.02,'结构形成'),COLORMAGENTA;DDBL22:JLDBL26 OR PHDBL26,NODRAW,COLORGREEN;DBBL22:ZJDBL26 OR GFDBL26,NODRAW,COLORYELLOW;DRAWTEXT(DDBL22,0,'顶背'),COLORGREEN;DRAWTEXT(DBBL22,0,'底背'),COLORGREEN;11特殊MACD背离DIFF4:EMA(CLOSE,12) - EMA(CLOSE,26),COLORBFFF10;DEA4 :EMA(DIFF4,9);IF(DIFF4>DEA4 AND DIFF4<0,DIFF4,NULL),COLORBFA4D9,LINETHICK2;IF(DIFF4>DEA4 AND DIFF4>0,DIFF4,NULL),COLORRED,LINETHICK2;IF(DEA4<0,DEA4,NULL),COLORBLUE,LINETHICK2;MACD : 2*(DIFF4-DEA4), COLORSTICK;MA1:=REF(MACD,1),POINTDOT,COLORGRAY;STICKLINE1(DEA4>0 AND MACD<MA1 AND MACD>=0,0,MACD,1,1),COLORBFA4D9;STICKLINE1(DEA4<0 AND MACD>=MA1 AND MACD<0,0,MACD,1,1),COLORBFFF10;MN:=BARSLAST(CROSS(DEA4,0))+1;SN:=BARSLAST(CROSS(DIFF4,DEA4))+1;JISHU:=COUNT(CROSS(DEA4,DIFF4) AND DEA4>0,MN);DD2000:=CROSS(DEA4,DIFF4) AND JISHU>1 AND HHV(DIFF4,SN)<HHV(DIFF4,MN) AND HHV(H,SN)=HHV(H,MN),NODRAW;DING:=HHV(DIFF4,MN),POINTDOT,COLORGREEN;STICKLINE1(DING=REF(DING,1) AND DEA4>0,DING,DING,5,0),COLORGREEN;DRAWTEXT(DD2000,DING,'DD2000');DRAWNUMBER1(CROSS(DEA4,DIFF4) AND DEA4>0,DING*1.3,JISHU,0),COLORGREEN;MN1:=BARSLAST(CROSS(0,DEA4))+1;JN:=BARSLAST(CROSS(DEA4,DIFF4))+1;JISHU1:=COUNT(CROSS(DIFF4,DEA4) AND DEA4<0,MN1);DIBU11:CROSS(DIFF4,DEA4) AND JISHU1>1 AND LLV(DIFF4,MN1)<LLV(DIFF4,JN) AND LLV(L,JN)=LLV(L,MN1),NODRAW;DI2000:=LLV(DIFF4,MN1),POINTDOT,COLORRED;STICKLINE1(DI2000=REF(DI2000,1) AND DEA4<0,DI2000,DI2000,5,0),COLORYELLOW;DRAWTEXT(DIBU11,DI2000,'DIBU11');DRAWNUMBER1(CROSS(DIFF4,DEA4) AND DEA4<0,DI2000*0.7,JISHU1,0),COLORYELLOW;12MACD连线背离DIFF:EMA(C,12) - EMA(CLOSE,26);DEA:EMA(DIFF,9);MACD:2*(DIFF-DEA),NODRAW;2*(DIFF-DEA),COLORSTICK;UPCOND:=CROSS(DIFF,DEA);DOWNCOND:=CROSSDOWN(DIFF,DEA);END_N1:=SUMBARS(DOWNCOND,1);RANGE_N1:=REF(SUMBARS(UPCOND,1),END_N1);END_N2:=SUMBARS(DOWNCOND,2);HH1:=REF(HV(H,RANGE_N1),END_N1-1);HH2:=REF(HV(H,RANGE_N1),END_N2-1);MACD1:=REF(HV(DIFF,RANGE_N1),END_N1-1);MACD2:=REF(HV(DIFF,RANGE_N1),END_N2-1);顶背离:=CROSS(0,MACD) && HH1>HH2 && MACD1<MACD2;DRAWTEXT(顶背离,MACD,'顶背离');Q:=BACKSET(CROSS(0,MACD),LLVBARS(DIFF,END_N1)+1);QQ:=BACKSET(顶背离,SUMBARS(Q>REF(Q,1),2));DRAWLINE1(QQ>REF(QQ,1),DIFF,Q>REF(Q,1),DIFF,0),COLORGREEN,LINETHICK3;END_M1:=SUMBARS(UPCOND,1);RANGE_M1:=REF(SUMBARS(DOWNCOND,1),END_M1);END_M2:=SUMBARS(UPCOND,2);LL1:=REF(LV(L,RANGE_M1),END_M1-1);LL2:=REF(LV(L,RANGE_M1),END_M2-1);MACD3:=REF(LV(DIFF,RANGE_M1),END_M1-1);MACD4:=REF(LV(DIFF,RANGE_M1),END_M2-1);底背离:=CROSS(MACD,0) && LL1<LL2 && MACD3>MACD4;DRAWTEXT(底背离,MACD,'底背离');W:=BACKSET(CROSS(0,MACD),HHVBARS(DIFF,END_N1)+1);WW:=BACKSET(底背离,SUMBARS(W>REF(W,1),2));DRAWLINE1(WW>REF(WW,1),DIFF,W>REF(W,1),DIFF,0),COLORRED,LINETHICK3;友情提示:本指标公式仅作为知识分享,供交流学习使用,不构成任何投资建议,不作为投资依据。
免责声明:本网站部分内容由用户自行上传,若侵犯了您的权益,请联系我们处理,谢谢!联系QQ:2760375052