下面策略没信号,辛苦修改一下。
策略思路:
1 上穿20曰线平空开多,下穿20日线平多开空
2 上穿20日线开多后,再次上穿60日线,这持有多单,只能在下穿60日线平多(小级别建仓,大级别平仓)
2 下穿20日线开空后,再次下穿60日线,这持有空单,只能在上穿60日线平空(小级别建仓,大级别平仓)
3 止盈和止损,两种条件holding<0 and h>=min(enterprice+zsx,kstop1) 和holding>0 and l<=max(enterprice-zsx,dstop1)
input:p(10,1,200,1);
input:length(10,10,120,10);
input:zs(3,1,10,1);
input:k1(5,1,15,1);
variable:cc = 0;
variable:exitprice1= 0;
variable:enterprice1= 0 ;
line1:ref(ma(close,20),1);
line2:ref(ma(close,120),1);
tr1 :=max(max((high-low),abs(ref(close,1)-high)),abs(ref(close,1)-low));
atr:=ma(tr1,length);
zsx:=ifelse(zs*ref(atr,1)<0.02*ref(c,1),0.02*ref(c,1),zs*ref(atr,1));
enterbars1:=enterbars+1;
dstop1:=hhv(h,enterbars1)-k1*ref(atr,1);//平多价
kstop1:=llv(l,enterbars1)+k1*ref(atr,1);//平空价
long1:=cross(h,line1);
short1:=cross(line1,l);
long2:=cross(h,line2);
short2:=cross(line2,l);
if holding<0 and cc=-2 then sellshort(1,p,limitr,exitprice1),ignorecheckprice;
if holding<0 and cc=-1 then sellshort(1,p,limitr,exitprice1),ignorecheckprice;
if holding=0 and cc=0 then buy(1,p,limitr ,enterprice1),ignorecheckprice;
if holding>0 and cc=2 then sell(1,p,limitr,exitprice1),ignorecheckprice;
if holding>0 and cc=1 then sell(1,p,limitr,exitprice1),ignorecheckprice;
if holding=0 and cc=0 then buyshort(1,p,limitr,enterprice1),ignorecheckprice;
if holding<0 and cc=-2 and long2 then begin
exitprice1:=h+mindiff;
cc:=0;
end
if holding<0 and cc=-1 and short2 then cc:=-2;
if holding<0 and cc=-1 and long1 then begin
exitprice1:=h+mindiff;
cc:=0;
end
if holding>0 and cc=2 and short2 then begin
exitprice1:=l-mindiff;
cc:=0;
end
if holding>0 and cc=1 and long2 then cc:=2;
if holding>0 and cc=1 and short1 then begin
exitprice1:=l-mindiff;
cc:=0;
end
if holding=0 and long1 and cc=0 then begin
enterprice1:=h+mindiff;
cc:=1;
end
if holding=0 and short1 and cc=0 then begin
enterprice1:=l+mindiff;
cc:=-1;
end
if holding<0 and h>=min(enterprice+zsx,kstop1) and cc<0 then begin
exitprice1:=min(enterprice+zsx,kstop1)+mindiff;
cc:=0;
end
if holding>0 and l<=max(enterprice-zsx,dstop1) and cc>0 then begin
exitprice1:=max(enterprice-zsx,dstop1)-mindiff;
cc=0;
end
,limitr ,enterprice1
开仓下单价格是这样写的,
enterprice1的初值是0,所以问题是,用0的价格下单要表达什么意思?
但是你的条件写的简单,还没有上下穿就触发了,导致了下单价格是0
所以这个下单价格为0你是要表达什么意思?
if holding=0 and cc=0 then buy(1,p,limitr ,enterprice1),ignorecheckprice;
你的下单语句是这样写的,cc的初值是0,没持仓时holding也是0,那么就是第一根k就满足了开仓条件,然后以0的价格下单
我明白你的意思,怎样编写,才能实现策略思路?
策略思路:
1 上穿20曰线平空开多,下穿20日线平多开空
2 上穿20日线开多后,再次上穿60日线,这持有多单,只能在下穿60日线平多(小级别建仓,大级别平仓)
2 下穿20日线开空后,再次下穿60日线,这持有空单,只能在上穿60日线平空(小级别建仓,大级别平仓)
3 止盈和止损,两种条件holding<0 and h>=min(enterprice+zsx,kstop1) 和holding>0 and l<=max(enterprice-zsx,dstop1)
1 就是小级别建仓后,满足大级别建仓条件,只能按大级别平仓条件平仓,不再按小级别条件平仓
2 小级别建仓后,不满足大级别建仓条件,按小级别条件平仓.