首先我们建立一个TLStart的宏,然后再响应品种报表数据变化事件,代码如下:
Sub TLStart()
'注册CF09和CF11品种
call marketdata.RegReportNotify("CF09","ZQ")
call marketdata.RegReportNotify("CF11","ZQ")
End Sub
'响应注册的品种行情变化通知
Sub MARKETDATA_ReportNotify(ReportData)
'得到这两个品种的行情报价
Set Report1 = marketdata.GetReportData("CF09","ZQ")
Set Report2 = marketdata.GetReportData("CF11","ZQ")
'得到品种的持仓量等信息
dim BuyHoding1
dim BuyHlding2
dim BuyTodayHoding1
dim BuyTodayHoding2
dim SellHoding1
dim SellHoding2
dim SellTodayHoding1
dim SellTodayHoding2
dim BuyCost
dim SellCost
dim PNL
Dim UseMargin
'取指定持仓品种信息
call Order.HoldingInfoByCode2("CF09","ZQ",BuyHoding1,BuyCost,BuyTodayHoding1,SellHoding1,SellCost,SellTodayHoding1,PNL,UseMargin)
call Order.HoldingInfoByCode2("CF11","ZQ",BuyHoding2,BuyCost,BuyTodayHoding2,SellHoding2,SellCost,SellTodayHoding2,PNL,UseMargin)
'当差价出现大于1800时进行套利开仓
'假设是09买 11卖
Diff = Report1.SellPrice1 - Report2.BuyPrice1 '分别取卖价和买价计算差价
if Diff > 1800 and BuyHoding1 = 0 then
call Order.Buy(0,1,Report1.SellPrice1,0,"CF09","ZQ","",0)
call Order.BuyShort(0,1,Report2.BuyPrice1,0,"CF11","ZQ","",0)
end if
'当差价小于1000时进行套利平仓
Diff = Report1.BuyPrice1 - Report2.SellPrice1
if diff < 1000 and BuyHoding1 > 0 then
call Order.Sell(0,1,Report1.BuyPrice1,0,"CF09","ZQ","",0)
call Order.Sellshort(0,1,Report2.SellPrice1,0,"CF11","ZQ","",0)
end if
End Sub
代码编写完毕后Alt+F8,然后选择我们刚才建立的TLStart宏名即可
建立建立TLStart宏后要怎么操作
好像 不能运行提示1024 usemargin 有错??
“缺少语句”
要专业版才行的
Sub TLStart()
'注册CF09和CF11品种
call marketdata.RegReportNotify("CF09","ZQ")
call marketdata.RegReportNotify("CF11","ZQ")
End Sub
'响应注册的品种行情变化通知
Sub MARKETDATA_ReportNotify(ReportData)
'得到这两个品种的行情报价
Set Report1 = marketdata.GetReportData("CF09","ZQ")
Set Report2 = marketdata.GetReportData("CF11","ZQ")
这里的获取行情信息,是不是重复了,既然已经使用RegReportNotify注册了品种,就可以在 MarketData_ReportNotity事件中获取价格了,所以,只需要判断ReportData返回的品种代码就可以知道是哪个品种的价格。
如:
if ReportData.label="CF09" then
CF09Price=ReportData.BuyPrice1
else
CF11Price=ReportData.SellPrice1
end if
Diff=CF09Price-CF11Price