INPUT:ZY(0.03,0.01,0.09,0.005),ZS(0.009,0.001,0.02,0.001);
IF BULL AND B_COND AND BVOL THEN BEGIN
TSELLSHORT(1,0,LMT,C);
TBUY(THOLDING=0,CW%,LMT,C),PERTRADER;
END
zg:=hhv(h,TENTERBARS+1);
IF (ZG-TAVGENTERPRICE)/TAVGENTERPRICE>=ZY*0.2 AND C<TAVGENTERPRICE THEN BEGIN
TSELL(1,0,LMT,C);
END
if (zg-TAVGENTERPRICE)/TAVGENTERPRICE>=ZY*0.4 and (C-TAVGENTERPRICE)<=(zg-TAVGENTERPRICE)*0.5 then begin
TSELL(1,0,LMT,C);
END
多单止损:=TSELL(TAVGENTERPRICE-c>c*ZS and THOLDING>0 ,0,LMT,C);
请问老师,后台代码这样表述正确吗??
目前遇到的问题:回测时,平仓信号与图表大部分不一致,偶尔也会一致,不知道是什么原因导致的。
如图所示:出现提前平仓,后续多开仓的情况。
1.思路完全一致,无更改,只修改了后台代码和交易指令;
2.数据量也是完全一致的;
3.两个回测机制略有差错可以理解,但是,后台回测下来,没有按照指令去实现平仓,开仓是符合逻辑的;
4.更改为TAVGENTERPRICEEX2(0),错误提示:所调用的参数与预定义参数不符。
BULL:=(C>DJX AND N1=1) OR (C>XJX AND N3=1);
BEAR:=(C<GJX AND N2=1) OR (C<SJX AND N4=1);
BVOL:=C>O AND VOL>VA1 AND VOL>VA2 AND VOL>VA3;
SVOL:=C<O AND VOL>VA1 AND VOL>VA2 AND VOL>VA3;
B_COND:=C>REF(YL,1) OR ( CROSS(C,A4) AND CD6 ) OR (CROSS(C,BF) AND CD2);
S_COND:=C<REF(ZC,1) OR ( CROSS(A3,C) AND CD8 ) OR (CROSS(BG,C) AND CD4);
zg:=hhv(h,enterbars+1);
CS:=LLV(L,ENTERBARS+1);
IF (ZG-AVGENTERPRICE)/AVGENTERPRICE>=ZY*0.2 AND C<AVGENTERPRICE THEN BEGIN
SELL(1,0,limitr,c);
END
IF (AVGENTERPRICE-CS)/CS>=ZY*0.2 AND C>AVGENTERPRICE THEN BEGIN
SELLSHORT(1,0,limitr,c);
END
if (zg-avgenterprice)/avgenterprice>=ZY*0.4 and (C-avgenterprice)<=(zg-avgenterprice)*0.5 then begin
sell(1,0,limitr,c);
END
if (avgenterprice-CS)/CS>=ZY*0.4 and (avgenterprice-C)<=(avgenterprice-CS)*0.5 then begin
sellshort(1,0,limitr,c);
End
if (zg-avgenterprice)/avgenterprice>=ZY*0.6 and (C-avgenterprice)<=(zg-avgenterprice)*0.6 then begin
sell(1,0,limitr,c);
END
if (avgenterprice-CS)/CS>=ZY*0.6 and (avgenterprice-C)<=(avgenterprice-CS)*0.6 then begin
sellshort(1,0,limitr,c);
End
if (zg-avgenterprice)/avgenterprice>=ZY*0.8 and (C-avgenterprice)<=(zg-avgenterprice)*0.7 then begin
sell(1,0,limitr,c);
END
if (avgenterprice-CS)/CS>=ZY*0.8 and (avgenterprice-C)<=(avgenterprice-CS)*0.7 then begin
sellshort(1,0,limitr,c);
End
if (zg-avgenterprice)/avgenterprice>=ZY and (C-avgenterprice)<=(zg-avgenterprice)*0.8 then begin
sell(1,0,limitr,c);
END
if (avgenterprice-CS)/CS>=ZY and (avgenterprice-C)<=(avgenterprice-CS)*0.8 then begin
sellshort(1,0,limitr,c);
End
多单止损:=sell(avgenterprice-c>c*ZS and holding>0 ,0,limitr,c);
空单止损:=sellshort(c-avgenterprice>c*ZS and holding<0 ,0 ,limitr,c);
IF BULL AND B_COND AND BVOL THEN BEGIN
SELLSHORT(1,0,limitr,c);
BUY(HOLDING=0,CW%,limitr,c);
END
IF BEAR AND S_COND AND SVOL THEN BEGIN
SELL(1,0,limitr,c);
BUYSHORT(HOLDING=0,CW%,limitr,c);
END
开仓逻辑是正确的,问题出在平仓语句上;
麻烦老师帮忙把这段语句更改为后台语句,非常感谢!!