当根K线收盘价大于前一K线收盘价3%(找出涨幅>3%的K棒),后市若价格继续上涨1%,则开多单,若行情不再继续上涨,没达到开多条件,回调至上涨3% K棒的50%处,吞掉一半涨幅,则开空单
当根K线收盘价小于前一K线收盘价3%(找出跌幅>3%的K棒),后市若价格继续下跌1%,则开空单,若行情不再继续下跌,没达到开空条件,反弹至下跌3% K棒的50%处,吞掉一半跌幅,则开多单
多单 动态跟踪回撤止损= 开仓后的最高收盘价向下回撤1.5%时止损
(如开多后当根K棒收盘价在10元,止损设在10元向下回撤1.5%处,下根K棒收盘价10.8元,则以新高收盘价10.8元向下回撤1.5%设为止损价,若后期收盘价创新高,则继续以新高收盘价向下回测1.5%设止损)
空单 动态跟踪回撤止损= 开仓后的最低收盘价向上反弹1.5%时止损
请老师帮忙编写公式模型,涨跌幅度,止损幅度修改方便,便于做测试
VARIABLE:bj=0;
nn1:=barslast((c-ref(c,1))/ref(c,1)>=0.03);
nn2:=barslast((ref(c,1)-c)/ref(c,1)>=0.03);
if (c-ref(c,1))/ref(c,1)>=0.03 then bj:=1;
if (ref(c,1)-c)/ref(c,1)>=0.03 then bj:=-1;
if bj=1 and nn1>0 and (c-ref(c,1))/ref(c,1)>0.01 then buy(holding=0,1,marketr);
if bj=1 and nn1>0 and c<=ref(ref(c,1)*1.015,nn1) then buyshort(holding=0,1,marketr);
if bj=-1 and nn2>0 and (ref(c,1)-c)/ref(c,1)>0.01 then buyshort(holding=0,1,marketr);
if bj=-1 and nn2>0 and c>-ref(ref(c,1)*0.985,nn2) then buy(holding=0,1,marketr);
if holding>0 and c<=hhv(h,enterbars+1)*1.015 then sell(1,0,marketr);
if holding<0 and c>=llv(l,enterbars+1)*0.985 then sellshort(1,0,marketr);