欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件策略编写求助区 → 求帮助

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有4385人关注过本帖树形打印复制链接

主题:求帮助

帅哥哟,离线,有人找我吗?
d6317448
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:6 积分:37 威望:0 精华:0 注册:2012/9/3 14:29:01
求帮助  发帖心情 Post By:2012/10/29 15:14:47 [只看该作者]

请帮忙翻译并改编这这样的

 


此主题相关图片如下:未命名.jpg
按此在新窗口浏览图片

 

k
dim count
count=0

 

dim pingcang
pingcang=""
'全局变量
dim exce1

dim report1ComboBox1
dim report2ComboBox1
       report1ComboBox1=taoli_report1ComboBox.value
       report2ComboBox1=taoli_report2ComboBox.value
     
dim report1
dim report2

   set report1=nothing
   set report2=nothing
  


 
Sub MARKETDATA_ReportNotify(ReportData)
    '显示自定义的最新价格
     display
    if not report1 is nothing and not report2 is nothing then
     taoli_Label1.caption=Report1.newprice
     taoli_Label2.caption=Report2.newprice
     taoli_chajia.caption= Report1.newprice-Report2.newprice
     end if
   '如果有订单为成交,则撤销,以免影响批量下单的进度
     if not report1 is nothing and not report2 is nothing then
           num1=0   '使用于ctp平仓功能变量
           num2=0   '使用于ib平仓功能变量
           ctp=Order.StockType(report1.Label,report1.marketName)
           if ctp=1 then
              num1=Order.OrderInfoByCode2(report1.Label,report1.marketName, OrderID1, ConSign, Filled, R1, Action, OrderType, LmtPrice, Account, Kaiping)
              num2=Order.OrderInfoByCode2(report2.Label,report2.marketName, OrderID2, ConSign, Filled, R2, Action, OrderType, LmtPrice, Account, Kaiping)
           elseif ctp=0 then
              num1=Order.OrderInfoByCode(report1.Label,report1.marketName, OrderID1, ConSign, Filled, R1, Action, OrderType, LmtPrice, Account, Kaiping)
              num2=Order.OrderInfoByCode(report2.Label,report2.marketName, OrderID2, ConSign, Filled, R2, Action, OrderType, LmtPrice, Account, Kaiping)
           end if
     if num1=1 or num2=1 then
        'application.MsgOut count&" 检测撤单中 "&OrderID1
          count=count+1
          
       if count=5 then
           num11=0
           num12=0
           ctp=Order.StockType(report1.Label,report1.marketName)
           if ctp=1 then
              num11=Order.OrderInfoByCode2(report1.Label,report1.marketName, OrderID3, ConSign, Filled, R1, Action, OrderType, LmtPrice, Account, Kaiping)
              num12=Order.OrderInfoByCode2(report2.Label,report2.marketName, OrderID4, ConSign, Filled, R2, Action, OrderType, LmtPrice, Account, Kaiping)
           elseif ctp=0 then
              num11=Order.OrderInfoByCode(report1.Label,report1.marketName, OrderID3, ConSign, Filled, R1, Action, OrderType, LmtPrice, Account, Kaiping)
              num12=Order.OrderInfoByCode(report2.Label,report2.marketName, OrderID4, ConSign, Filled, R2, Action, OrderType, LmtPrice, Account, Kaiping)
           end if
        
           if num11=1 and OrderID1=OrderID3 then
           call Order.CancelOrder(OrderID3)
           'application.MsgOut time()&"  "&report1.Label&"   "&OrderId1&" 111 chedan"&OrderID3
          end if
           if num12=1 and OrderID2=OrderID4 then  
              call Order.CancelOrder(OrderID4)
            'application.MsgOut time()&"  "&report2.Label&"   "&OrderId2&" 222 chedan"&OrderID4
           end if
            k执行" and not report1 is nothing and  taoli_term1price<>"" and  taoli_term1num<>"" and taoli_term1cleanprice<>"" then
          '第一条件的执行       
           diffbuy1=0
           diffsell1=0 
           BuyHoding1=0
           SellHoding1=0
           chicang=0
           ctp=Order.StockType(report1.Label,report1.marketName)
           if ctp=1 then
              call Order.HoldingInfoByCode2(report1.Label,report1.marketName,BuyHoding1,BuyCost,BuyTodayHoding1,SellHoding1,SellCost,SellTodayHoding1,PNL,UseMargin)
         
           elseif ctp=0 then
              call Order.HoldingInfoByCode(report1.Label,report1.marketName, Hold, MktPrice, AvgPrice, MktValue, AgeCost, PNL)
                 if hold>0 then
                   BuyHoding1=Hold                 
                   end if
                 if hold<0 then
                   SellHoding1=-hold                  
                   end if 
             end if            
               diffbuy1=taoli_term1num.value-BuyHoding1
               diffsell1=taoli_term1num.value-SellHoding1
               diff=Report1.newprice-Report2.newprice-taoli_term1price
            
       if instr(taoli_term1ComboBox.value,"大于") <> 0 and diff>0 and k  then
        
              '下列语句在满足条件1 大于实际差价情况下,只对品种1来判断操作,品种2的操作时事件触发
               if instr(report1ComboBox1,"买入") <> 0 and diffbuy1>0  then
                       call Order.Buy(0,1,Report1.SellPrice1,0,Report1.label,Report1.marketname,"",0)
                       k卖出") <> 0 and diffsell1>0  then
                      call Order.BuyShort(0,1,Report1.BuyPrice1,0,Report1.label,Report1.marketname,"",0)
                      k小于") <> 0 and diff<0  and k  then
         
               '下列语句在满足条件1 大于实际差价情况下,只对品种1来判断操作,品种2的操作时事件触发
               if instr(report1ComboBox1,"买入") <> 0 and diffbuy1>0 then
                       call Order.Buy(0,1,Report1.SellPrice1,0,Report1.label,Report1.marketname,"",0)
                       k卖出") <> 0 and diffsell1>0  then
                      call Order.BuyShort(0,1,Report1.BuyPrice1,0,Report1.label,Report1.marketname,"",0)
                       k大于") <> 0 and diff>0  and k and chicang=1 then
           
             if BuyHodingclean1>0  then
                call Order.Sell(0,1,Report1.BuyPrice1,0,report1.Label,report1.marketName,"",0)
                 k",0)
                k小于") <> 0 and diff<0  and k and chicang=1 then
             if BuyHodingclean1>0  then
                call Order.Sell(0,1,Report1.BuyPrice1,0,report1.Label,report1.marketName,"",0)
                 k",0)
                 k执行" then
       chicang=0
         Buyhoding=0
         Sellhoding=0
      
        if not report1 is nothing and not report2 is nothing then
          ctp=Order.StockType(report1.Label,report1.marketName)
            if ctp=1 then
             chicang=Order.HoldingInfoByCode2(report1.Label,report1.marketName,BuyHoding,BuyCost,BuyTodayHoding1,SellHoding,SellCost,SellTodayHoding1,PNL,UseMargin)
          
            elseif ctp=0 then
                Hold=0
                chicang=Order.HoldingInfoByCode(report1.Label,report1.marketName, Hold, MktPrice, AvgPrice, MktValue, AgeCost, PNL)
                 if hold>0 then
                   Buyhoding=Hold
                 end if
                 if hold<0 then
                   Sellhoding=-hold
                 end if
                 if hold=0 then
                   Buyhoding=Hold
                   Sellhoding=hold
                 end if
              end if  
               
             if Buyhoding>0 and k and chicang=1 then
              call Order.Sell(0,1,Report1.BuyPrice1,0,report1.Label,report1.marketName,"",0)
              kzhixing" and chicang=1 then
              call Order.Sellshort(0,1,Report1.SellPrice1,0,report1.Label,report1.marketName,"",0)
              k"
             end if
      end if
    end if
end sub

'当成交量出现变化时发生的事件处理

Sub ORDER_OrderStatusEx(OrderID,Status,Filled,Remaining,Price,Code,Market,OrderType,Aspect,Kaiping)
       'application.MsgOut  time()&code&" aspect "&Aspect&" kaiping "&Kaiping&"  Status  "&Status&Filled
      
   
     if code=UCase(taoli_report1) and status="Filled" then
           
        if kaiping=0 and aspect=0 then
             '品种2开空
            taoli_ts.AddItem time()&" 条件  买入  "&Filled&"手   "&Report1.StockName&"价格为"&Report1.SellPrice1
            call Order.BuyShort(0,Filled,Report2.BuyPrice1,0,Report2.label,Report2.marketname,"",0)
                
           
        elseif kaiping=0 and aspect=1  then
             '品种2开多
            taoli_ts.AddItem time()&" 条件  卖出  "&Filled&"手   "&Report1.StockName&"价格为"&Report1.BuyPrice1
            call Order.Buy(0,Filled,Report2.SellPrice1,0,Report2.label,Report2.marketname,"",0)
                
           
        elseif (kaiping=1 or kaiping=3) and aspect=0 then
             '品种2平多
              taoli_ts.AddItem time()&" 自动平仓      "&Filled&"手   "&Report1.StockName&"价格为"&Report1.BuyPrice1
            call Order.Sell(0,Filled,Report2.BuyPrice1,0,report2.Label,report2.marketName,"",0)
                                
           
        elseif (kaiping=1 or kaiping=3) and aspect=1 then
             '品种2平空
             taoli_ts.AddItem time()&" 自动平仓      "&Filled&"手   "&Report1.StockName&"价格为"&Report1.BuyPrice1
            call Order.Sellshort(0,Filled,Report2.SellPrice1,0,report2.Label,report2.marketName,"",0)
                           
           
        end if
         
      
      elseif code=UCase(taoli_report2) and status="Filled" then
     
           if kaiping=0 and aspect=0 then
             taoli_ts.AddItem time()&" 自动  买入  "&Filled&"手   "&Report2.StockName&"价格为"&Report2.BuyPrice1
             elseif kaiping=0 and aspect=1  then
             taoli_ts.AddItem time()&" 自动  卖出  "&Filled&"手   "&Report2.StockName&"价格为"&Report2.SellPrice1
             elseif (kaiping=1 or kaiping=3) and aspect=0 then
             taoli_ts.AddItem time()&" 自动平仓      "&Filled&"手   "&Report2.StockName&"价格为"&Report2.BuyPrice1
             elseif (kaiping=1 or kaiping=3) and aspect=1 then
             taoli_ts.AddItem time()&" 自动平仓      "&Filled&"手   "&Report2.StockName&"价格为"&Report2.SellPrice1
           end if
           
             k
           
            
      elseif status="Cancelled" and code=UCase(taoli_report2) then
      
        ctp=Order.StockType(report1.Label,report1.marketName)
     
        if taoli_checkbox1.value and ctp=1 then
           'application.MsgOut  "report2 追加 aspect "&Aspect&" kaiping "&Kaiping&"  Status  "&Status
          
          if kaiping=0 and aspect=0  then
                        
            call Order.Buy(0,Remaining,Report2.SellPrice1,0,Report2.label,Report2.marketname,"",0)                 
           
          elseif kaiping=0 and aspect=1  then
          
            call Order.BuyShort(0,Remaining,Report2.BuyPrice1,0,Report2.label,Report2.marketname,"",0)                
           
          elseif (kaiping=1 or kaiping=2) and aspect=0 then
            'application.MsgOut "撤销品种2 后追加平空"
           
            call Order.Sellshort(0,Remaining,Report2.SellPrice1,0,report2.Label,report2.marketName,"",0)          
          
          elseif (kaiping=1 or kaiping=2) and aspect=1 then
           ' application.MsgOut "撤销品种2 后追加平多"        
          
            call Order.Sell(0,Remaining,Report2.BuyPrice1,0,report2.Label,report2.marketName,"",0)    
           
          end if
        elseif not(taoli_checkbox1.value) and ctp=1 then
        
            k
        elseif taoli_checkbox1.value and ctp=0 then
            if  aspect=0 then
             '品种2开空
           
             call Order.Buy(0,Remaining,Report2.SellPrice1,0,Report2.label,Report2.marketname,"",0)           
             elseif  aspect=1  then
             '品种2开多
                    
            call Order.BuyShort(0,Remaining,Report2.BuyPrice1,0,Report2.label,Report2.marketname,"",0)
            end if
         elseif not(taoli_checkbox1.value) and ctp=0 then
             k
         end if
       
      elseif status="Cancelled" and  code=UCase(taoli_report1) then
         
          k
          'application.MsgOut  Aspect&" report1撤销  "&Kaiping
      elseif status="Inactive" and  code=UCase(taoli_report1) then
         
          k
     end if
    
        
  

End Sub


 

'强制平仓
Sub taoli_clearButton_Click()
     exce1=""
    
     pingcang="执行"
     k
End Sub

 


'调试按钮
Sub taoli_CommandButton1_Click()
        application.ClearMsg
      taoli_ts.clear
                  
End Sub


'下面两个过程是生成操作提示
sub display()
           
            Set report1 = marketdata.GetReportData(taoli_report1.text,taoli_report1market)
            Set report2 = marketdata.GetReportData(taoli_report2.text,taoli_report2market)
            
      if  taoli_term1price<>"" and taoli_term1num<>"" and taoli_term1cleanprice<>"" then
        if not report1 is nothing and not report2 is nothing then
            dim s
           s="条件设定成立 当差价"&taoli_term1ComboBox.value&taoli_term1price.text&"时,将进行:"&vbCrLf&"    "
           s=s&report1ComboBox1&taoli_term1num.text&"手  "&report1.stockname&"  "
           s=s&report2ComboBox1&taoli_term1num.text&"手  "&report2.stockname
             if exce1="执行" then
               taoli_display1.caption=s&" 正在执行"
               else
               taoli_display1.caption=s&" 未执行"
              end if
           else
           taoli_display1.caption="条件1设立不足"
           exce1=""
        end if
      end if
end sub

 

Sub taoli_Load()
      taoli_checkbox1.value=true
     
     taoli_term1ComboBox.clear
     taoli_term1ComboBox.AddItem "大于"
     taoli_term1ComboBox.AddItem "小于"
     taoli_term1ComboBox.ListIndex = 0

  

     taoli_report1ComboBox.clear    
     taoli_report1ComboBox.AddItem "买入"
     taoli_report1ComboBox.AddItem "卖出"
     taoli_report1ComboBox.ListIndex = 0

     taoli_report2ComboBox.clear
     taoli_report2ComboBox.AddItem "买入"
     taoli_report2ComboBox.AddItem "卖出"
     taoli_report2ComboBox.ListIndex = 1
   
     taoli_term1cleanComboBox.clear
     taoli_term1cleanComboBox.AddItem "大于"
     taoli_term1cleanComboBox.AddItem "小于"
     taoli_term1cleanComboBox.ListIndex = 1
    
   
 End Sub


 

Sub taoli_executebutton1_Click()
    
   '各个填入控件的约束
 
  
    Set report1 = marketdata.GetReportData(taoli_report1.text,taoli_report1market)
   if  report1 is nothing then
      
       msgbox "品种1代码或市场错误"
       exit sub 
    else
       'Application.MsgOut Report1.stockname&"   "&Report1.NewPrice
   end if
  
   Set report2 = marketdata.GetReportData(taoli_report2.text,taoli_report2market)
   if  report2 is nothing then
    
       msgbox "品种2代码或市场错误"
       exit sub
    else
       'Application.MsgOut Report2.stockname&"   "&Report2.NewPrice
   end if
    
   if taoli_term1price.text="" or not(IsNumeric(taoli_term1price.text)) then
      msgbox "条件开仓差价未填或不是数字"
      exit sub
   end if
 
   if taoli_term1num.text="" or not(IsNumeric(taoli_term1num.text)) or CInt(taoli_term1num.text)<0 then
      if  CInt(taoli_term1num.text)<0 then
       msgbox "条件数量应大于0"
      exit sub
      end if
      msgbox "条件数量未填或不是数字"
      exit sub
   end if
  
   if taoli_term1cleanprice.text="" or not(IsNumeric(taoli_term1cleanprice.text)) then
      msgbox "条件平仓差价未填或不是数字"
      exit sub
   end if
     
  
   taoli_report1market.enabled=false
   taoli_report2market.enabled=false
   report1ComboBox1=taoli_report1ComboBox.value
   report2ComboBox1=taoli_report2ComboBox.value
          
   exce1="执行"
   k
   pingcang=""
End Sub

 


Sub taoli_term1ComboBox_Click()
   
    exce1=""
End Sub


Sub taoli_term1cleanComboBox_Click()
  
    exce1=""
End Sub

 

Sub taoli_report1ComboBox_Click()
       taoli_report2ComboBox.clear
       taoli_report2ComboBox.AddItem "买入"
       taoli_report2ComboBox.AddItem "卖出"
    if taoli_report1ComboBox.ListIndex =0 then
       taoli_report2ComboBox.ListIndex =1
    else
       taoli_report2ComboBox.ListIndex =0
    end if
      
End Sub

Sub taoli_report2ComboBox_Click()
       taoli_report1ComboBox.clear
       taoli_report1ComboBox.AddItem "买入"
       taoli_report1ComboBox.AddItem "卖出"
    if taoli_report2ComboBox.ListIndex =0 then
       taoli_report1ComboBox.ListIndex =1
    else
       taoli_report1ComboBox.ListIndex =0
    end if
     
End Sub


Sub taoli_term1price_Change()
    exce1=""
End Sub

 

Sub taoli_term1num_Change()
     exce1=""
End Sub

 

Sub taoli_term1cleanprice_Change()
    exce1=""
End Sub


Sub taoli_pause_Click()
     exce1=""
     k"
End Sub


Sub taoli_test_Click()
          
    Set report1 = marketdata.GetReportData(taoli_report1.text,taoli_report1market)
   if  report1 is nothing then
      
       msgbox "品种1代码或市场错误"
       exit sub 
    else
   
       'Application.MsgOut Report1.stockname&"   "&Report1.NewPrice
   end if
  
   Set report2 = marketdata.GetReportData(taoli_report2.text,taoli_report2market)
   if  report2 is nothing then
    
       msgbox "品种2代码或市场错误"
       exit sub
    else
    'call marketdata.RegReportNotify(report2.Label,report2.marketName)
      ' Application.MsgOut Report2.stockname&"   "&Report2.NewPrice
   end if
   call marketdata.RegReportNotify(report1.Label,report1.marketName)
    
End Sub


Sub taoli_report1_Change()
     if not report1 is nothing then
          call marketdata.UnRegReportNotify(report1.Label,report1.marketName)
          taoli_report1market.enabled=true
          set report1=nothing
      
     end if
End Sub


Sub taoli_report2_Change()
      if not report2 is nothing then
          call marketdata.UnRegReportNotify(report2.Label,report2.marketName)
          taoli_report2market.enabled=true
          set report2=nothing
        
     end if
End Sub

[此贴子已经被作者于2012-10-29 15:16:21编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
王锋
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:罗宾汉 帖子:11808 积分:20695 威望:0 精华:10 注册:2009/8/18 8:15:13
  发帖心情 Post By:2012/10/29 16:09:42 [只看该作者]

这种复杂的策略改写,金字塔客服无法免费为您服务,请参考下面链接的收费服务

http://www.weistock.com/bbs/dispbbs.asp?boardid=10&Id=9107 



金字塔—专业程序化软件提供商

金字塔-技术部

-----------------------------------------------------------------------------------------------------

工作时间:周一至周五 08:30 - 17:30   周末及法定节假日休息

Email:service@weistock.com
 回到顶部