-- 作者:Ritter
-- 发布时间:2020/11/24 13:50:21
-- 图表转后台的问题
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);
请问老师,后台代码这样表述正确吗??
目前遇到的问题:回测时,平仓信号与图表大部分不一致,偶尔也会一致,不知道是什么原因导致的。
|
-- 作者:Ritter
-- 发布时间:2020/11/24 15:22:37
--
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
开仓逻辑是正确的,问题出在平仓语句上;
麻烦老师帮忙把这段语句更改为后台语句,非常感谢!!
|
-- 作者:FireScript
-- 发布时间:2020/11/24 15:45:36
--
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,tenterbars+2);//tenterbars从-1开始,必须+2.否则可能会取到所以K的最高价 CS:=LLV(L,tenterbars+2);
IF (ZG-TAVGENTERPRICEEX2(\'\',\'\',0))/TAVGENTERPRICEEX2(\'\',\'\',0)>=ZY*0.2 AND C<TAVGENTERPRICEEX2(\'\',\'\',0) THEN BEGIN tSELL(1,0,LMT,c); END IF (TAVGENTERPRICEEX2(\'\',\'\',1)-CS)/CS>=ZY*0.2 AND C>TAVGENTERPRICEEX2(\'\',\'\',1) THEN BEGIN tSELLSHORT(1,0,LMT,c); END
if (zg-TAVGENTERPRICEEX2(\'\',\'\',0))/TAVGENTERPRICEEX2(\'\',\'\',0)>=ZY*0.4 and (C-TAVGENTERPRICEEX2(\'\',\'\',0))<=(zg-TAVGENTERPRICEEX2(\'\',\'\',0))*0.5 then begin tSELL(1,0,LMT,c); END if (TAVGENTERPRICEEX2(\'\',\'\',1)-CS)/CS>=ZY*0.4 and (TAVGENTERPRICEEX2(\'\',\'\',1)-C)<=(TAVGENTERPRICEEX2(\'\',\'\',1)-CS)*0.5 then begin tSELLSHORT(1,0,LMT,c); End
if (zg-TAVGENTERPRICEEX2(\'\',\'\',0))/TAVGENTERPRICEEX2(\'\',\'\',0)>=ZY*0.6 and (C-TAVGENTERPRICEEX2(\'\',\'\',0))<=(zg-TAVGENTERPRICEEX2(\'\',\'\',0))*0.6 then begin tSELL(1,0,LMT,c); END if (TAVGENTERPRICEEX2(\'\',\'\',1)-CS)/CS>=ZY*0.6 and (TAVGENTERPRICEEX2(\'\',\'\',1)-C)<=(TAVGENTERPRICEEX2(\'\',\'\',1)-CS)*0.6 then begin tSELLSHORT(1,0,LMT,c); End
if (zg-TAVGENTERPRICEEX2(\'\',\'\',0))/TAVGENTERPRICEEX2(\'\',\'\',0)>=ZY*0.8 and (C-TAVGENTERPRICEEX2(\'\',\'\',0))<=(zg-TAVGENTERPRICEEX2(\'\',\'\',0))*0.7 then begin tSELL(1,0,LMT,c); END if (TAVGENTERPRICEEX2(\'\',\'\',1)-CS)/CS>=ZY*0.8 and (TAVGENTERPRICEEX2(\'\',\'\',1)-C)<=(TAVGENTERPRICEEX2(\'\',\'\',1)-CS)*0.7 then begin tSELLSHORT(1,0,LMT,c); End
if (zg-TAVGENTERPRICEEX2(\'\',\'\',0))/TAVGENTERPRICEEX2(\'\',\'\',0)>=ZY and (C-TAVGENTERPRICEEX2(\'\',\'\',0))<=(zg-TAVGENTERPRICEEX2(\'\',\'\',0))*0.8 then begin tSELL(1,0,LMT,c); END if (TAVGENTERPRICEEX2(\'\',\'\',1)-CS)/CS>=ZY and (TAVGENTERPRICEEX2(\'\',\'\',1)-C)<=(TAVGENTERPRICEEX2(\'\',\'\',1)-CS)*0.8 then begin tSELLSHORT(1,0,LMT,c); End
tSELL(TAVGENTERPRICEEX2(\'\',\'\',0)-c>c*ZS and TBUYHOLDINGEX(\'\',\'\',1)>0 ,0,LMT,c);//多单止损 tSELLSHORT(c-TAVGENTERPRICEEX2(\'\',\'\',1)>c*ZS and TSELLHOLDINGEX(\'\',\'\',1)>0 ,0 ,LMT,c);//空单止损
IF BULL AND B_COND AND BVOL THEN BEGIN tSELLSHORT(1,0,LMT,c); tBUY(TBUYHOLDINGEX(\'\',\'\',1)=0,CW%,LMT,c),PERTRADER; END
IF BEAR AND S_COND AND SVOL THEN BEGIN tSELL(1,0,LMT,c); tBUYSHORT(TSELLHOLDINGEX(\'\',\'\',1)=0,CW%,LMT,c),PERTRADER; END
供参考。
|