通达信自动画趋势线公式代码-短期压力与支撑线画线
A1:=REF(H,N)=HHV(H,2*N+1);
B1:=FILTER(A1,N);
C1:=BACKSET(B1,N+1);
D1:=FILTER(C1,N);{高点}
A2:=REF(L,N)=LLV(L,2*N+1);
B2:=FILTER(A2,N);
C2:=BACKSET(B2,N+1);
D2:=FILTER(C2,N);{低点}
E1:=(REF(LLV(L,2*N),1)+REF(HHV(H,2*N),1))/2; E2:=(H+L)/2;{高低点出现在同一K线上时可作取舍}
H1:=(D1 AND NOT(D2 AND E1>=E2)) OR ISLASTBAR OR BARSCOUNT(C)=1;
L1:=(D2 AND NOT(D1 AND E1<E2)); H2:=D1 AND NOT(D2 AND E1>=E2);
X1:=REF(BARSLAST(H1),1)+1; F1:=BACKSET(H1 AND COUNT(L1,X1)>0,LLVBARS
(IF(L1,L,10000),X1));
G1:=F1>REF(F1,1); I1:=BACKSET(G1,2); LD:=I1>REF(I1,1);{过滤后低点}
L2:=LD OR ISLASTBAR OR BARSCOUNT(C)=1;
X2:=REF(BARSLAST(L2),1)+1; F2:=BACKSET(L2 AND COUNT(H2,X2)>0,HHVBARS
(IF(H2,H,0),X2));
G2:=F2>REF(F2,1); I2:=BACKSET(G2,2); HD:=I2>REF(I2,1);{过滤后高点}
R1:=BACKSET(ISLASTBAR,BARSLAST(HD)+1); S1:=R1>REF(R1,1); {前一高}
T1:=BACKSET(ISLASTBAR,BARSLAST(LD)+1); U1:=T1>REF(T1,1); {前一低}
R2:=BACKSET(S1,REF(BARSLAST(HD),1)+2); S2:=R2>REF(R2,1); {前二高}
T2:=BACKSET(U1,REF(BARSLAST(LD),1)+2); U2:=T2>REF(T2,1); {前二低}
T3:=BACKSET(U2,REF(BARSLAST(LD),1)+2); U3:=T3>REF(T3,1); {前三低}
T4:=BACKSET(U3,REF(BARSLAST(LD),1)+2); U4:=T4>REF(T4,1); {前四低}
R3:=BACKSET(S2,REF(BARSLAST(HD),1)+2); S3:=R3>REF(R3,1); {前三高}
R4:=BACKSET(S3,REF(BARSLAST(HD),1)+2); S4:=R4>REF(R4,1); {前四高}
短期压力:DRAWLINE(S2,H,S1,H,1),COLORRED;
短期支撑:DRAWLINE(U2,L,U1,L,1),COLORGREEN;
中期压力:DRAWLINE(S3,H,S2,H,1),COLORYELLOW;
中期支撑:DRAWLINE(U3,L,U2,L,0),COLORGREEN;
长期压力:DRAWLINE(S4,H,S3,H,1),COLORFF00FF;
长期支撑:DRAWLINE(U4,L,U3,L,0),COLORGREEN;
DRAWICON(S1,H*1.01,7);
DRAWICON(S2,H*1.01,7);
DRAWICON(S3,H*1.01,7);
DRAWICON(S4,H*1.01,7);
DRAWICON(U1,L*0.99,6);
DRAWICON(U2,L*0.99,6);
DRAWICON(U3,L*0.99,6);
DRAWICON(U4,L*0.99,6);