我给过你类似的模型,结果不好。再有为什么要限制交易次数?这在策略设计时是没有道理的。
variable:a1=0;
r1:=barslast(day-ref(day,1)<>0);
r2:ref(o,r1);
r3:r2+10;
r4:r2-10;
r5:=time>091500 and time<151000;
if cross(h,r2) and r5 and holding=0 and a1=0 then
begin
buy(1,1,limitr,r3)
end
if cross(r4,l) and r5 and holding=0 and a1=0 then
begin
buyshort(1,1,limitr,r4);
end
if holding>0 and cross(r4,l) and r5 then
begin
sell(1,0,limitr,r4);
a1:=1;
end
if holding<0 and cross(h,r3) and r5 then
begin
sellshort(1,0,limitr,r3);
a1:=1;
end
if time>=151000 and holding<>0 then
begin
sell(holding>0,0,thisclose);
sellshort(holding<0,0,thisclose);
a1:=1;
end
以上的代码用于测试,实际交易时用如下代码:
variable:a1=0;
r1:=barslast(day-ref(day,1)<>0);
r2:ref(o,r1);
r3:r2+10;
r4:r2-10;
r5:=time>091500 and time<151000;
if cross(c,r2) and r5 and holding=0 and a1=0 then
begin
buy(1,1,limitr,r3)
end
if cross(r4,c) and r5 and holding=0 and a1=0 then
begin
buyshort(1,1,limitr,r4);
end
if holding>0 and cross(r4,c) and r5 then
begin
sell(1,0,limitr,r4);
a1:=1;
end
if holding<0 and cross(c,r3) and r5 then
begin
sellshort(1,0,limitr,r3);
a1:=1;
end
if time>=151000 and holding<>0 then
begin
sell(holding>0,0,thisclose);
sellshort(holding<0,0,thisclose);
a1:=1;
end
以上代码没有测试,估计不会有大问题,