单独运行上面的代码,单独执行也没有你说的现象存在。除非你本地的修改后的策略存在逻辑错误。(建议你完整排查自己本地策略中牵扯到extgbdataset函数处理的部分呢)
注:针对账户权益的代码,本身不需要区分多空方向。直接独立成一个策略进行运行即可。也有利于策略管理。
下面是增加带日志以及合并处理的逻辑,建议你参照测试后使用。
[PEL] 复制代码 as1:=extgbdata(taccount( 1));//记录资产的全局变量
dt:=extgbdata(taccount( 1)+'_date');//记录数据更新日期的全局变量
isclear:=extgbdata(taccount( 1)+'_isclear');//标记是否应该清仓的全局变量
if tholdcount('')=0 then //如果没有持仓了,清空掉之前的数据
begin
extgbdataset(taccount( 1),0);
DEBUGFILE('D:\bbb.TXT','位置1='& NUMTOSTR(extgbdata(taccount( 1)),2),1);
extgbdataset(taccount( 1)+'_date',date);//记录数据更新的日期
extgbdataset(taccount( 1)+'_isclear',0); //隔日后清仓标记也重置掉
end
//更新到最新日期的数据,用来处理隔日的问题
if date>dt and tholdcount('')>0 then
begin
extgbdataset(taccount( 1),taccount( 6));
DEBUGFILE('D:\bbb.TXT','位置2='& NUMTOSTR(extgbdata(taccount( 1)),2),1);
extgbdataset(taccount( 1)+'_date',date);//记录数据更新的日期
extgbdataset(taccount( 1)+'_isclear',0); //隔日后清仓标记也重置掉
end
//始终记录最大的动态权益
if tholdcount('')>0 and taccount( 6)>as1 and isclear=0 then
begin
extgbdataset(taccount( 1),taccount( 6));
DEBUGFILE('D:\bbb.TXT','位置3='& NUMTOSTR(extgbdata(taccount( 1)),2),1);
extgbdataset(taccount( 1)+'_date',date);//记录数据更新的日期
end
as1:=extgbdata(taccount( 1));
//回撤逻辑在这里调整即可
if as1-taccount( 6)>5000 and tholdcount('')>0 and isclear=0 then
begin
extgbdataset(taccount( 1)+'_isclear',1);
DEBUGFILE('D:\bbb.TXT','位置4='& NUMTOSTR(extgbdata(taccount( 1)),2),1);
tcancelex(1,2,'',stklabel);//撤空单
tcancelex(1,4,'',stklabel);//撤多单
end
isclear:=extgbdata(taccount( 1)+'_isclear');//标记是否应该清仓的全局变量
DEBUGFILE('D:\bbb.TXT','位置5='& NUMTOSTR(extgbdata(taccount( 1)),2),1);
if isclear then
begin
tsell(tbuyholdingex('','',1)>0,0,mkt);//每次只能平当前品种,所以必须监控账户栏实际持仓才能全平
TSELLSHORT(TSELLHOLDINGEX('','',1),0,mkt);
end
DEBUGFILE('D:\bbb.TXT','-----------------------------',1);
|