以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  高级功能研发区  (http://weistock.com/bbs/list.asp?boardid=5)
----  请问老师,我想达到条件时开仓做空,用MARKETDATA_ReportNotify来追踪止损下面的代码对吗?  (http://weistock.com/bbs/dispbbs.asp?boardid=5&id=62986)

--  作者:rhymesky
--  发布时间:2014/3/21 16:07:59
--  请问老师,我想达到条件时开仓做空,用MARKETDATA_ReportNotify来追踪止损下面的代码对吗?
请问各位老师,我想达到条件时开仓做空,用MARKETDATA_ReportNotify来追踪止损下面的代码对吗?这样在价格达到止损价格是,是马上能够触发吗?

Sub Test2(code,market,price,stopprice)
call marketdata.RegReportNotify(code,market)

order.OrderQueue = 1
if Hour(Time) >09 and Hour(Time) <=14 and SellHolding= 0 then
call order.buyshort(0,2,price,stopprice,code,market,"",0)  \'这里下限价单,能行吗?

end if


End Sub


Sub MARKETDATA_ReportNotify(ReportData)

  \'得到这品种的行情报价
set ReportData = MarketData.GetReportData(code,market)
   

 

 \'取指定持仓品种信息
call Order.HoldingInfoByCode2(code,market,BuyHoding1,BuyCost,BuyTodayHoding1,SellHoding1,SellCost,SellTodayHoding1,PNL,UseMargin)
 \'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'品种信息

     call order.Contract(code,market, Multipliter, MinTick, ShortPercent, LongPercent)
 

if Hour(Time) >=09 and Hour(Time) <=14 and SellHolding > 0 then
\'止损时的报价是止损价格+10点,保证必须成交
if ReportData.buyPrice1 >= (zsprice) then
  call Order.Sellshort(0,2,ReportData.buyPrice1+MinTick*2,0,code,market,"",0)
  application.MsgOut "注意!!!到达止损价格!!!"
  end if

\'达到2倍止损距离时,平仓1手,保留1手人工平仓。
\'止损时的报价是止损价格+5点,保证必须成交
if ReportData.SellPrice1 <= (kcprice-(zsprice-kcprice)*2) then
  call Order.Sellshort(0,1,ReportData.SellPrice1+MinTick*2,0,code,market,"",0)
  application.MsgOut "到达第一目标价格!!!"
  end if


\'达到5倍止损距离时,全部平仓。
if ReportData.SellPrice1 <= (kcprice-(zsprice-kcprice)*5) then
  call Order.Sellshort(1,1,ReportData.SellPrice1+MinTick*2,0,code,market,"",0)
  application.MsgOut "到达最终目标,剩余仓位全部平仓!!!"
  end if
end if
End Sub

--  作者:王锋
--  发布时间:2014/3/21 18:19:42
--  

具体你用一下调试手段就可以了。

此外你要注意一下,下单前你要判断是否有未成交单存在,或者下单后保留委托ID,待收到该委托ID的成交回报或者下单撤单失败回报等情况后重置状态,这样防止出现连续交易的现象

[此贴子已经被作者于2014/3/21 18:20:50编辑过]

--  作者:rhymesky
--  发布时间:2014/3/21 19:55:31
--  
谢谢您的回复,我刚接触金字塔的VBA没多久,不知道怎么用调试的功能。您有没有相关的例子介绍给我?谢谢了
--  作者:rhymesky
--  发布时间:2014/3/21 20:15:07
--  
“下单前你要判断是否有未成交单存在,或者下单后保留委托ID,待收到该委托ID的成交回报或者下单撤单失败回报等情况后重置状态,这样防止出现连续交易的现象” 还有您说的这些,不知道怎么弄啊。请问代码在哪能查到?