trueHolding:=tbuyholdingex('','IF11',1)-tsellholdingex('','IF11',1);
if islastbar and trueHolding<>holding then sendmail(1,'myemail@xxx.com','持仓不一致','虚拟:'& holding & '手,真实:' & trueHolding & '手');
用IF11做示范,你交易的品种是哪个合约,这个需要用另外的方法获得,不同策略就不一样了,'IF11'可用变量替代。
再说明一点点,如果一直有故障,这个代码会一直发邮件,没必要,你可以弄一个全局变量,例如IsError:
globalvariable:IsError=false;
trueHolding:=tbuyholdingex('','IF11',1)-tsellholdingex('','IF11',1);
if islastbar then
begin
if IsError=false and trueHolding<>holding then
begin
sendmail(1,'myemail@xxx.com','持仓不一致','虚拟:'& holding & '手,真实:' & trueHolding & '手');
IsError=true;
end;
if IsError=true and trueHolding=holding then
begin
sendmail(1,'myemail@xxx.com','持仓已恢复一致','持仓已恢复一致');
IsError=false;
end;
end;