周期微调:=5; 高位微调:=1;低位微调:=1;
强势线:MA(C,9),COLORMAGENTA,LINETHICK2;
A1:=REF(HIGH,周期微调)=HHV(HIGH,13+1);
B1:=FILTER(A1,周期微调);
C1:=BACKSET(B1,周期微调+1);
D1:=FILTER(C1,周期微调);{高点}
A2:=REF(LOW,周期微调)=LLV(LOW,12+1);
B2:=FILTER(A2,周期微调);
C2:=BACKSET(B2,周期微调+1);
D2:=FILTER(C2,周期微调);{低点}
E1:=(REF(LLV(LOW,2*3),1)+REF(HHV(HIGH,10),1))/2;
E2:=(HIGH+LOW)/2;{高低点出现在同一k线上时可作取舍}
H1:=(D1 AND NOT(D2 AND E1>=E2)) OR ISLASTBAR OR BARSCOUNT(CLOSE)=1;
H2:=D1 AND NOT(D2 AND E1>=E2);
L1:=D2 AND NOT(D1 AND E1=E2);
X1:=REF(BARSLAST(H1),1)+1;
F1:=BACKSET(H1 AND COUNT(L1,X1)>0,LLVBARS(IF(L1,LOW,10000),X1));
G1:=F1>REF(F1,1);
I1:=BACKSET(G1,2);
LD:=I1>REF(I1,1);{过滤后低点}
L2:=LD OR ISLASTBAR OR BARSCOUNT(CLOSE)=1;
X2:=REF(BARSLAST(L2),1)+1;
F2:=BACKSET(L2 AND COUNT(H2,X2)>0,HHVBARS(IF(H2,HIGH,0),X2));
G2:=F2>REF(F2,1);
I2:=BACKSET(G2,2);
HD:=I2>REF(I2,1);{过滤后高点}
A3:=H;
B3:=REF(H,REF(BARSLAST(HD),1)+1)>REF(H,REF(BARSLAST(HD),1)+2+REF(BARSLAST(HD),REF(BARSLAST(HD),1)+2));
D3:=A3 AND B3 AND HD;
E3:=BACKSET(D3,REF(BARSLAST(HD),1)+2);
HH:=E3>REF(E3,1);{找出全部长期高点}
A4:=L>REF(L,REF(BARSLAST(LD),1)+1);
B4:=REF(L,REF(BARSLAST(LD),1)+1); D4:=A4 AND B4 AND LD; E4:=BACKSET(D4,REF(BARSLAST(LD),1)+2); LL:=E4>REF(E4,1);{找出全部长期低点}
H3:=HH OR ISLASTBAR OR BARSCOUNT(C)=1; {后面进行过滤,方法同前。只是不用考虑高低点出现在同一K线}
X3:=REF(BARSLAST(H3),1)+1;
F3:=BACKSET(H3 AND COUNT(LL,X3)>0,LLVBARS(IF(LL,L,POW(10,20)),X3));
G3:=F3>REF(F3,1);
I3:=BACKSET(G3,2);
LZ:=I3>REF(I3,1); {长期低点,也可供引用}
L4:=LZ OR ISLASTBAR OR BARSCOUNT(C)=1;
X4:=REF(BARSLAST(L4),1)+1;
F4:=BACKSET(L4 AND COUNT(HH,X4)>0,HHVBARS(IF(HH,H,-POW(10,20)),X4));
G4:=F4>REF(F4,1);
I4:=BACKSET(G4,2);
HZ:=I4>REF(I4,1);{长期高点,也可供引用}
K1:=BACKSET(ISLASTBAR,MIN(BARSLAST(HZ),BARSLAST(LZ))+1);
K2:=K1>REF(K1,1);
UU:=BACKSET(ISLASTBAR,BARSLAST(LD)+低位微调);
VV:=UU>REF(UU,1);
WW:=BACKSET(VV,REF(BARSLAST(LD),1)+2);
XX:=WW>REF(WW,1);
UU2:=BACKSET(ISLASTBAR,BARSLAST(HD)+高位微调);
VV2:=UU2>REF(UU2,1);
WW2:=BACKSET(VV2,REF(BARSLAST(HD),1)+2);
XX2:=WW2>REF(WW2,1);
高点:=BARSLAST(VV2);
低点:=BARSLAST(VV);
J1:=BACKSET(ISLASTBAR,MIN(高点,低点)+1);
J2:=J1>REF(J1,1);
NOTEXT1:DRAWLINE(LD,L,HD,H,0),LINETHICK1,DOTLINE,COLOR0000FF;
NOTEXT2:DRAWLINE(HD,H,LD,L,0),LINETHICK1,DOTLINE,COLOR00FF00;
NOTEXT3:DRAWLINE(J2,IF(HD,H,L),ISLASTBAR,IF(高点>低点,H,L),0),DOTLINE,COLORFFFFFF;
VAR8:=REFDATE(HHV(H,高点+1),DATE);
VAR9:=REFDATE(LLV(L,低点+1),DATE);
{买入}
高位价:REF(REF(H,高点),1),COLORRED,NODRAW;
低位价:REF(REF(L,低点),1),COLORGREEN,NODRAW;
H11:=高位价,NODRAW;
H12:=低位价,NODRAW;
L22:=DRAWNULL,NODRAW;
VVA:=IF(高点<低点,H11,L22)NODRAW;
买入成立:=VVA,COLOR00FFFF,NODRAW;
VVB:=IF(高点>低点,L22,H12)NODRAW;
买入不成立:=VVB,COLORGREEN,NODRAW;
高位价1:=IFC(高点<低点,H11,L22);
低位价1:=IFC(高点<低点,H12,L22);
BCJ:=高位价1-低位价1,NODRAW;
B11:=高位价1-(BCJ*0.382),NODRAW;
B21:=高位价1-(BCJ*0.618),NODRAW;
B31:=高位价1-(BCJ*1.618),NODRAW;
B41:=高位价1-(BCJ*2.618),NODRAW;
B51:=高位价1-(BCJ*3.618),NODRAW;
B61:=高位价1-(BCJ*4.618)NODRAW;
B382:DRAWLINE(VV2,CONST(B11),CURRBARSCOUNT=1,B11,1),COLORGREEN;
B618:DRAWLINE(VV2,CONST(B21),CURRBARSCOUNT=1,B21,1),COLORGREEN;
B1618:DRAWLINE(VV2,CONST(B31),CURRBARSCOUNT=1,B31,1),COLORGREEN;
B2618:DRAWLINE(VV2,CONST(B41),CURRBARSCOUNT=1,B41,1),COLORGREEN;
B3618:DRAWLINE(VV2,CONST(B51),CURRBARSCOUNT=1,B51,1),COLORGREEN;
B4618:DRAWLINE(VV2,CONST(B61),CURRBARSCOUNT=1,B61,1),COLORGREEN;
DRAWTEXT(CURRBARSCOUNT=1,B382,VARCAT('(B0.382):',VAR2STR(B382,2))),COLORWHITE;
DRAWTEXT(CURRBARSCOUNT=1,B618,VARCAT('(B0.618):',VAR2STR(B618,2))),COLORWHITE;
DRAWTEXT(CURRBARSCOUNT=1,B1618,VARCAT('(B1.618):',VAR2STR(B1618,2))),COLORWHITE;
DRAWTEXT(CURRBARSCOUNT=1,B2618,VARCAT('(B2.618):',VAR2STR(B2618,2))),COLORWHITE;
DRAWTEXT(CURRBARSCOUNT=1,B3618,VARCAT('(B3.618):',VAR2STR(B3618,2))),COLORWHITE;
DRAWTEXT(CURRBARSCOUNT=1,B4618,VARCAT('(B4.618):',VAR2STR(B4618,2))),COLORWHITE;
DRAWTEXT(VV,L,VARCAT('低位【A】',VAR2STR(L,2))),COLORGREEN;
DRAWTEXT(VV2,H,VARCAT('高位【B】',VAR2STR(H,2))),COLORRED;
STICKLINE(VV2,H,CONST(B61),0,-1),COLORGREEN;
DRAWLINE(VV2,H,CURRBARSCOUNT=1,CONST(B61),0),COLORGREEN,DOTLINE;
DRAWLINE(VV,L,VV2,H,0),COLORGREEN,LINETHICK2;
{卖出}
高位价2:=REF(REF(H,高点),1),NODRAW;
低位价2:=REF(REF(L,低点),1),NODRAW;
H111:=高位价2,NODRAW;
H121:=低位价2,NODRAW;
L221:=DRAWNULL,NODRAW;
H221:=高位价2,NODRAW;
H231:=低位价2,NODRAW;
VVA1:=IF(高点>低点,H121,DRAWNULL)NODRAW;
卖出成立:=VVA1,COLOR00FFFF,NODRAW;
VVB1:=IF(高点<低点,L221,DRAWNULL)NODRAW;
卖出不成立:=VVB1,COLORGREEN,NODRAW;
高位价3:=IFC(高点>低点,H111,L221);
低位价3:=IFC(高点>低点,H121,L221);
SCJ:=(高位价3-低位价3),NODRAW;
S11:=低位价3+(SCJ*0.382),NODRAW;
S21:=低位价3+(SCJ*0.618),NODRAW;
S31:=低位价3+(SCJ*1.618),NODRAW;
S41:=低位价3+(SCJ*2.618),NODRAW;
S51:=低位价3+(SCJ*3.618),NODRAW;
S61:=低位价3+(SCJ*4.618),NODRAW;
S382:DRAWLINE(VV,CONST(S11),CURRBARSCOUNT=1,S11,1),COLORRED;
S618:DRAWLINE(VV,CONST(S21),CURRBARSCOUNT=1,S21,1),COLORRED;
S1618:DRAWLINE(VV,CONST(S31),CURRBARSCOUNT=1,S31,1),COLORRED;
S2618:DRAWLINE(VV,CONST(S41),CURRBARSCOUNT=1,S41,1),COLORRED;
S3618:DRAWLINE(VV,CONST(S51),CURRBARSCOUNT=1,S51,1),COLORRED;
S4618:DRAWLINE(VV,CONST(S61),CURRBARSCOUNT=1,S61,1),COLORRED;
DRAWTEXT(CURRBARSCOUNT=1,S382,VARCAT('(S0.382):',VAR2STR(S382,2))),COLORYELLOW;
DRAWTEXT(CURRBARSCOUNT=1,S618,VARCAT('(S0.618):',VAR2STR(S618,2))),COLORYELLOW;
DRAWTEXT(CURRBARSCOUNT=1,S1618,VARCAT('(S1.618):',VAR2STR(S1618,2))),COLORYELLOW;
DRAWTEXT(CURRBARSCOUNT=1,S2618,VARCAT('(S2.618):',VAR2STR(S2618,2))),COLORYELLOW;
DRAWTEXT(CURRBARSCOUNT=1,S3618,VARCAT('(S3.618):',VAR2STR(S3618,2))),COLORYELLOW;
DRAWTEXT(CURRBARSCOUNT=1,S4618,VARCAT('(S4.618):',VAR2STR(S4618,2))),COLORYELLOW;
STICKLINE(VV,L,CONST(S61),0,-1),COLORRED;
DRAWLINE(VV,L,CURRBARSCOUNT=1,CONST(S61),0),COLORRED,DOTLINE;
DRAWLINE(VV2,H,VV,L,0),COLORRED,LINETHICK2;
DRAWICON(VV,L,38);
DRAWICON(VV2,H,39);