N1:=3;
N2:=5;
N3:=13;
N4:=21;
DIFF:=EMA(CLOSE,12) - EMA(CLOSE,26);
DEA:= EMA(DIFF,9);
MACD:=(DIFF-DEA)*2;
AA:=ZIG(3,N4);
GG:=EMA(AA,2);
SS:IF(REF(GG,1)<GG,1,0);
XJ:IF(REF(GG,1)>GG,1,0);
VAR1:=((CLOSE - LLV(LOW,N1))/(HHV(HIGH,N1) - LLV(LOW,N1)))*(100);
VAR3:=SMA(VAR1,5,1);
K:=SMA(VAR3,3,1);
D:=SMA(K,3,1);
STICKLINE((K >= D),K,D,8,0),COLOR0000A8;
STICKLINE((K >= D),K,D,6,0),COLOR0000C0;
STICKLINE((K >= D),K,D,4,0),COLOR0000E0;
STICKLINE((K >= D),K,D,3,0),COLOR0000F0;
STICKLINE((K >= D),K,D,2,0),COLOR0000D0;
STICKLINE((K >= D),K,D,1,0),COLOR8080FF;
STICKLINE((K <= D),K,D,8,0),COLOR008800;
STICKLINE((K <= D),K,D,6,0),COLOR009900;
STICKLINE((K <= D),K,D,4,0),COLOR00AA00;
STICKLINE((K <= D),K,D,3,0),COLOR00BB00;
STICKLINE((K <= D),K,D,2,0),COLOR00CC00;
STICKLINE((K <= D),K,D,1,0),COLOR00DD00;
MID:=(3*CLOSE+LOW+OPEN+HIGH)/6;
K2:=(20*MID+19*REF(MID,1)+18*REF(MID,2)+17*REF(MID,3)+16*REF(MID,4)+15*REF(MID,5)+14*REF(MID,6)+13*REF(MID,7)+12*REF(MID,8)+11*REF(MID,9)+10*REF(MID,10)+9*REF(MID,11)+8*REF(MID,12)+7*REF(MID,13)+6*REF(MID,14)+5*REF(MID,15)+4*REF(MID,16)+3*REF(MID,17)+2*REF(MID,18)+REF(MID,20))/210;
K3:=MA(K2,5);
J:=MAX(MA(C,N2),MA(C,N3));
K1:=MIN(MA(C,N2),MA(C,N3));
A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));
A3:=BARSLAST(REF(CROSS(K,D),1));
A4:=BARSLAST(REF(CROSS(D,K),1));
底背离:=IF(REF(LOW,A1+1)>LOW AND DIFF>REF(DIFF,A1+1) AND CROSS(DIFF,DEA),1,0);
顶背离:=IF(REF(HIGH,A2+1)<HIGH AND REF(DIFF,A2+1)>DIFF AND CROSS(DEA,DIFF),1,0);
底背离1:=IF(REF(LOW,A3+1)>LOW AND K>REF(K,A3+1) AND CROSS(K,D),1,0);
顶背离1:=IF(REF(HIGH,A4+1)<HIGH AND REF(D,A4+1) AND CROSS(D,K),1,0);
DRAWTEXT(CROSS(K,D) AND C>J AND D<76 AND REF(MACD,1)<MACD AND (顶背离=0 OR 顶背离1=0) AND SS=1 AND C>K2,K,'买'),COLORRED;
DRAWICON(CROSS(K,D) AND C>J AND D<76 AND REF(MACD,1)<MACD AND (顶背离=0 OR 顶背离1=0) AND SS=1 AND C>K2,K,1);
DRAWTEXT(CROSS(D,K) AND (C<K1 OR (J>=C AND C>=K)) AND REF(MACD,1)>MACD AND (底背离=0 OR 底背离1=0) AND D>18 AND XJ=1 AND C<K3,D,'卖'),COLORWHITE;
DRAWICON(CROSS(D,K) AND (C<K1 OR (J>=C AND C>=K)) AND REF(MACD,1)>MACD AND (底背离=0 OR 底背离1=0) AND D>18 AND XJ=1 AND C<K3,D,2);
DRAWTEXT(CROSS(K,D) AND (底背离=1 AND 底背离1=1) AND 顶背离1=0 AND SS=1 ,K,'买'),COLORRED;
DRAWICON(CROSS(K,D) AND (底背离=1 AND 底背离1=1) AND 顶背离1=0 AND SS=1 ,K,1);
DRAWTEXT(CROSS(D,K) AND 顶背离=1 AND 顶背离1=1 AND XJ=1,D,'卖'),COLORWHITE;
DRAWICON(CROSS(D,K) AND 顶背离=1 AND 顶背离1=1 AND XJ=1,D,2),COLORWHITE;