DIFF:EMA(CLOSE,12) - EMA(CLOSE,26); DEA:EMA(DIFF,9); MACD:2*(DIFF-DEA),COLORSTICK; JC:=CROSS(DIFF,DEA); SC:=CROSSDOWN(DIFF,DEA); N1:=BARSLAST(JC)+1; N2:=BARSLAST(SC)+1;
MHD:=VALUEWHEN(CROSSDOWN(DIFF,DEA),HHV(DIFF,N1));//上次MACD紅柱期間DIFF最大值 MHD2:=VALUEWHEN(CROSSDOWN(DIFF,DEA),REF(MHD,1));//上上次MACD紅柱期間DIFF最大值
MLD:=VALUEWHEN(CROSS(DIFF,DEA),LLV(DIFF,N2)); MLD2:=VALUEWHEN(CROSS(DIFF,DEA),REF(MLD,1));
A1:=SC&&REF(N1,1)>5&&REF(N1,N1)>5; A2:=JC&&REF(N2,1)>5&&REF(N2,N2)>5;
DRAWLINE3(A1&&MHD2>MHD,MHD2,REF(HHVBARS(DIFF,N1),N1)+N1,A1&&MHD2>MHD,MHD,HHVBARS(DIFF,N1),0); DRAWLINE3(A2&&MLD2<MLD,MLD2,REF(LLVBARS(DIFF,N2),N2)+N2,A2&&MLD2<MLD,MLD,LLVBARS(DIFF,N2),0); Q:=BACKSET(A1&&MHD2>MHD,HHVBARS(DIFF,N1)+1); QQ:=BACKSET(A2&&MLD2<MLD,LLVBARS(DIFF,N2)+1);
DRAWTEXT(CROSS(Q,0.5),DIFF,'頂背離'); DRAWTEXT(CROSS(QQ,0.5),DIFF,'底背離');
|