你好,请教个问题:
我编写的系统在多数交易日信号都是没有问题的,信号都正常,但一个月总有那么两三天的开平仓是有问题的;如图所示,开仓信号是没问题的,但居然在当根K线就平了多仓(且随后又在当根K线开了空仓和平了空仓),我排查了很久都找不出原因,真怀疑是不是软件问题,烦请找出“平多仓”原因,因为本次“平多仓”行为在代码里根本找不到相关依据,谢谢。以下是源代码:
//此策略好多执行错误(没达到条件的居然开平仓),BUG日期:
//1月18号的开仓:平多仓有问题,及随后开空仓和平空仓有问题
//1月13号的开空仓有问题,以及根本就没有到达平仓位置就平仓了
//12月19号有问题
//这里n=0.6,m=60;
//函数定义
a1:=ref(hhv(high,m),1);
a2:=ref(llv(low,m),1);
//m分钟最高最低点
a3:=ref(hhv(high,todaybar),1);
a4:=ref(llv(low,todaybar),1);
//a3和a4是日内最高最低点
a6:=ref(hhv(high,todaybar),enterbars);
a7:=ref(llv(low,todaybar),enterbars);
//a6、a7是开仓时的日内最高最低点
a8:=a7-n*abs(a6-a7); //第一次做多止损
a9:=a6+n*abs(a6-a7); //第一次做空止损
//时间定义
t8:=time>=185800;
t1:=time<184500;
//做多条件
if holding=0 and todaybar>=m and high>=a1 and high>=a3 and totaldaytrade<1 and t1
then begin
buy(1,1,limitr,a3);
end
//做多止损
if holding>0 and totaldaytrade<1 and low<=a8
then begin
sell(1,0,limitr,a8);
end //第一次做多止损
if holding=0 and totaldaytrade>=1 and low<=a8 and t1
then begin
buyshort(1,1,limitr,a8);
end //反手做空
if holding<0 and totaldaytrade>=1 and high>=a3
then begin
sellshort(1,0,limitr,a3);
end //反手做空止损
//做空条件
if holding=0 and todaybar>=m and low<=a2 and low<=a4 and totaldaytrade<1 and t1
then begin
buyshort(1,1,limitr,a4);
end
//做空止损
if holding<0 and totaldaytrade<1 and high>=a9
then begin
sellshort(1,0,limitr,a9);
end //第一次做空止损
if holding=0 and totaldaytrade>=1 and high>=a9 and t1
then begin
buy(1,1,limitr,a9);
end //反手做多
if holding>0 and totaldaytrade>=1 and low<=a4
then begin
sell(1,0,limitr,a4);
end //反手做多止损
//收盘平仓
if holding>0 and t8
then begin
sell(1,0,market);
end
if holding<0 and t8
then begin
sellshort(1,0,market);
end