想要把多个策略写在一起,会用到开平仓历时函数,但组合在一起需要各个策略各自计算自己的开平仓历时,自己怎么用代码来表示enterbars和exitbars呢?
谢谢!
我自己写了下列代码,就是不行:
phold:=ref(hold,1); //hold
r10:BARSLAST(phold=0 and hold<>0),LINETHICK0;//开仓历时
er10:BARSLAST(phold<>0 and hold=0),LINETHICK0;//平仓历时
hold是这么计算的:
if 平多 and phold>0 then hold:=0;
if 平空 and phold<0 then hold:=0;
if 开多 and phold=0 then hold:=1;
if 开空 and phold=0 then hold:=-1;
请问,有什么问题吗?
可以,将你的hold定义为一个全局变量
先用两个策略组合起来尝试
可以,将你的hold定义为一个全局变量
先用两个策略组合起来尝试
不行啊,开仓历时和平仓历时就是不正确啊!!
组合在一起,各个策略就无法用到enterbars了
策略写在一起?holding怎么判断的?
holding不判断可以这么写
nn1:barslast(下单条件1)+1;
nn2:barslast(下单条件2)+1;
nn3:barslast(下单条件3)+1;
nn4:barslast(下单条件4)+1;
kk1:barslast(平仓条件1)+1;
kk2:barslast(平仓条件2)+1;
kk3:barslast(平仓条件3)+1;
kk4:barslast(平仓条件4)+1;