首先我們建立一個(gè)TLStart的宏,然后再響應(yīng)品種報(bào)表數(shù)據(jù)變化事件,代碼如下:
Sub TLStart()
'注冊(cè)CF09和CF11品種
call marketdata.RegReportNotify("CF09","ZQ")
call marketdata.RegReportNotify("CF11","ZQ")
End Sub
'響應(yīng)注冊(cè)的品種行情變化通知
Sub MARKETDATA_ReportNotify(ReportData)
'得到這兩個(gè)品種的行情報(bào)價(jià)
Set Report1 = marketdata.GetReportData("CF09","ZQ")
Set Report2 = marketdata.GetReportData("CF11","ZQ")
'得到品種的持倉(cāng)量等信息
dim BuyHoding1
dim BuyHlding2
dim BuyTodayHoding1
dim BuyTodayHoding2
dim SellHoding1
dim SellHoding2
dim SellTodayHoding1
dim SellTodayHoding2
dim BuyCost
dim SellCost
dim PNL
Dim UseMargin
'取指定持倉(cāng)品種信息
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)
'當(dāng)差價(jià)出現(xiàn)大于1800時(shí)進(jìn)行套利開倉(cāng)
'假設(shè)是09買 11賣
Diff = Report1.SellPrice1 - Report2.BuyPrice1 '分別取賣價(jià)和買價(jià)計(jì)算差價(jià)
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
'當(dāng)差價(jià)小于1000時(shí)進(jìn)行套利平倉(cāng)
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宏名即可
[此貼子已經(jīng)被作者于2010-7-14 21:54:24編輯過(guò)]
建立建立TLStart宏后要怎么操作