SHORT:=12;
LONG:=26;
M:=9;
DIFF : EMA(CLOSE,SHORT) - EMA(CLOSE,LONG),colorwhite;
DEA : EMA(DIFF,M),coloryellow;
MACD :=2*(DIFF-DEA);
Zero : 0;
STICKLINE(MACD 0,0,MACD,1,0),colorred;
STICKLINE(MACD 0,0,MACD,1,0),colorgreen;
//VARGu:=(REF(diff,2) =REF(diff,1) AND diff REF(diff,1))OR (REF(diff,2) =REF(diff,1) AND ( (REF(diff,1)-REF(diff,2)) /REF(diff,2) (diff-REF(diff,1)) /REF(diff,1)*1.1 ) );
//VARGu:=(REF(diff,2) =REF(diff,1) AND diff REF(diff,1));
VARGu:=CROSS(diff,dea);
AA:=COUNT(VARGu,BARSLAST(DEA =0));
A1:=BARSLAST(REF(VARGu,1));
二次金叉:=CROSS(DIFF,DEA) AND DEA 0 AND AA =2 AND dea 0 AND A1
DRAWTEXT(二次金叉,0.2,''+AA+'次金叉'),coloryellow;
底背离:=MIN(REF(CLOSE,A1+1),REF(CLOSE,A1+2),REF(CLOSE,A1+3),REF(CLOSE,A1+4)) LLV(CLOSE,3) AND LLV(DIFF,3) MIN(REF(DIFF,A1+1), REF(DIFF,A1+2),REF(DIFF,A1+3),REF(DIFF,A1+4)) AND VARGu AND diff
A3:=COUNT(底背离,BARSLAST(DEA =0));
STICKLINE(底背离,0,HHV(MACD,500),6,0),colorred;
DRAWLINE(A1=0, MIN(REF(DIFF,A1+1), REF(DIFF,A1+2),REF(DIFF,A1+3),REF(DIFF,A1+4)),底背离,LLV(DIFF,3),0),colorred;
//DRAWTEXT(底背离,0.12,' '+a3+'次背离'),COLORFF00FF;
A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));
顶背离:=REF(CLOSE,A2+1) CLOSE AND REF(DIFF,A2+1) DIFF AND CROSS(DEA,DIFF);
DRAWLINE(A2=0,DEA,顶背离,DEA,0),colorgreen;
建仓:IF(底背离,A3*HHV(MACD,500),0),colorred;