//用全局变量,实现次周期恢复持仓功能,供参考
buycond:=ref(count(c>o,2)=2,1);
sellcond:=ref(count(c<o,2)=2,1);
if holding>0 and sellcond and not(islastbar) then sell(1,1,marketr);
if holding<0 and buycond and not(islastbar) then sellshort(1,1,marketr);
if buycond and holding=0 and not(islastbar) then
begin
buy(1,1,marketr);
end
if holding=0 and sellcond and not(islastbar) then buyshort(1,1,marketr);
if islastbar and tholding2<>holding then
begin
if barpos=EXTGBDATA('kai')+1 then//开仓信号消失,平仓恢复仓
begin
sell(tholding2>0,1,marketr);
sellshort(tholding2<0,1,marketr);
EXTGBDATASET( 'kai',0);
end
if barpos=EXTGBDATA('ping')+1 then//平仓信号消失,开仓恢复仓
begin
buy(holding>0,1,marketr);
buyshort(holding<0,1,marketr);
EXTGBDATASET( 'ping',0);
end
end
if holding>0 and sellcond and islastbar then
begin
sell(1,1,marketr);
EXTGBDATASET( 'ping',BARPOS);
end
if holding<0 and buycond and islastbar then
begin
sellshort(1,1,marketr);
EXTGBDATASET( 'ping',BARPOS);
end
//全局变量BAR,信号消失一根K线上也只开一次仓
if ISLASTBAR AND buycond and barpos>EXTGBDATA('kai') and holding=0 then
begin
buy(1,1,marketr);
EXTGBDATASET( 'kai',BARPOS);
end
if ISLASTBAR AND sellcond and barpos>EXTGBDATA('kai') and holding=0 then
begin
buyshort(1,1,marketr);
EXTGBDATASET( 'kai',BARPOS);
end
这是之前老师写的代码,需要怎样修改呢
实际持仓 与理论同步
在程序里面写入,程序走完一根K先,自动检测,实际持仓与理论是否同步