请斑竹指导一下程序错误
//目的是进行价差套利。当rb1510-rb1505<=8的时候,多rb1510,空rb1505. 当rb1510-rb1505>=16的时候,平仓。//代码写好了,用rb1501的1分钟数据测试,总是没有买卖记录,请斑竹指出程序错误。
//软件是易盛模拟。
//代码如下:
Params
Numeric diff_open(8);
Numeric diff_close(16);
GlobalVars
Bool hasBid(False);//是否已经下单
Vars
String far_name;
String mid_name;
Numeric far;
Numeric middle;
Numeric diff;
Numeric slip(1);//买卖时滑价
Bool Con1;
Bool Con2;
Begin
mid_name = "RB1505";
far_name = "RB1510";
far = Q_Close( mid_name );//rb1510最新价
middle = Q_Close( far_name);//rb1505最新价
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, Q_Close(mid_name)-slip, mid_name );
//买入far: rb1510
Buy(1,Q_Close(far_name)+slip, far_name);
}
}
if(Con2 && hasBid)//平仓
{
//是否已经有持仓?
if (A_SellPosition(mid_name) >= 1 && //没有卖仓
A_BuyPosition(far_name)>= 1//没有买仓
)
{
//价差平仓
//买平middle:rb1505
BuyToCover( 1, Q_Close(mid_name)+slip, mid_name );
//卖平far: rb1510
Sell(1,Q_Close(far_name)-slip, far_name);
hasBid = False;//没有持仓
}
}
End
本帖最后由 zhaowd2001 于 2015-1-18 17:48 编辑
删除2222222222222222222222
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;
NumericArraymiddle;
NumericArraydiffArr;
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
页:
[1]