if c>enterprice*(1+0.05) then sell(1,0,marketr);
if c<enterprice*(1-0.05) then sell(1,0,marketr);以上是现有的平仓策略
现在想改成隔天平仓,当天不平仓不新开仓。
隔天开盘价超过平仓价(超过止盈止损位),则开盘平仓。否则继续执行原来的平仓策略。
h1:=ref(holding,todaybar);
if c>enterprice*(1+0.05)and ref(holding,todaybar)>0 then sell(1,h1marketr);
if c<enterprice*(1-0.05) and ref(holding,todaybar)>0 then sell(1,h1,marketr);
我拿这个替换我原来的平仓策略以后,
测试的时候从几百次交易变成只有一次交易了,从第一次开仓然后持有到最后一天平仓,问题在哪里呢?
variable:n=0;
if isup then n:=n+1;
if isdown then n:=0;
if n>=3 then buy(holding=0,1,market);
if c>enterprice*(1+0.05) then sell(1,0,marketr);
if c<enterprice*(1-0.05 then sell(1,0,marketr);
if time=closetime(0) then begin
k:=0;
m:=0;
end
variable:n=0;
if isup then n:=n+1;
if isdown then n:=0;
if n>=3 then buy(holding=0,1,market);
if c>enterprice*(1+0.05) then sell(1,0,marketr);
if c<enterprice*(1-0.05) then sell(1,0,marketr);
if time=closetime(0) then begin
k:=0;
m:=0;
variable:n=0;
if isup then n:=n+1;
if isdown then n:=0;
if n>=3 then buy(holding=0,1,market);
if c>enterprice*(1+0.05) then sell(1,0,marketr);
if c<enterprice*(1-0.05) then sell(1,0,marketr);
if time=closetime(0) then begin
k:=0;
m:=0;
end