| 

 等级: 专业版 
注册: 2024-6-21曾用名:  | 
 
 
 楼主|
发表于 2024-10-24 22:04
|
显示全部楼层 
| ho1:stkindiex(stklabel,'策略1.ho',0,3,-1,500); ho2:stkindiex(stklabel,'策略1.ho',0,2,-1,500);
 ho3:stkindiex(stklabel,'策略1.ho',0,6,-1,500);
 
 //上一根k线的理论持仓
 ho:ho1+ho2+ho3;
 
 //账户多头持仓
 tbuyho:tbuyholdingex('',stklabel,1);
 //账户空头持仓
 tsellho:tsellholdingex('',stklabel,1);
 //是否有未成交单,返回1表示有未成交
 is_order:tglobalsubmitex(0,'',stklabel,0);
 
 //如果当前品种有挂单就不执行
 if is_order then exit;
 else
 begin
 
 
 //直接对比前一个周期的理论持仓和当前实际持仓是否存在差异,有差异执行矫正
 
 //多头部分
 if ho>=0 and tsellho>0 then tsellshort(1,tsellho,mkt);
 //理论持仓大于0,补仓
 if ho>0 and ho>tbuyho then
 begin
 tbuy(1,ho-tbuyho,mkt);
 end
 //理论持仓大于0,减仓
 if ho>0 and ho<tbuyho then
 begin
 tsell(1,tbuyho-ho,mkt);
 end
 
 //空头部分
 if ho<=0 and tbuyho>0 then tsell(1,tbuyho,mkt);
 //理论持仓小于0,补仓
 if ho<0 and abs(ho)>tsellho then
 begin
 tbuyshort(1,abs(ho)-tsellho,mkt);
 end
 //理论持仓小于0,减仓
 if ho<0 and abs(ho)<tsellho then
 begin
 tsellshort(1,tsellho-abs(ho),mkt);
 end
 end
 | 
 |