//交易系统
temp_ll:=llv(l,2);
if buycond and not(islastbar) then
begin
sellshort(holding<0,ss,marketr);
buy(holding=0,ss,marketr);
ll:=temp_ll;
end
bstop:=l<ll-1*MINDIFF;
if enterbars>0 and bstop and holding>0 and not(islastbar) then sell(1,ss,marketr);//止损止盈,实时出场
if h>valuewhen(bstop,hhv(fh,4))and bifx=1 and holding=0 and not(islastbar) then buy(1,ss,marketr);
if sellcond and not(islastbar) and holding>0 then sell(1,ss,marketr);
temp_hh:=hhv(h,2);
if sellcond and not(islastbar) then
begin
sell(holding>0,ss,marketr);
buyshort(holding=0,ss,marketr);
hh:=temp_hh;
end
sstop:=h>hh+1*MINDIFF;
if enterbars>0 and sstop and holding<0 and not(islastbar) then sellshort(1,ss,marketr);
if l<valuewhen(sstop,llv(fl,4)) and bifx=-1 and holding=0 and not(islastbar) then buyshort(1,ss,marketr);
if buycond and not(islastbar) and holding<0 then sellshort(1,ss,marketr);
//自动恢复持仓功能
if islastbar and tholding2<>holding then
begin
if barpos=EXTGBDATA('kai')+1 then//开仓信号消失 平仓
begin
sell(tholding2>0,ss,marketr);
sellshort(tholding2<0,ss,marketr);
EXTGBDATASET( 'kai',0);
end
if barpos=EXTGBDATA('ping')+1 then//平仓信号消失 开仓恢复
begin
buy(holding>0,ss,marketr);
buyshort(holding<0,ss,marketr);
EXTGBDATASET( 'ping',0);
end
end
if holding>0 and sellcond and islastbar then
begin
sell(1,ss,marketr);
EXTGBDATASET( 'ping',BARPOS);
end
if holding<0 and buycond and islastbar then
begin
sellshort(1,ss,marketr);
EXTGBDATASET( 'ping',BARPOS);
end
temp_ll:=llv(l,2);
if buycond and not(islastbar) then
begin
sellshort(holding<0,ss,marketr);
buy(holding=0,ss,marketr);
ll:=temp_ll;
end
bstop:=l<ll-1*MINDIFF;
if enterbars>0 and bstop and holding>0 and not(islastbar) then sell(1,ss,marketr);//止损止盈,实时出场
if h>valuewhen(bstop,hhv(fh,4))and bifx=1 and holding=0 and not(islastbar) then buy(1,ss,marketr);
if sellcond and not(islastbar) and holding>0 then sell(1,ss,marketr);
与后面同步持仓(次周期交易),应该使用not(islastbar)?
NOT(ISLASTBAR) //你这个只能用走完K线模式,固定时间间隔当前K线不会存在信号的。
另外我看你止损止盈又是实时出场
你现在是要实现?
你2楼的代码是用来当前交易的段落,还是处理历史交易信号的
建议类似代码用户可以加上些注释来方便工作人员理解,毕竟直接读源代码也是一件累事
if enterbars>0 and bstop and holding>0 and not(islastbar) then sell(1,ss,marketr);//止损,实时出场
if h>valuewhen(bstop,hhv(fh,4))and bifx=1 and holding=0 and not(islastbar) then buy(1,ss,marketr);//突破次周期交易
if sellcond and not(islastbar) and holding>0 then sell(1,ss,marketr);//止盈次周期
//自动恢复持仓功能
if islastbar and tholding2<>holding then
begin
if barpos=EXTGBDATA('kai')+1 then//开仓信号消失 平仓
begin
sell(tholding2>0,ss,marketr);
sellshort(tholding2<0,ss,marketr);
EXTGBDATASET( 'kai',0);
end
if barpos=EXTGBDATA('ping')+1 then//平仓信号消失 开仓恢复
begin
buy(holding>0,ss,marketr);
buyshort(holding<0,ss,marketr);
EXTGBDATASET( 'ping',0);
end
end
if holding>0 and sellcond and islastbar then
begin
sell(1,ss,marketr);
EXTGBDATASET( 'ping',BARPOS);
end
if holding<0 and buycond and islastbar then
begin
sellshort(1,ss,marketr);
EXTGBDATASET( 'ping',BARPOS);
end
实盘不执行持仓同步