全部 智大领峰 TBQuant功能 TBL语言 TB开户 问答专区 高手圈 其他
怎么样在收盘前对未成交的平仓委托单进行撤单
2024-09-02 13:40

请问:想要在收盘前做这个处理:1、对未成交的平仓委托单进行撤单。2、撤单后,按最新的即时价格重新报单。

我的想法是在onorder里对每笔平仓单进行记录订单号,然后在onbar里根据时间条件进行撤单。但是编译显示onorder里的结构体ord没有声明,这样的话应该怎么改?或者是,有没有其它办法?谢谢。


以下为代码:


Params

Numeric Length1(40);

Numeric Length2(20);


Vars

Series<Numeric> Lots;

Series<Numeric> HighestValue1;

Series<Numeric> LowestValue1;

Series<Numeric> HighestValue2;

Series<Numeric> LowestValue2;

Global Integer sellxinhao;

Global Integer buytocoverxinhao;

Global Integer c;

Global Integer d;

Series<Bool> Time_Close_day;

Global array<Integer> orderIds;

Bool c_ok;

Bool d_ok;

Events

   OnInit()

{

//与数据源有关

Range[0:DataCount-1]

{

//=========数据源相关设置==============

AddDataFlag(Enum_Data_RolloverBackWard()); //设置后复权

AddDataFlag(Enum_Data_RolloverRealPrice()); //设置映射真实价格

AddDataFlag(Enum_Data_AutoSwapPosition()); //设置自动换仓

     //AddDataFlag(Enum_Data_IgnoreSwapSignalCalc()); //设置忽略换仓信号计算

     //******************获取映射主力合约****************//

Array<String> symbols;

Bool ret = GetOrderMapRelatedSymbols(symbols);

//******************获取映射主力合约****************//

}

}

  OnOrder(OrderRef ord)

  {

       if(ord.symbol==RelativeSymbol and (ord.side==Enum_Sell or ord.side==Enum_ShortSelling) and (ord.combOffset==Enum_exit or ord.combOffset==Enum_ExitToday))

{

c = ord.orderid;

print(\"selltime:\"+text(time));

print(\"a:\"+text(c));

//t_id=CreateTimer(5000);

//t_time=ord.createDateTime;

       }

     

        if(ord.symbol==RelativeSymbol and (ord.side==Enum_buy or ord.side==Enum_MarginBuying) and (ord.combOffset==Enum_exit or ord.combOffset==Enum_ExitToday))

{

d = ord.orderid;

print(\"butycovertime:\"+text(time));

print(\"a:\"+text(d));

//t_id=CreateTimer(5000);

//t_time=ord.createDateTime;

       }      

  }

   onBar(ArrayRef<Integer> indexs)

   {    

    //集合竞价和小节休息的过滤;

Numeric Lots=1;

    Time_Close_day=(Time>=0.1459 and Time <0.1500); //or (Time>=0.0055 and Time < 0.0100) ; //or (Time>=0.2250 and Time < 0.2300)

    If(Time_Close_day)//当前时间如果大于设置时间,进行清仓;

{  

if(ord.symbol==RelativeSymbol and ord.status==Enum_declared  and sellxinhao==1 and MarketPosition>0)

{

A_DeleteOrderEx(c);

print(\"指定时间撤多单time:\"+text(time));

print(\"指定时间撤仓多单:\"+text(c));

c_ok=true;

}

if(c_ok)

{

sell(0,low);

c_ok=false;

}  

if(ord.symbol==RelativeSymbol and ord.status==Enum_declared  and buytocoverxinhao==1 and MarketPosition<0)

{

A_DeleteOrderEx(d);

print(\"指定时间撤空单time:\"+text(time));

print(\"指定时间撤空单:\"+text(d));

d_ok=true;

}

if(d_ok)

{

buytocover(0,high);

d_ok=false;

}

}


    HighestValue1 = HighestFC(High, Length1);

    LowestValue1 = LowestFC(Low, Length1);

    HighestValue2 = HighestFC(High, Length2);

    LowestValue2 = LowestFC(Low, Length2);

   


   //开仓条件

    if(H>=HighestValue1[1] and MarketPosition==0)

    {

    Buy(Lots,HighestValue1[1]-500);

    sellxinhao=0;  

    }

    if(L<=LowestValue1[1] and MarketPosition==0)

    {  

    SellShort(Lots,LowestValue1[1]+500);

               buytocoverxinhao=0;

    }

    // 平仓条件

    If(MarketPosition >0 And BarsSinceEntry >0  And Low <= HighestValue2[1])

    {          

    Sell(0,Min(Open,HighestValue2[1]));

    sellxinhao=1;

    }

    // 持有空单时,自适应出场均线高于出场线,平空单

    If(MarketPosition <0 And BarsSinceEntry >0  And High >= LowestValue1[1])

    {

    BuyToCover(0,Max(Open,LowestValue2[1]));

    BuyToCoverxinhao=1;

    }  

   }

kyover

ord是属于onorder事件域的传入容器,可以在onorder域里调用其中的数据,但是当onorder域执行完毕后,ord容器就被丢弃了。你现在报错的是因为你在onbar事件域里调用了ord,结构体,这个肯定是不对的。

你如果需要在两个事件域之间进行数据交互,可以使用global类型容器来保存数据。比如你需要ord.symbol,那你就 可以在onorder域里用一个global string 的容器temp_string来保存当时驱动的symbol,然后在onbar里再引用temp_string来获取在onorder里保存的symbol数据

2024-09-02 15:33
您未登录,请先 登录注册 后发表评论
顶部