VBA套利模型范例 [金字塔]
- 咨詢內容:
首先我們建立一個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宏名即可
[此貼子已經被作者于2010-7-14 21:54:24編輯過] - 金字塔客服:
太好了,非常感謝老大,如果能,多一些這樣的范例就好了,:-)
- 用戶回復:
這種舉例的形式好!學習中。。。
- 網友回復:
dim BuyHlding2少個O
- 網友回復:
建立建立TLStart宏后要怎么操作
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯系技術人員 QQ: 1145508240 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容