等级: 标准版
- 注册:
- 2021-5-31
- 曾用名:
|
楼主 |
发表于 2021-6-30 11:52
|
显示全部楼层
//该策略适用日线周期、分钟周期
VARIABLE:A:=0;
VARIABLE:MARK:=0;
ma37:=ma(c,n4)COLORMAGENTA;
CMI:=ABS(CLOSE-REF(CLOSE,29))/(HHV(HIGH,30)-LLV(L,30))*100;//0-100 取值越大,说明趋势越强,CMI<20震荡模式,反之为趋势
INPUT:N1(30,1,1000,1),N2(150,1,1000,1),P5(12,3,100,10),M1(12,1,100,10),N3(1,1,100,1),n(20,1,100,10),N4(10,1,200,1),P1(45,10,100,8),S(25,5,40,4),M(9,2,60,6),P(20,10,100,8),ZS(0.990,0.900,0.999,0.001),zy(0.985,0.900,0.999,0.001),zy1(0.985,0.900,0.999,0.001),SS(1,1,100,1);
PH3:=(CLOSE-OPEN)>=1*MINDIFF;
PH9:=(CLOSE-OPEN)>=10*MINDIFF;
PE9:=(OPEN-C)>=10*MINDIFF;
PE3:=(OPEN-CLOSE)>=1*MINDIFF;
DIFF : =EMA(CLOSE,S) - EMA(CLOSE,P1);
DEA : =EMA(DIFF,M);
MACD1 := 2*(DIFF-DEA), COLORSTICK;
PSY:=COUNT(CLOSE>REF(CLOSE,1),M1)/M1*100;
//中间变量
CD88:=OPENPROFIT>=100*MINDIFF;//表示盈利40个点以上平CLOSETIME(0) 60
CD66:=OPENPROFIT<=-10*MINDIFF;//表示盈利40个点以上平CLOSETIME(0)-10
CD300:=OPENPROFIT>=250*MINDIFF;//表示盈利40个点以上平CLOSETIME(0) 60
CD200:=OPENPROFIT>=250*MINDIFF;//表示盈利40个点以上平CLOSETIME(0) 60
CD600:=OPENPROFIT>=250*MINDIFF;//表示盈利40个点以上平CLOSETIME(0) 60
CD400:=OPENPROFIT>=200*MINDIFF;//表示盈利40个点以上平CLOSETIME(0) 60
H1:=IF(Low<ref(low,1) AND ref(low,1)<ref(low,2) and open>close,MAX(High,ref(High,1)),0);//创新低取最高价
L1:=IF(High>ref(High,1) and ref(High,1)>ref(High,2) and open<close,MIN(Low,ref(low,1)),0);//创新高取最低价
HR:=VALUEWHEN(H1>0,H1);//平空点
LR:=VALUEWHEN(L1>0,L1);//平多点
D1:=IF(C>HR,-1,IF(C<LR,1,0));//空头止损返回-1,多头止损返回1AND ISUP AND ISDOWN SLOPE(CLOSE,10 )
D2:=VALUEWHEN(D1<>0,D1);
BARSLAST(D1=-1);
G:=IF(D2=1,HR,LR);//如果多头止损画平空线,否则画平多线
多头止损线:=IF(D2<=0,G,drawnull),COLOR6633FF,LINETHICK1,COLORWHITE;
空头止损线:=IF(D2>0,G,drawnull),COLORFF9933,LINETHICK1,COLORGREEN;
MC:=TYPEBAR(holding>0,1);
MC2:=TYPEBAR(holding<0,3);
成交量H:=VOL=HHV(VOL,2);
成交量L:=VOL=LLV(VOL,2);
成交量L1:=VOL=LLV(VOL,2);
VAR2:=MA(C,N2)COLORWHITE;
VAR3:MA(VAR2,N1)COLORYELLOW;
VAR4:=IF((H+L)<=(REF(H,1)+REF(L,1)),0,MAX(ABS(H-REF(H,1)),ABS(L-REF(L,1))));
VAR5:=IF((H+L)>=(REF(H,1)+REF(L,1)),0,MAX(ABS(H-REF(H,1)),ABS(L-REF(L,1))));
VAR6:=SUM(VAR4,N1)/(SUM(VAR4,N1)+SUM(VAR5,N1));
VAR7:=SUM(VAR5,N1)/(SUM(VAR4,N1)+SUM(VAR5,N1));
VAR8:=VAR6-VAR7;
VAR9:=MA(VAR8,2*N1);
VAR10:=MA(VAR9,N1);
手数:ss;
TR1:= EMA(EMA(EMA(CLOSE,P5),P5),P5);
TRIX : (TR1-REF(TR1,1))/REF(TR1,1)*100;
TRcd : MA(TRIX,N);
TRx :=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
ATR :=MA(TRx,20);
CDTT:= (C-VAR3)<=15*MINDIFF;
CDYY:= (VAR3-C)<=15*MINDIFF;
CDTT1:= (C-VAR2)<=15*MINDIFF;
CDYY1:= (VAR2-C)<=15*MINDIFF;
CDBB:=VAR2-VAR3<=2*MINDIFF;
CDXX:=VAR3-VAR2<=2*MINDIFF;
CONPD:C<VAR2 AND C>ENTERPRICE*(1+0.03*N3);
CONPK:C>VAR2 AND C<ENTERPRICE*(1-0.03*N3);
CONKD:BARPOS>N2 AND C>VAR2 AND VAR2>VAR3 AND VAR8>0 AND VAR9>VAR10;
CONKK:BARPOS>N2 AND C<VAR2 AND VAR2<VAR3 AND VAR8<0 AND VAR9<VAR10;
//交易条件:
平空条件:=ma37>VAR3 AND TRIX>TRCD AND CDTT AND MARK>=0 and holding<=0;
开多条件:=ma37>VAR3 AND TRIX>TRCD AND CDTT AND MARK>=0 and holding=0;
平多条件:=ma37<VAR3 AND TRIX<TRCD AND CDYY AND MARK<=0 and holding>=0;
开空条件:=ma37<VAR3 AND TRIX<TRCD AND CDYY AND MARK<=0 and holding=0;
平空条件1:= DEA>0 AND TRIX>TRCD AND MARK>=0 AND CDTT and holding<=0;
开多条件1:= DEA>0 AND TRIX>TRCD AND MARK>=0 AND CDTT and holding=0;
平多条件1:= DEA<0 AND TRIX<TRCD AND MARK<=0 AND CDYY and holding>=0;
开空条件1:= DEA<0 AND TRIX<TRCD AND MARK<=0 AND CDYY and holding=0;
平空条件2:=ma37>VAR3 and DEA>0 AND MARK>=0 AND TRIX>TRCD AND CDTT and c>VAR3 and holding<=0;
开多条件2:=ma37>VAR3 AND MARK>=0 and DEA>0 AND TRIX>TRCD AND CDTT and c>VAR3 and holding=0;
平多条件2:=ma37<VAR3 and DEA<0 AND MARK<=0 AND TRIX<TRCD AND CDYY and c<VAR3 and holding>=0;
开空条件2:=ma37<VAR3 AND MARK<=0 and DEA<0 AND TRIX<TRCD AND CDYY and c<VAR3 and holding=0;
IF ma37>VAR3 AND ISDOWN AND C>=MA37 AND CMI>15 AND PE3 THEN BEGIN
A:=0;
IF 平空条件 AND ISDOWN THEN BEGIN
平空10:=sellshort( holding=-2*ss, 2*ss,MARKETR);
平空5:=sellshort( holding=-ss, 1,MARKETR);
//MARK:=0;
//END
//IF 开多条件 AND ISDOWN AND PE3 THEN BEGIN
开多1:=buy( holding=0, 手数*1,MARKETR);
MARK:=-1;
END
IF 平空条件 AND ISDOWN THEN BEGIN
平空10:=sellshort( holding=-2*ss, 2*ss,MARKETR);
平空5:=sellshort( holding=-ss, 1,MARKETR);
//MARK:=0;
//END
//IF 开多条件 AND ISDOWN AND PE3 THEN BEGIN
开多2:=buy( holding=0, 手数*1,MARKETR);
MARK:=-1;
END
END
{ IF 平空条件 AND ISUP and cdtt THEN BEGIN
平空10:=sellshort( holding=-2*ss, 2*ss,MARKETR);
平空5:=sellshort( holding=-1, 1,limitr,c);
//MARK:=0;
//END
//IF 开多条件 AND ISDOWN AND PE3 THEN BEGIN
开多3:=buy( holding=0, 手数*2,limitr,c);
MARK:=0;
END}
IF MC>=5 AND CD200 and 手数*1 AND ISUP THEN BEGIN
波幅止盈Ag350:SELL(holding=ss,1,MARKETR);
mark:=-1;
END
IF MC>=50 AND CD600 and 手数*1 AND ISUP THEN BEGIN
波幅止盈A600:SELL(holding=ss,1,MARKETR);
mark:=-1;
END
IF MC>=2 AND PH9 and 手数*1 AND ISUP THEN BEGIN
波幅止盈PH9:SELL(holding=ss,1,MARKETR);
mark:=-1;
END
IF ma37<VAR3 AND CMI>15 AND C<MA37 AND ISUP AND PH3 THEN BEGIN
A:=0;
IF 平多条件 AND ISUP THEN BEGIN
平多2:=sell( holding=2*ss,2*ss,MARKETR);
平多1:=sell( holding=ss,1,MARKETR);
// mark:=1;
// END
//IF 开空条件 AND ISUP THEN BEGIN
开空1:BUYSHORT( HOLDING=0 ,1,MARKETR);
mark:=1;
END
IF 平多条件 AND ISUP THEN BEGIN
平多2:=sell( holding=2*ss,2*ss,MARKETR);
平多1:=sell( holding=ss,1,MARKETR);
// mark:=0;
// END
//IF 开空条件 AND ISUP THEN BEGIN
开空2:BUYSHORT( HOLDING=0 ,1,MARKETR);
mark:=1;
END
IF 平多条件 AND ISDOWN THEN BEGIN
平多2:=sell( holding=2*ss,2*ss,MARKETR);
平多1:=sell( holding=ss,1,MARKETR);
// mark:=1;
// END
//IF 开空条件 AND ISUP THEN BEGIN
开空3:BUYSHORT( HOLDING=0 ,1,MARKETR);
mark:=1;
END
END
IF MC2>=5 AND CD300 and 手数*1 THEN BEGIN
波幅止盈By100:SELLSHORT(holding=-1,1,MARKETR);
// 开多B1:=buy( holding=0, 手数*2,MARKETR);
mark:=1;
END
IF MC2<=10 AND ISDOWN AND CD400 and 手数*1 THEN BEGIN
波幅止盈B40:SELLSHORT(holding=-1,1,MARKETR);
mark:=1;
END
{ IF MC2>=2 AND ISDOWN AND PH9 and 手数*2 THEN BEGIN
波幅止盈PE10:SELLSHORT(holding=-2,1,MARKETR);
mark:=1;
END }
IF DEA>0 AND CDXX AND C>MA37 AND CMI>15 AND PE3 THEN BEGIN
A:=1;
IF 平空条件1 AND ISDOWN THEN BEGIN
平空10:=sellshort( holding=-2*ss, 2*ss,MARKETR);
平空5:=sellshort( holding=-ss, 1,MARKETR);
//MARK:=0;
//END
//IF 开多条件 AND ISDOWN AND PE3 THEN BEGIN
开多1:=buy( holding=0, 手数*1,MARKETR);
MARK:=-1;
END
IF 平空条件1 AND ISDOWN THEN BEGIN
平空10:=sellshort( holding=-2*ss, 2*ss,MARKETR);
平空5:=sellshort( holding=-ss, 1,MARKETR);
//MARK:=0;
//END
//IF 开多条件 AND ISDOWN AND PE3 THEN BEGIN
开多2:=buy( holding=0, 手数*1,MARKETR);
MARK:=-1;
END
END
IF DEA<0 AND ISUP AND C<MA37 AND TRIX<TRCD AND CMI>15 AND PH3 THEN BEGIN
A:=1;
IF 平多条件1 AND ISUP AND C<=MA37 AND CDBB AND TRIX<TRCD THEN BEGIN
平多2:=sell( holding=2*ss,2*ss,MARKETR);
平多1:=sell( holding=ss,1,MARKETR);
// mark:=1;
// END
//IF 开空条件1 AND ISUP THEN BEGIN
开空A1:BUYSHORT( HOLDING=0 ,1,MARKETR);
mark:=1;
END
IF 平多条件1 AND ISUP THEN BEGIN
平多2:=sell( holding=2*ss,2*ss,MARKETR);
平多1:=sell( holding=ss,1,MARKETR);
// mark:=1;
// END
//IF 开空条件1 AND ISUP THEN BEGIN
开空A2:BUYSHORT( HOLDING=0 ,1,MARKETR);
mark:=1;
END
IF 平多条件1 AND ISDOWN THEN BEGIN
平多2:=sell( holding=2*ss,2*ss,MARKETR);
平多1:=sell( holding=ss,1,MARKETR);
// mark:=1;
// END
//IF 开空条件1 AND ISUP THEN BEGIN
开空A3:BUYSHORT( HOLDING=0 ,1,MARKETR);
mark:=1;
END
END
IF DEA>0 AND ma37>VAR3 AND C>MA37 AND CMI>15 AND PE3 THEN BEGIN
A:=-1;
IF 平空条件2 AND ISDOWN THEN BEGIN
平空10:=sellshort( holding=-2*ss, 2*ss,MARKETR);
平空5:=sellshort( holding=-ss, 1,MARKETR);
//MARK:=0;
//END
//IF 开多条件 AND ISDOWN AND PE3 THEN BEGIN
开多B1:=buy( holding=0, 手数*1,MARKETR);
MARK:=-1;
END
IF 平空条件 AND ISDOWN THEN BEGIN
平空10:=sellshort( holding=-2*ss, 2*ss,MARKETR);
平空5:=sellshort( holding=-ss, 1,MARKETR);
//MARK:=0;
//END
//IF 开多条件 AND ISDOWN AND PE3 THEN BEGIN
开多B2:=buy( holding=0, 手数*1,MARKETR);
MARK:=-1;
END
END
IF DEA<0 AND ma37<VAR3 AND CMI>15 AND PH3 THEN BEGIN
A:=-1;
IF 平多条件 AND ISUP THEN BEGIN
平多2:=sell( holding=2*ss,2*ss,MARKETR);
平多1:=sell( holding=ss,1,MARKETR);
// mark:=1;
// END
//IF 开空条件 AND ISUP THEN BEGIN
开空B1:BUYSHORT( HOLDING=0 ,1,MARKETR);
mark:=1;
END
IF 平多条件 AND ISUP THEN BEGIN
平多2:=sell( holding=2*ss,2*ss,MARKETR);
平多1:=sell( holding=ss,1,MARKETR);
// mark:=0;
// END
//IF 开空条件 AND ISUP THEN BEGIN
开空B2:BUYSHORT( HOLDING=0 ,1,MARKETR);
mark:=1;
END
IF 平多条件 AND ISDOWN THEN BEGIN
平多2:=sell( holding=2*ss,2*ss,MARKETR);
平多1:=sell( holding=ss,1,MARKETR);
// mark:=1;
// END
//IF 开空条件 AND ISUP THEN BEGIN
开空B3:BUYSHORT( HOLDING=0 ,1,MARKETR);
mark:=1;
END
END
多头止损条件:=C<=ZS*AVGENTERPRICE;
空头止损条件:=C>=(2-ZS)*AVGENTERPRICE;
//*********************************************************************************************
IF HOLDING>0 AND 多头止损条件 THEN
BEGIN
多头止损:=SELL(多头止损条件,0,MARKETR);
反手开空:buyshort(holding=0 ,1,MARKETR);
// MARK:=-1;//重置全局变量为-1
END
IF HOLDING<0 AND 空头止损条件 THEN
BEGIN
空头止损:=SELLSHORT(空头止损条件,0,MARKETR);
反手开多D:buy(holding=0 ,1,MARKETR);
// MARK:=1;//重置全局变量为1
END
{if C>ENTERPRICE+ATR*2 then begin
多头波段止盈1:=sell(holding=10,10,marketr);
//多头波段止盈2:=sell(holding=2,1,marketr);
//多头波段止盈3:=sell(holding=ss,1,MARKETR);
MARK:=-1;
END
//if C>ENTERPRICE+ATR*2 then sellshort(holding<0,holding,THISCLOSE);
if C<ENTERPRICE-ATR*2 then begin
空头波段止盈1:=sellshort(holding=-10,10,marketr);
//空头波段止盈2:=sellshort(holding=-2,1,marketr);
//空头波段止盈3:=sellshort(holding=-1,1,marketr);
MARK:=1;
END
{//开平仓条件
CONKD:BARPOS>N2 AND C>VAR2 AND VAR2>VAR3 AND VAR8>0 AND VAR9>VAR10;
CONKK:BARPOS>N2 AND C<VAR2 AND VAR2<VAR3 AND VAR8<0 AND VAR9<VAR10;
CONPD:C<VAR2 AND C>ENTERPRICE*(1+0.03*N3);
CONPK:C>VAR2 AND C<ENTERPRICE*(1-0.03*N3);
//止损条件
DTZS:=C<ENTERPRICE*(1-0.03*N3);
KTZS:=C>ENTERPRICE*(1+0.03*N3);
//交易系统
SELL(HOLDING>0 AND CONPD,HOLDING,MARKET);
SELLSHORT(HOLDING<0 AND CONPK,HOLDING,MARKET);
BUY(HOLDING=0 AND CONKD,SS,MARKET);
BUYSHORT(HOLDING=0 AND CONKK,SS,MARKET);
SELL(HOLDING>0 AND DTZS,HOLDING,MARKET);
SELLSHORT(HOLDING<0 AND KTZS,HOLDING,MARKET);}
多头波段止盈条件:c>=(2-zy)*AVGENTERPRICE AND DIFF>15 AND 成交量L AND MARK>=0 ;
空头波段止盈条件:c<=zy*AVGENTERPRICE AND DIFF<-12 AND 成交量L AND MARK<=0;
多头波段止盈条件1:c>=(2-zy1)*AVGENTERPRICE AND DIFF>20 AND MARK>=0;
空头波段止盈条件1:c<=zy1*AVGENTERPRICE AND DIFF<-20 AND MARK<=0;
IF mc<=25 THEN BEGIN
A:=1;
if 多头波段止盈条件 AND 手数*1 then
begin
多头波段止盈:sell(holding=ss,1,MARKETR);
//反手开空5A:buyshort(holding=0,手数*2,MARKETR);
//mark:=-1;//重置全局变量为1
end
end
IF mc2<=25 THEN BEGIN
A:=-1;
if 空头波段止盈条件 AND 手数*1 AND ISDOWN then
begin
空头波段止盈:sellshort( holding=-ss, 1,MARKETR);
//反手开多E:buy(holding=0 ,手数*1,MARKETR);
//mark:=1;//重置全局变量为1
end
end
IF mc>25 THEN BEGIN
A:=-1;
if 多头波段止盈条件1 AND 手数*1 AND MC>25 then
begin
多头趋势止盈高1:sell(holding=ss,1,MARKETR);
//反手开空5A:buyshort(holding=0,手数*2,MARKETR);
//mark:=-1;//重置全局变量为1
end
if 多头波段止盈条件1 AND 手数*1 AND MC>25 then
begin
多头趋势止盈高1A:sell(holding=ss,1,MARKETR);
//反手开空5A:buyshort(holding=0,手数*2,MARKETR);
mark:=-1;//重置全局变量为1
end
end
IF mc2>25 THEN BEGIN
A:=1;
if 空头波段止盈条件1 AND 手数*1 AND MC2>25 then
begin
空头趋势止盈高2:sellshort( holding=-ss, 1,MARKETR);
//反手开多E:buy(holding=0 ,手数*1,MARKETR);
//mark:=1;//重置全局变量为1
end
if 空头波段止盈条件1 AND 手数*1 AND MC2>25 then
begin
空头趋势止盈高2A:sellshort( holding=-ss, 1,MARKETR);
//反手开多E:buy(holding=0 ,手数*1,MARKETR);
//mark:=1;//重置全局变量为1
end
end
//收盘前1分钟平仓模块}
abb1:=(timetot0(CLOSETIME(1))-timetot0(time));//夜盘收盘距离现在K的秒数AND TIME <145500
abb2:=(timetot0(CLOSETIME(0))-timetot0(time));//白盘收盘距离现在K的秒数
cd6:=(abb1<0.5*60 and abb1>=0);
cd7:=(abb2<1.2*60 and abb2>=0);
//*********************************************************************************************
if cd7 then
begin
收盘平多8:sell(holding=2*ss,2*ss,MARKETR);
收盘平空8:sellshort(holding=-2,2,marketr);
MARK:=0;//普通平仓情况下全局变量重置为0
end
if cd7 then
begin
收盘平多88:sell(holding=ss,1,MARKETR);
收盘平空88:sellshort(holding=-1,1,marketr);
MARK:=0;//普通平仓情况下全局变量重置为0
end
|
|