等级: 免费版
- 注册:
- 2021-8-13
- 曾用名:
|
楼主 |
发表于 2021-12-28 10:37
|
显示全部楼层
//中间变量
INPUT:M(50,5,300,30),N(1.25,0.1,10,0.1),D(30,1,100,1);
//
VARIABLE: zz:=0;
VARIABLE: ss:=1;
VARIABLE:X:=50;
CC:=ref(c,1);
MID : MA(CLOSE,M);//布林中轨
UPPER:MID + N*STD(CLOSE,M);//布林上轨
LOWER:MID - N*STD(CLOSE,M);//布林下轨
CYC:=ENTERBARS+1,NOAXIS;//开仓至今的周期数
HC30:=REF(HHV(C,D),1);//30周期收盘价高点
LC30:=REF(LLV(C,D),1);//30周期收盘价低点
IFMM:IF(HOLDING<>0,IF(CYC>=40,10,51-CYC),50)-1;
出场MA:MA(CLOSE,IF(HOLDING<>0,IF(CYC>=40,10,51-CYC),50)-1);
MA21:=MA(C,21);
//交易条件
开多平空条件:=C>HC30 AND H>REF(UPPER,1);//收盘价大于30周期收盘价最高值,且最高价上穿上轨
开空平多条件:=C<LC30 AND L<REF(LOWER,1);//收盘价小于30周期收盘价最高值,且最低价下穿下轨
多头出场条件:=C<出场MA AND 出场MA<UPPER;
空头出场条件:=C>出场MA AND 出场MA>LOWER;
pd3:=多头出场条件 AND HOLDING>0;
if ref(pd3,1) THEN
BEGIN
sell(1,holding,LIMITr,cc);
if NUMPROFIT(1)>0 then zz:=1;
if NUMPROFIT(1)<0 then zz:=zz+1;
end
pk4:=空头出场条件 AND HOLDING<0 ;
if ref(pk4,1) THEN
BEGIN
sellshort(1,holding,LIMITr,cc);
if NUMPROFIT(1)>0 then zz:=1;
if NUMPROFIT(1)<0 then zz:=zz+1;
end
pd5:=开空平多条件 and holding>0;
if ref(pd5,1) THEN
BEGIN
sell(1,holding,LIMITr,cc);
if NUMPROFIT(1)>0 then zz:=1;
if NUMPROFIT(1)<0 then zz:=zz+1;
end
pk6:=开多平空条件 and holding<0;
if ref(pk6,1) THEN
BEGIN
sellshort(1,holding,LIMITr,cc);
if NUMPROFIT(1)>0 then zz:=1;
if NUMPROFIT(1)<0 then zz:=zz+1;
end
if zz=1 then ss:=1;
if zz=2 then ss:=1;
if zz=3 then ss:=2;
if zz=4 then ss:=4;
if zz=5 then ss:=8;
if zz>=6 then ss:=16;
kd1:=开多平空条件 and HOLDING=0;
kk1:=开空平多条件 and HOLDING=0;
IF ref(KD1,1) and HOLDING=0 THEN BUY(1,ss,LIMITr,cc);
IF ref(KK1,1) and HOLDING=0 THEN BUYSHORT(1,ss,LIMITr,cc);
TH:HOLDING;
zzC:zz;
NRT:NUMPROFIT(1); |
|