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客户端或QQ群发送指定消息字…
- 下一篇:滤波器的设计
相关文章
-
指定的模型还没有相关内容!