多头止盈:=h>ref(close,enterbars)*1.005 and enterbars>1;
多头止损:=l<ref(close,enterbars)*0.995 and enterbars>1;
空头止盈:=l<ref(close,enterbars)*0.995 and enterbars>1;
空头止损:=h>ref(close,enterbars)*1.005 and enterbars>1;
//********************交易系统*****提前n秒下单*******************************
input:tq(5,3,60,1);//定义变量
abb:=(time0-timetot0(dynainfo(207))<=tq) or not(islastbar);
if abb then begin
if holding=0 and 开多 then buy(1,1,thisclose),ignorecheckprice,orderqueue;
if holding=0 and 开空 then buyshort(1,1,thisclose),ignorecheckprice,orderqueue;
if holding>0 and 多头止损 then sell(1,1,thisclose),ignorecheckprice,orderqueue;
if holding<0 and 空头止损 then sellshort(1,1,thisclose),ignorecheckprice,orderqueue;
end
//***************************提前n秒下单**********************************
if abb then begin
if holding>0 and 多头止盈 then sell(1,1,thisclose),ignorecheckprice,orderqueue;//多头平仓
if holding<0 and 空头止盈 then sellshort(1,1,thisclose),ignorecheckprice,orderqueue;//空头平仓
end
此主题相关图片如下:2016-07-11_092649.png

因为k线图上同时出了开和平的信号,说明此时开平条件是同时满足的
因为代码里面的enterbars判断是写在开仓之前的,所以止损判断里面就变成了判断上一次开仓的周期而不是现在开仓的周期
直接把开仓周期判断,写在平仓语句里面,不要提前写
在改成这样才行吗?
多头止盈:=h>ref(close,enterbars)*1.005;
多头止损:=l<ref(close,enterbars)*0.995;
空头止盈:=l<ref(close,enterbars)*0.995;
空头止损:=h>ref(close,enterbars)*1.005;
多头止盈:=h>ref(close,enterbars)*1.005 and enterbars>1;
多头止损:=l<ref(close,enterbars)*0.995 and enterbars>1;
空头止盈:=l<ref(close,enterbars)*0.995 and enterbars>1;
空头止损:=h>ref(close,enterbars)*1.005 and enterbars>1;
//********************交易系统*****提前n秒下单*******************************
input:tq(5,3,60,1);//定义变量
abb:=(time0-timetot0(dynainfo(207))<=tq) or not(islastbar);
if abb then begin
if holding=0 and 开多 then buy(1,1,thisclose),ignorecheckprice,orderqueue;
if holding=0 and 开空 then buyshort(1,1,thisclose),ignorecheckprice,orderqueue;
if holding>0 and 多头止损 and enterbars>1 then sell(1,1,thisclose),ignorecheckprice,orderqueue;
if holding<0 and 空头止损 and enterbars>1 then sellshort(1,1,thisclose),ignorecheckprice,orderqueue;
end
//***************************提前n秒下单**********************************
if abb then begin
if holding>0 and 多头止盈 and enterbars>1 then sell(1,1,thisclose),ignorecheckprice,orderqueue;//多头平仓
if holding<0 and 空头止盈 and enterbars>1 then sellshort(1,1,thisclose),ignorecheckprice,orderqueue;//空头平仓
end