|
3楼
楼主 |
发表于 2015-1-18 18:12:18
|
只看该作者
1分钟价差:
//目的是进行价差套利。当rb1510-rb1505<=8的时候,多rb1510,空rb1505. 当rb1510-rb1505>=16的时候,平仓。
//软件是易盛模拟。
//代码如下:
Params
Numeric diff_open(10);
Numeric diff_close(18);
GlobalVars
Bool hasBid(False);//是否已经下单
Vars
String far_name;
String mid_name;
NumericArray far;
NumericArray middle;
NumericArray diffArr;
Numeric diff;
Numeric slip(1);//买卖时滑价
Bool Con1;
Bool Con2;
Numeric i(0);
Begin
mid_name = "RB1505";
far_name = "RB1510";
middle = HisData(Enum_Data_Close, Enum_Period_Min1, mid_name ); //rb1510最新价
far = HisData(Enum_Data_Close,Enum_Period_Min1, far_name);//rb1505最新价
print(diff);
print(far);
print(middle);
//diffArr = far-middle;
diff = far - middle;
if(diff <= 0 || diff > 100)
return;
//PlotNumeric("diff", far-middle); //绘制价差
Con1 = (diff < diff_open); //开仓
Con2 = (diff >= diff_close);//平仓
if (Con1 && (hasBid==False))//开仓
{
//是否已经有持仓?
if (A_SellPosition(mid_name) <= 0 && //没有卖仓
A_BuyPosition(far_name) <= 0//没有买仓
)
{
hasBid = True;//开仓标志
//价差开仓
//卖出middle:rb1505
SellShort(1, middle-slip, mid_name );
//买入far: rb1510
Buy(1, far+slip, far_name);
}
}
if(Con2 && hasBid)//平仓
{
//是否已经有持仓?
if (A_SellPosition(mid_name) >= 1 && //没有卖仓
A_BuyPosition(far_name) >= 1//没有买仓
)
{
//价差平仓
//买平middle:rb1505
BuyToCover( 1, middle+slip, mid_name );
//卖平far: rb1510
Sell(1, far -slip, far_name);
hasBid = False;//没有持仓
}
}
End
|
|