[PEL] 复制代码
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;
ho4:stkindiex(stklabel,'策略1.ho',0,3,0,500);
ho5:stkindiex(stklabel,'策略1.ho',0,2,0,500);
ho6:stkindiex(stklabel,'策略1.ho',0,6,0,500);
//集合竞价时候,我们直接对比实际持仓和当前的理论持仓。因为这时候新的K线其实没有生成.这时候的理论持仓其实是前面已经
//确定的历史的理论持仓,可以直接操作的
//当前K线理论持仓
hc:ho4+ho5+ho6;
//账户多头持仓
tbuyho:tbuyholdingex('',stklabel,1);
//账户空头持仓
tsellho:tsellholdingex('',stklabel,1);
//是否有未成交单,返回1表示有未成交
is_order:tglobalsubmitex(0,'',stklabel,0);
//集合竞价时间 请根据品种自行配置。
isjh:currenttime>=92500 and currenttime<92900;
//集合竞价时候报单的加点
input:ds(3,1,100,1);
//如果当前品种有挂单就不执行
if is_order then exit;
//连续交易阶段,请根据实际时间调整这里的时间
if not(isjh) and currenttime>93000 then
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
//集合竞价期间
//注意报单价,如果不合理有可能不成交,目前是采用基于对手价超价报单(涨跌停价格取不到,只能用盘口对手价操作)
if isjh then
begin
//多头部分
if hc>=0 and tsellho>0 then tsellshort(1,tsellho,lmt,DYNAINFO( 34)+ds*mindiff);
//理论持仓大于0,补仓
if hc>0 and hc>tbuyho then
begin
tbuy(1,hc-tbuyho,lmt,dynainfo(34)+ds*mindiff);
end
//理论持仓大于0,减仓
if hc>0 and hc<tbuyho then
begin
tsell(1,tbuyho-hc,lmt,dynainfo( 28)-ds*mindiff);
end
//空头部分
if hc<=0 and tbuyho>0 then tsell(1,tbuyho,lmt,dynainfo( 28)-ds*mindiff);
//理论持仓小于0,补仓
if hc<0 and abs(hc)>tsellho then
begin
tbuyshort(1,abs(hc)-tsellho,lmt,dynainfo( 28)-ds*mindiff);
end
//理论持仓小于0,减仓
if hc<0 and abs(hc)<tsellho then
begin
tsellshort(1,tsellho-abs(hc),lmt,dynainfo( 34)+ds*mindiff);
end
end