人人爽天天爽夜夜爽qc-人人爽天天爽夜夜爽曰-人人天天爱天天做天天摸-人人天天夜夜-色网站在线-色网站在线看

您現在的位置:程序化交易>> 期貨公式>> 金字塔等>> 金字塔知識>>正文內容

到期合約換月自動移倉代碼 [金字塔]

  • 咨詢內容:

    '代碼中需要用到YcSet.ini文件,自己建立一個放到c:\,內容如下:

    [gen]

    AccountCount=1

    Account1_Code=888888

    Account1_Yc=1

    有n個賬戶需要自動移倉,則AccountCode=n,注意:多賬戶時需要機構版,同時登陸這些賬戶

    Account1中的1,是序號,有多個時,依次遞增,_Code指定該賬戶的賬號,_Yc為1表示要自動移倉,0則不要。

     

    '''''以下為代碼

    public iMultipliter   

    public ZhuLiCode,AccountID   '主力合約,賬戶

    Sub APPLICATION_VBAStart()
     Call Application.SetTimer(2,1000*30)  '使用定時器30秒輪詢
    End Sub

    Sub Application_Timer(ID)
     'Application.MsgOut CDate(Time)
     if weekday(cdate(date),vbMonday)>=6 then  '周六、周日不執行
      exit sub
     end if 
     '''''''''''''''''
     If CDate(Time)>=cdate("10:0000") then    '10:00-10:10判斷是否需要移倉
      If CDate(Time)<=cdate("10:10:00") then
       TotalAccount=Cdbl(Document.GetPrivateProfileString("Gen","AccountCount",0,"C:\YcSet.Ini"))  '賬戶數
       For j=1 to TotalAccount
        CurrentAccount=Document.GetPrivateProfileString("Gen","Account" & Cstr(j) & "_Code",0,"C:\YcSet.Ini")  '本賬戶號碼
        Yc=Document.GetPrivateProfileString("Gen","Account" & Cstr(j) & "_Yc",0,"C:\YcSet.Ini")  '是否移倉
        if Yc=1 then
         GetAllHolding CurrentAccount
        end if 
       Next 
      end if
     end if  
    End Sub

    '獲取合約乘數
    Sub GetContract(sCode,sMarket)
     'Application.MsgOut sCode & "," & sMarket
     Call Order.Contract(sCode,sMarket,Multipliter,MinTick,ShortPercent,LongPercent)
     iMultipliter=Multipliter
     'application.MsgOut iMultipliter
     iMinTick=MinTick
     iShortPercent=ShortPercent
     iLongPercent=LongPercent
    End Sub

    Sub GetAllHolding(sAccount)
      dim i,k
      dim BuyHold
     dim BuyCost
     dim SellHold
     dim SellCost
     dim CurCode
     dim CurMarket

      On Error resume Next
     HoldingCount=Order.Holding2(sAccount)
      If HoldingCount>0 then
       For i=0 to HoldingCount-1
        Call Order.HoldingInfo2(i,BuyHolding,BuyCost,BuyTodayHolding,SellHolding,SellCost,SellTodayHolding,PNL,UseMargin,Code,Market,sAccount)
        CurCode=Code
        CurMarket=Market
        BuyHold=BuyHolding
        SellHold=SellHolding
        AutoYiCang CurCode,CurMarket,BuyHold,SellHold,sAccount  '自動移倉
       Next 
      End If 
    End Sub

    sub AutoYiCang(sCode,sMarket,iBuy,iSell,sAcc)
     dim PreCode
     dim i
     
     for i=1 to len(sCode)
      if isnumeric(mid(sCode,i,1)) then
       PreCode=left(sCode,i-1)
       exit for
      end if 
     next
     'application.MsgOut "i:" & i & ",PreCode:" & PreCode & ",sAcc:" & sAcc
     GetContractCode sMarket,PreCode
     if sCode<>ZhuLiCode And left(ZhuLiCode,i-1)=left(sCode,i-1) then  '不是持有主力合約
      if iBuy>0 then
       PingDuoDan 0,sCode,sMarket,iBuy,sAcc
       KaiDuoDan 0,ZhuLiCode,sMarket,iBuy,sAcc
      end if
      if iSell>0 then
       PingKongDan 0,sCode,sMarket,iSell,sAcc
       KaiKongDan 0,ZhuLiCode,sMarket,iSell,sAcc
      end if
     end if
    end sub

    Sub GetContractCode(sMarketCode,sStockPre)    '根據市場編碼取得主力合約編碼
     If sMarketCode="" then
      exit sub
     End if 
     
     contractvolume = 0
      
     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

    '開多單
    Sub KaiDuoDan(nPrice,sCode,sMarket,iOrdVol,sAccount)  '開多單,nPrice=0時為市價,否則就是傳遞過來的價
     'application.MsgOut "iOrdVol:" & iOrdVol & "," & sCode & "," & sMarket & "," & sAccount & "," & nPrice
     If iOrdVol>0 then
      If nPrice=0 then
       'application.MsgOut "sCode,sMarket,AccountID:" & sCode & "," & sMarket & "," & AccountID
       Call Order.Buy(1,iOrdVol,0,0,sCode,sMarket,sAccount,0)     '市價開多單
      Else
       Call Order.Buy(0,iOrdVol,nPrice,0,sCode,sMarket,sAccount,0)   '限價開多單
      End If 
     End If
    End Sub

    '開空單
    Sub KaiKongDan(nPrice,sCode,sMarket,iOrdVol,sAccount)  '開空單,nPrice=0時為市價,否則就是傳遞過來的價
     'application.MsgOut "iOrdVol:" & iOrdVol & "," & sCode & "," & sMarket & "," & sAccount & "," & nPrice
     If iOrdVol>0 then
      If nPrice=0 then
       Call Order.BuyShort(1,iOrdVol,0,0,sCode,sMarket,sAccount,0)    '市價開空單
      Else
       Call Order.BuyShort(0,iOrdVol,nPrice,0,sCode,sMarket,sAccount,0)   '限價開空單
      End If 
     End If
    End Sub

    '平多單
    Sub PingDuoDan(nPrice,sCode,sMarket,iOrdVol,sAccount)  '平多單,nPrice=0時為市價,否則就是傳遞過來的價
     If iOrdVol>0 then
      If nPrice=0 then
       Call Order.Sell(1,iOrdVol,0,0,sCode,sMarket,sAccount,0)    '市價平多單
      Else
       Call Order.Sell(0,iOrdVol,nPrice,0,sCode,sMarket,sAccount,0)   '限價平多單
      End If 
     End If
    End Sub
    '平空單
    Sub PingKongDan(nPrice,sCode,sMarket,iOrdVol,sAccount)  '平空單,nPrice=0時為市價,否則就是傳遞過來的價
     If iOrdVol>0 then
      If nPrice=0 then
       Call Order.SellShort(1,iOrdVol,0,0,sCode,sMarket,sAccount,0)    '市價平空單
      Else
       Call Order.SellShort(0,iOrdVol,nPrice,0,sCode,sMarket,sAccount,0)   '限價平空單
      End If 
     End If
    End Sub

     

     

     

     

  • 金字塔客服:

    '代碼中需要用到YcSet.ini文件,自己建立一個放到c:\,內容如下:

    [gen]

    AccountCount=1

    Account1_Code=888888

    Account1_Yc=1

    有n個賬戶需要自動移倉,則AccountCode=n,注意:多賬戶時需要機構版,同時登陸這些賬戶

    Account1中的1,是序號,有多個時,依次遞增,_Code指定該賬戶的賬號,_Yc為1表示要自動移倉,0則不要。

     

    '''''以下為代碼

    public iMultipliter   

    public ZhuLiCode,AccountID   '主力合約,賬戶

    Sub APPLICATION_VBAStart()
     Call Application.SetTimer(2,1000*30)  '使用定時器30秒輪詢
    End Sub

    Sub Application_Timer(ID)
     'Application.MsgOut CDate(Time)
     if weekday(cdate(date),vbMonday)>=6 then  '周六、周日不執行
      exit sub
     end if 
     '''''''''''''''''
     If CDate(Time)>=cdate("10:0000") then    '10:00-10:10判斷是否需要移倉
      If CDate(Time)<=cdate("10:10:00") then
       TotalAccount=Cdbl(Document.GetPrivateProfileString("Gen","AccountCount",0,"C:\YcSet.Ini"))  '賬戶數
       For j=1 to TotalAccount
        CurrentAccount=Document.GetPrivateProfileString("Gen","Account" & Cstr(j) & "_Code",0,"C:\YcSet.Ini")  '本賬戶號碼
        Yc=Document.GetPrivateProfileString("Gen","Account" & Cstr(j) & "_Yc",0,"C:\YcSet.Ini")  '是否移倉
        if Yc=1 then
         GetAllHolding CurrentAccount
        end if 
       Next 
      end if
     end if  
    End Sub

    '獲取合約乘數
    Sub GetContract(sCode,sMarket)
     'Application.MsgOut sCode & "," & sMarket
     Call Order.Contract(sCode,sMarket,Multipliter,MinTick,ShortPercent,LongPercent)
     iMultipliter=Multipliter
     'application.MsgOut iMultipliter
     iMinTick=MinTick
     iShortPercent=ShortPercent
     iLongPercent=LongPercent
    End Sub

    Sub GetAllHolding(sAccount)
      dim i,k
      dim BuyHold
     dim BuyCost
     dim SellHold
     dim SellCost
     dim CurCode
     dim CurMarket

      On Error resume Next
     HoldingCount=Order.Holding2(sAccount)
      If HoldingCount>0 then
       For i=0 to HoldingCount-1
        Call Order.HoldingInfo2(i,BuyHolding,BuyCost,BuyTodayHolding,SellHolding,SellCost,SellTodayHolding,PNL,UseMargin,Code,Market,sAccount)
        CurCode=Code
        CurMarket=Market
        BuyHold=BuyHolding
        SellHold=SellHolding
        AutoYiCang CurCode,CurMarket,BuyHold,SellHold,sAccount  '自動移倉
       Next 
      End If 
    End Sub

    sub AutoYiCang(sCode,sMarket,iBuy,iSell,sAcc)
     dim PreCode
     dim i
     
     for i=1 to len(sCode)
      if isnumeric(mid(sCode,i,1)) then
       PreCode=left(sCode,i-1)
       exit for
      end if 
     next
     'application.MsgOut "i:" & i & ",PreCode:" & PreCode & ",sAcc:" & sAcc
     GetContractCode sMarket,PreCode
     if sCode<>ZhuLiCode And left(ZhuLiCode,i-1)=left(sCode,i-1) then  '不是持有主力合約
      if iBuy>0 then
       PingDuoDan 0,sCode,sMarket,iBuy,sAcc
       KaiDuoDan 0,ZhuLiCode,sMarket,iBuy,sAcc
      end if
      if iSell>0 then
       PingKongDan 0,sCode,sMarket,iSell,sAcc
       KaiKongDan 0,ZhuLiCode,sMarket,iSell,sAcc
      end if
     end if
    end sub

    Sub GetContractCode(sMarketCode,sStockPre)    '根據市場編碼取得主力合約編碼
     If sMarketCode="" then
      exit sub
     End if 
     
     contractvolume = 0
      
     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

    '開多單
    Sub KaiDuoDan(nPrice,sCode,sMarket,iOrdVol,sAccount)  '開多單,nPrice=0時為市價,否則就是傳遞過來的價
     'application.MsgOut "iOrdVol:" & iOrdVol & "," & sCode & "," & sMarket & "," & sAccount & "," & nPrice
     If iOrdVol>0 then
      If nPrice=0 then
       'application.MsgOut "sCode,sMarket,AccountID:" & sCode & "," & sMarket & "," & AccountID
       Call Order.Buy(1,iOrdVol,0,0,sCode,sMarket,sAccount,0)     '市價開多單
      Else
       Call Order.Buy(0,iOrdVol,nPrice,0,sCode,sMarket,sAccount,0)   '限價開多單
      End If 
     End If
    End Sub

    '開空單
    Sub KaiKongDan(nPrice,sCode,sMarket,iOrdVol,sAccount)  '開空單,nPrice=0時為市價,否則就是傳遞過來的價
     'application.MsgOut "iOrdVol:" & iOrdVol & "," & sCode & "," & sMarket & "," & sAccount & "," & nPrice
     If iOrdVol>0 then
      If nPrice=0 then
       Call Order.BuyShort(1,iOrdVol,0,0,sCode,sMarket,sAccount,0)    '市價開空單
      Else
       Call Order.BuyShort(0,iOrdVol,nPrice,0,sCode,sMarket,sAccount,0)   '限價開空單
      End If 
     End If
    End Sub

    '平多單
    Sub PingDuoDan(nPrice,sCode,sMarket,iOrdVol,sAccount)  '平多單,nPrice=0時為市價,否則就是傳遞過來的價
     If iOrdVol>0 then
      If nPrice=0 then
       Call Order.Sell(1,iOrdVol,0,0,sCode,sMarket,sAccount,0)    '市價平多單
      Else
       Call Order.Sell(0,iOrdVol,nPrice,0,sCode,sMarket,sAccount,0)   '限價平多單
      End If 
     End If
    End Sub
    '平空單
    Sub PingKongDan(nPrice,sCode,sMarket,iOrdVol,sAccount)  '平空單,nPrice=0時為市價,否則就是傳遞過來的價
     If iOrdVol>0 then
      If nPrice=0 then
       Call Order.SellShort(1,iOrdVol,0,0,sCode,sMarket,sAccount,0)    '市價平空單
      Else
       Call Order.SellShort(0,iOrdVol,nPrice,0,sCode,sMarket,sAccount,0)   '限價平空單
      End If 
     End If
    End Sub

     

  • 用戶回復: 感覺有些復雜,建議是否將自動換月的功能加入到軟件中. 比如可以在主連上跑策略,程序自動實現換月.

     

  • 網友回復: 還有人關注此貼嗎,好像不能映射大連市場的幾組連續合約,J00和JD00,P00和PP00會搞混,不知什么原因,請老師解惑2016-09-23 21:00:00.119    【圖表】TA00 運行完畢2016-09-23 21:00:00.119    【圖表】MA00 運行完畢2016-09-23 21:00:00.119    【圖表】RM00 運行完畢2016-09-23 21:00:00.119    【圖表】CF00 運行完畢2016-09-23 21:00:01.133    【圖表】FG00 運行完畢2016-09-23 21:00:01.133    【圖表】ZC00 運行完畢2016-09-23 21:00:02.147    【圖表】J01 運行完畢2016-09-23 21:00:02.147    【圖表】M00 運行完畢2016-09-23 21:00:02.147    【圖表】RU00 運行完畢2016-09-23 21:00:02.147    【圖表】Y00 運行完畢2016-09-23 21:00:02.147    【圖表】HC00 運行完畢2016-09-23 21:00:02.147    【圖表】RB00 運行完畢2016-09-23 21:00:02.147    【圖表】AL00 運行完畢2016-09-23 21:00:02.147    【圖表】I00 運行完畢2016-09-23 21:25:12.401    【下單】J01 價0.000000 量1 買賣1 類型1 開平1 賬戶600802 Formula 12016-09-23 21:25:12.417    【下單】JD01 價0.000000 量1 買賣0 類型1 開平0 賬戶600802 Formula 12016-09-23 21:25:12.417    【指令】收到回報指令 ID = 3042061372016-09-23 21:25:12.433    【回報】600802 : j1701 - 已報單 1 價格:1249.5 平 賣2016-09-23 21:25:12.511    【指令】收到回報指令 ID = 3042061382016-09-23 21:25:12.511    【回報】600802 : jd1701 - 已報單 1 價格:3378 開 買2016-09-23 21:25:12.511    【指令】收到回報指令 ID = 3042061372016-09-23 21:25:12.587    【指令】收到回報指令 ID = 3042061382016-09-23 21:25:12.597    【回報】600802 : JD01 雞蛋1701 - 已撤單 量:12016-09-23 21:25:12.597    【指令】收到回報指令 ID = 3042061382016-09-23 21:25:12.597    【指令】收到回報指令 ID = 3042061372016-09-23 21:25:12.657    【指令】收到成交回報指令 ORDERID = 3042061372016-09-23 21:25:12.677    【回報】600802 : j1701 - 已成交 1 價格:1250.5 平 賣2016-09-23 21:25:12.677    【回報】600802 : j1701 - 全部成交 12016-09-23 21:27:47.744    【同步】600802 : J01 理論持倉 多1 空0 實際持倉 多0 空02016-09-23 21:27:47.744    【圖表】J01 理論持倉比實際持倉大,需要補倉2016-09-23 21:27:47.764    【下單】J01 價0.000000 量1 買賣0 類型1 開平0 賬戶600802 Formula 12016-09-23 21:27:47.774    【指令】收到回報指令 ID = 3042061392016-09-23 21:27:47.774    【回報】600802 : j1701 - 已報單 1 價格:1250.0 開 買2016-09-23 21:27:47.774    【指令】收到回報指令 ID = 3042061392016-09-23 21:27:47.774    【指令】收到回報指令 ID = 3042061392016-09-23 21:27:47.784    【指令】收到成交回報指令 ORDERID = 3042061392016-09-23 21:27:47.794    【回報】600802 : j1701 - 已成交 1 價格:1249.0 開 買2016-09-23 21:27:47.794    【回報】600802 : j1701 - 全部成交 12016-09-23 21:31:12.647    【下單】P01 價0.000000 量1 買賣1 類型1 開平1 賬戶600802 Formula 12016-09-23 21:31:12.647    【下單】PP01 價0.000000 量1 買賣0 類型1 開平0 賬戶600802 Formula 12016-09-23 21:31:12.663    【指令】收到回報指令 ID = 3042061402016-09-23 21:31:12.725    【回報】600802 : p1701 - 已報單 1 價格:5706 平 賣2016-09-23 21:31:12.742    【指令】收到回報指令 ID = 3042061402016-09-23 21:31:12.742    【指令】收到回報指令 ID = 3042061402016-09-23 21:31:12.793    【指令】收到成交回報指令 ORDERID = 3042061402016-09-23 21:31:12.803    【回報】600802 : p1701 - 已成交 1 價格:5710 平 賣2016-09-23 21:31:12.803    【回報】600802 : p1701 - 全部成交 12016-09-23 21:31:12.853    【指令】收到回報指令 ID = 3042061412016-09-23 21:31:12.863    【回報】600802 : pp1701 - 已報單 1 價格:7079 開 買2016-09-23 21:31:12.903    【指令】收到回報指令 ID = 3042061412016-09-23 21:31:12.913    【回報】600802 : PP01 聚丙烯1701 - 已撤單 量:12016-09-23 21:31:12.913    【指令】收到回報指令 ID = 304206141

 

有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友

可聯系技術人員 QQ: 511411198  點擊這里給我發消息進行 有償 編寫!不貴!點擊查看價格!


【字體: 】【打印文章】【查看評論

相關文章

    沒有相關內容
主站蜘蛛池模板: 日本中文字幕一区 | 日韩一区二区在线观看 | 激情丁香网 | 狠狠色丁香九九婷婷综合五月 | 亚洲欧美18v中文字幕高清 | 日本波多野结衣字幕久久 | 国产在线视频第一页 | 欧美在线看视频 | 日韩日b视频| 一级毛片aa高清免费观看 | 午夜影院啪啪 | 亚洲永久中文字幕在线 | 国产亚洲精品影达达兔 | 在线视频精品播放 | 日本亚州视频在线八a | 国产50页| 亚洲欧美天堂网 | 一个人看的视频www 一个人看的视频www免费 | 欧美午夜春性猛交xxxx | 在线视频亚洲一区 | 一女np男h高h | 国产一区日韩二区欧美三区 | 夜夜嗨视频网 | 日韩性freexxxx在线观看 | 日韩欧美一区二区三区在线观看 | 男女交性过程视频无遮挡在线 | 黑人一区二区三区中文字幕 | 国产成人亚洲毛片 | 97人人做人人添人人爱 | 一区二区在线欧美日韩中文 | 欧美成人免费在线观看 | 日本一区免费 | 日韩精品视频免费在线观看 | 高清一级毛片免免费看 | 丝袜足控免费软件xx | 在线观看免费精品国产 | 亚欧日韩毛片在线看免费网站 | 星空影院免费观看韩国三集 | 日韩视频在线精品视频免费观看 | 日韩中文字幕精品 | 中日韩精品视频在线观看 |