5分钟周期固定时间间隔(1秒)模式下的止盈操作有本根k线内被触发的危险。程序段落如下:
//开空
if 开空条件 then begin
buyshort(1,ss,thisclose);
stopLossPrice:=preHigh;
buyBar:=1;
end
//平空
if holding<0 and buyBar=0 then begin
if (enterprice-l)>2*ATR and gainLock=0 then begin
stopGainPrice := enterprice-0.5*ATR;
gainLock:=1;
end
myExitPrice:= if(平空条件,close,if(gainLock,stopGainPrice,stopLossPrice));
sellshort(h>myExitPrice,ss,limitr,myExitPrice);
end
问题是这里的l 和h, 在图表上和调试中, 是5分钟k线的,而非1秒钟轮询周期的,所以(enterprice-l)>2*ATR 和 h>myExitPrice 将在本根k线中被同时满足,阴线再长也将触发止盈。(实测中没有这个问题)。如何解决?
那么可以在止盈条件里面加上:and enterbars>0。这样就能避免同根k线出信号了
这样的话,在enterbars=0 这根K线上,止盈或止损是无效的,如果出现长长的上下影线,将蒙受很大的损失。固定时间间隔(1秒)模式下,有无可能在同一根k线上,同时按1秒钟的间隔开仓并止损/止盈?
那么只能是上面的结果了,调试时有交易,实际上是没有交易,图表上不能判断同根k线上的行情升降先后