N:=9;
DIF:=MA(CLOSE,9)-MA(CLOSE,7);
DEA:=MA(DIF,4);
macd1:=(DIF-DEA)*2;
RSV:=(CLOSE-LLV(LOW,9))/(HHV(HIGH,9)-LLV(LOW,9))*100;
K:=MA(RSV,4);
D:=MA(K,4);
J:=3*K-2*D;
LC:=REF(CLOSE,1);
rsi1:=MA(MAX(CLOSE-LC,0),9)/MA(Abs(CLOSE-LC),4)*100;
TYP1:=(HIGH+LOW+CLOSE)/3;
cci1:=(TYP1-MA(TYP1,4))/(0.015*AVEDEV(TYP1,9));
DD:=C=LLV(C,N);{60日最低点}
DDSJ:=BArslAST(REF(DD,1));{上一低点时间}
DDGJ:=REF(CLOSE,DDSJ+1)>CLOSE;{股价趋势}
kdZB:=REF(J,DDSJ+1);
K底背离:=DDGJ AND KDZB;
GD:=C=HHV(C,N);{60日最高点}
GDSJ:=BARSLAST(REF(GD,1));{上一高点时间}
GDGJ:=REF(CLOSE,GDSJ+1);
KGZB:=REF(J,GDSJ+1)>J;
K顶背离:=GDGJ AND KGZB;
MDZB:=REF(MacD1,DDSJ+1);
M底背离:=DDGJ AND MDZB;
MGZB:=REF(MACD1,GDSJ+1)>MACD1;
M顶背离:=GDGJ AND MGZB;
RDZB:=REF(RSI1,DDSJ+1);
R底背离:=DDGJ AND RDZB;
RGZB:=REF(RSI1,GDSJ+1)>RSI1;
R顶背离:=GDGJ AND RGZB;
TYP:=(HIGH + LOW + CLOSE)/3;
CDZB:=REF(CCI1,DDSJ+1);
C底背离:=DDGJ AND CDZB;
CGZB:=REF(CCI1,GDSJ+1)>CCI1;
C顶背离:=GDGJ AND CGZB;
DRAWTEXT(K顶背离,IF(ISLASTBAR,27.5,25),'←'),LINETHICK2 ;
DRAWTEXT(M顶背离,(ISLASTBAR,24.5,20),'←'),LINETHICK2 ;
DRAWTEXT(R顶背离,(ISLASTBAR,20.5,15),'←'),LINETHICK2 ;
DRAWTEXT(C顶背离,(ISLASTBAR,15.5,10),'←'),LINETHICK2 ;
DRAWTEXT(ISLASTBAR,10.1 ,'CCI '),LINETHICK2,COLORGREEN;
DRAWTEXT(C底背离,IF(ISLASTBAR,12,10),'←'),LINETHICK2,COLORRED;
DRAWTEXT(ISLASTBAR,15,'RSI '),LINETHICK2,COLORRED;
DRAWTEXT(R底背离,IF(ISLASTBAR,8.5,15),'←'),LINETHICK2,COLORRED;
DRAWTEXT(ISLASTBAR,20,'MACD '),LINETHICK2,COLORMAGENTA;
DRAWTEXT(M底背离,IF(ISLASTBAR,4.5,20),'←'),LINETHICK2,COLORRED;
DRAWTEXT(ISLASTBAR,25,'kdj '),LINETHICK2,COLORRED;
DRAWTEXT(K底背离,IF(ISLASTBAR,1.5,25),'←'),LINETHICK2,COLORRED;
综合顶:=K顶背离+M顶背离+R顶背离+C顶背离;
综合底:=C底背离+R底背离+M底背离+K底背离;
相对顶背离:=综合顶=3;
DRAWICON(综合顶=3 AND C<(REF(C,1)*0.99),40,1);
DRAWICON(综合底=4 AND C<(REF(C,1)*0.99),0,1);