Monday, May 4, 2020

开拓者之A函数下单撤单以及全局变量操作

Params
Numeric offset(1);   //委托价格偏移
Numeric beforemins(10);   //收盘前几分钟开始操作
Vars
Numeric temppos;   //仓位
Numeric deleteordertickcounter;   //tick计数器
Numeric hassendorder(0);   //撤单标志,初始值为0
Begin
//第一根bar,初始化tick计数器、撤单标志,存于全局变量中
if (BarStatus==0)
{
deleteordertickcounter = 9999;
hassendorder = 0;
SetGlobalVar(0,deleteordertickcounter);
SetGlobalVar(1,hassendorder);
}
Else   //其他bar,从全局变量中读取撤单tick计数器、撤单标志的值
{
deleteordertickcounter = GetGlobalVar(0);
hassendorder = GetGlobalVar(1);
}
//收盘前N分钟,且撤单标志为0,即还未撤单时
if (CurrentTime>(0.1459-0.0001*(beforemins-1)) && BarStatus==2 && hassendorder==0)
{
if (Close<>InvalidInteger && A_GetOpenOrderCount()>0)
{
A_DeleteOrder();
deleteordertickcounter = 1;   //tick开始计数,为了延迟5个tick后做平仓用的
}
deleteordertickcounter = deleteordertickcounter+1;
SetGlobalVar(0,deleteordertickcounter);
if (deleteordertickcounter<5) Return;   //撤单后需要延迟几个tick才平仓
//平多单
temppos = A_BuyPosition;
if (temppos>0)
{
A_SendOrder(enum_buy,enum_exit,temppos,Q_AskPrice-offset*MinMove*PriceScale);
}
//平空单
temppos = A_sellPosition;
if (temppos>0)
{
A_SendOrder(enum_sell,enum_exit,temppos,Q_AskPrice+offset*MinMove*PriceScale);
}
hassendorder = 1;
SetGlobalVar(1,hassendorder);
}
End
 
 http://blog.sina.com.cn/s/blog_eb5c186a0102vot9.html

No comments: