IF TIME=CLOSETIME(0) THEN NUM:=0;
5分K线上,一直没有恢复0?导致后继无开仓。
是最后一条语句,却一直无法恢复。
input:n(4,1,100,1),K1(0.7,0.1,1,0.1),k2(0.7,0.1,1,0.1),nmin(50,1,100,1),ss(4,1,100,1);
variable:num=0;
CYC:=barslast(date<>ref(date,1))+1;
昨高:=callstock(stklabel,vthigh,6,-1);
昨低:=callstock(stklabel,vtlow,6,-1);
昨收:=callstock(stklabel,vtclose,6,-1);
开盘价:=valuewhen(cyc=1,open);
HH:=hhv(昨高,n);//N日high的最高价
HC:=hhv(昨收,n);//N日close的最高价
LC:=LLV(昨收,n);//N日close的最低价
LL:=LLV(昨低,n);//N日low的最低价
浮动区间:=max(HH-LL,HC-LL);//range
上轨:开盘价+k1*浮动区间;
下轨:开盘价-K2*浮动区间;
t1:=time>opentime(1) and time<closetime(0)-nmin*100;
t2:=time>=closetime(0)-nmin*100;
手数:=ss;
//交易条件 www.cxh99.com
开多条件:=c>上轨 and holding=0;
开空条件:=c<下轨 and holding=0;
if holding>0 then
begin
zyp:=enterprice*1.02;
zsp:=enterprice*0.99;
cdy:=h>zyp;
cds:=l<zsp;
多盈:sell(cdy,手数,marketr),linethick0;
多损:sell(cds,手数,marketr),linethick0;
//num:=1;
end;
if holding<0 then
begin
zyp:=enterprice*0.98;
zsp:=enterprice*1.01;
cdy:=l<zyp;
cds:=h>zsp;
空盈:sellshort(cdy,手数,marketr),linethick0;
空损:sellshort(cds,手数,marketr),linethick0;
//num:=1;
end;
//交易系统
if holding=0 then
begin
开多:buy(开多条件 and t1 and cyc>1 and num<1,手数,market);
开空:buyshort(开空条件 and t1 and cyc>1 and num<1,手数,market);
num:=1;
end;
收盘平多:sell(t2,手数,market);
收盘平空:sellshort(t2,手数,market);
IF TIME>CLOSETIME(0) THEN
begin
num:=0;
end;
Nu:num,linethick0;
TIME>CLOSETIME(0) 改成 TIME>=CLOSETIME(0)
或者直接改成= 也行。 time值肯定不会大于CLOSETIME(0)的。
最早,用time=closetime(0),没用
后改为time>closetime(0)-1000,也改为time>closetime(0)-500,都不起作用。我也搞不清怎么回事。
因为还有个问题。
if holding=0 then
begin
开多:buy(开多条件 and t1 and cyc>1 and num<1,手数,market);
开空:buyshort(开空条件 and t1 and cyc>1 and num<1,手数,market);
num:=1;
end;
只要仓位是0 num总会在当日第一个K被重设为1
你应该这样:
if 开多条件 and holding=0 then
begin
开多:buy(开多条件 and t1 and cyc>1 and num<1,手数,market);
num:=1;
end
开空也是这样的。