打印本文打印本文 关闭窗口关闭窗口

金字塔获取主力合约最简单的VBA代码

作者:金字塔 来源:cxh99.com 发布时间:2012年11月12日
  • 内容:

    '本过程需要两个参数

    '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

     

打印本文打印本文 关闭窗口关闭窗口