以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  高级功能研发区  (http://weistock.com/bbs/list.asp?boardid=5)
----  新年献礼:获取主力合约最简单的VBA代码  (http://weistock.com/bbs/dispbbs.asp?boardid=5&id=9753)

--  作者:guotx2010
--  发布时间:2012/1/29 14:00:47
--  新年献礼:获取主力合约最简单的VBA代码

\'本过程需要两个参数

\'1.sMarketCode市场代码,如中金所是ZJ,上期所SQ,郑商所ZQ,大连所DQ

\'2.sStockPre品种代码的前缀,如股指IF,螺纹钢RB等,就是合约代码的符号,不要月份。

\'调用方法:GetContractCode \'ZJ\',\'IF\'      \'返回股指期货的主力合约

\'调用上述过程之后,ZhuLiCode就保存了主力合约的代码

\'本方法是通过判断那个合约的成交量与连续合约的成交量相等的方式来判断主力合约的,跟金字塔内部的方式一致。

 

public ZhuLiCode     \'主力合约代码

Sub GetContractCode(sMarketCode,sStockPre)    \'根据市场编码取得主力合约编码
 If sMarketCode="" then
  sMarketCode="ZJ"
 End if 
 
 n = marketdata.GetReportCount(sMarketCode)
 
 For j = 0 To n - 1
  Set report1 = marketdata.GetReportDataByIndex(sMarketCode, j)
  suffixlabel = Right(report1.Label, 2)
  If sStockPre=left(report1.Label,len(sStockPre)) then
   If suffixlabel = "00" Then
    ZhuLiVol=report1.volume
   End If
 
   If cdbl(suffixlabel) >= 1 And cdbl(suffixlabel) <= 12 Then
    If report1.volume = ZhuLiVol Then
     ZhuLiCode = report1.Label
     \'application.MsgOut ZhuLiCode
     exit for
    End If
   End If
  End if 
 Next
End Sub


--  作者:meteor528528
--  发布时间:2012/2/2 11:28:53
--  
图片点击可在新窗口打开查看
--  作者:solarhe2006
--  发布时间:2012/5/6 23:33:36
--  

\'本过程需要两个参数

\'1.sMarketCode市场代码,如中金所是ZJ,上期所SQ,郑商所ZQ,大连所DQ

\'2.sStockPre品种代码的前缀,如股指IF,螺纹钢RB等,就是合约代码的符号,不要月份。

\'调用方法:GetContractCode \'ZJ\',\'IF\'      \'返回股指期货的主力合约

\'调用上述过程之后,ZhuLiCode就保存了主力合约的代码

\'本方法是通过判断那个合约的成交量与连续合约的成交量相等的方式来判断主力合约的,跟金字塔内部的方式一致。

 

public ZhuLiCode     \'主力合约代码

Sub GetContractCode(sMarketCode,sStockPre)    \'根据市场编码取得主力合约编码
 If sMarketCode="" then
  sMarketCode="ZJ"
 End if 
 
 n = marketdata.GetReportCount(sMarketCode)
 
 For j = 0 To n - 1
  Set report1 = marketdata.GetReportDataByIndex(sMarketCode, j)
  suffixlabel = Right(report1.Label, 2)
  If sStockPre=left(report1.Label,len(sStockPre)) then
   If suffixlabel = "00" Then
    ZhuLiVol=report1.volume
   End If
 
   If cdbl(suffixlabel) >= 1 And cdbl(suffixlabel) <= 12 Then
    If report1.volume = ZhuLiVol Then
     ZhuLiCode = report1.Label
     \'application.MsgOut ZhuLiCode
     exit for
    End If
   End If
  End if 
 Next
End Sub


--  作者:shawaverage
--  发布时间:2012/9/10 19:12:44
--  
粘贴进去,公式测评显示语句末尾缺少分号,麻烦请指导下。谢谢
--  作者:guotx2010
--  发布时间:2012/9/10 22:03:28
--  
朋友,这个是vba代码,不是pel语言的,不能用在公式或策略中的。
--  作者:sunset0920
--  发布时间:2012/9/20 11:08:02
--  

 非常感兴趣的是 如何获取次主力合约代码

 

没见到有强人在讨论。