|
3楼
楼主 |
发表于 2015-1-18 22:06:27
|
只看该作者
本帖最后由 zhaowd2001 于 2015-1-18 22:14 编辑
//目的是进行价差套利。当rb1510-rb1505<=9的时候,多rb1510,空rb1505. 当rb1510-rb1505>=14的时候,平仓。
//代码写好了,用rb1501的1分钟数据测试,总是没有买卖记录,请斑竹指出程序错误。
//软件是易盛模拟。
//代码如下:
Params
Numeric diff_open(9);//赌扩大
Numeric diff_close(15);
Numeric diff_sell(22);//赌缩小
GlobalVars
Bool hasBid(False);//是否已经下单:赌扩大
Bool hasBid2(False);//是否已经下单:赌缩小
Vars
String far_name;
String mid_name;
NumericArray far;
NumericArray middle;
NumericArray diffArr;
Numeric diff;
Numeric slip(1);//买卖时滑价
Bool Open1;
Bool Close1;
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); //绘制价差
//赌扩大
Open1 = (diff < diff_open); //开仓
Close1 = (diff >= diff_close);//平仓
if (Open1 && (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(Close1 && 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;//没有持仓
}
}
//赌缩小
Open1 = (diff >= diff_sell); //开仓
Close1 = (diff <= diff_close);//平仓
if (Open1 && (hasBid==False))//开仓
{
//是否已经有持仓?
//if (A_SellPosition(mid_name) <= 0 && //没有卖仓
// A_BuyPosition(far_name) <= 0//没有买仓
// )
{
hasBid = True;//开仓标志
//价差开仓
//买入middle:rb1505
Buy(1, middle+slip, mid_name );
//卖出far: rb1510
SellShort(1, far-slip, far_name);
}
}
if(Close1 && hasBid)//平仓
{
//是否已经有持仓?
//if (A_SellPosition(mid_name) >= 1 && //没有卖仓
// A_BuyPosition(far_name) >= 1//没有买仓
// )
{
//价差平仓
//卖平middle:rb1505
Sell( 1, middle-slip, mid_name );
//买平far: rb1510
BuyToCover(1, far +slip, far_name);
hasBid = False;//没有持仓
}
}
End
|
|