随便找个开仓条件作为首次开仓,接下来,按照高点回落(低点回升)6%幅度平仓并且反向,这个怎么实现呢 ?
参考以下代码的思路:
buy(TODAYBAR=1 and holding=0,1,market);
hv:hhv(c,ENTERBARS+1);//仅以收盘价计算持仓后的最高点,也可以改成最高价
cd1:hv>AVGENTERPRICE and (hv-c)/hv>=0.06;
if cd1 and holding>0 then
begin
sell(1,holding,market);
buyshort(holding=0,1,market);
END
lv:llv(c,ENTERBARS+1);//仅以收盘价计算持仓后的最低点,也可以改成最低价
cd2:=lv<AVGENTERPRICE and (c-lv)/lv>=0.06;
if cd2 and holding<0 then
begin
sellshort(1,holding,market);
buy(holding=0,1,market);
END