修改了版主代碼,發(fā)出全平模塊(增加下信息資源) [金字塔]
- 咨詢(xún)內(nèi)容:
function GetHoldStr(sAccount) dim i 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 HoldStr=HoldStr & CurCode if BuyHold>0 then call order.sell(1,BuyHold,0,0,CurCode,CurMarket,sAccount,0) end if if SellHold>0 then call order.sellshort(1,SellHold,0,0,CurCode,CurMarket,sAccount,0) end if Next End If End function [此貼子已經(jīng)被作者于2013-5-27 11:07:34編輯過(guò)] - 金字塔客服:
說(shuō)明詳細(xì)一些,另外測(cè)試過(guò)了?
搞好了加精
- 用戶(hù)回復(fù):
測(cè)試過(guò)了 稍后加上說(shuō)明
- 網(wǎng)友回復(fù):
'此模塊中sAccount為傳遞賬號(hào),對(duì)按照某個(gè)時(shí)間(比如15:30)平全部倉(cāng)位的用戶(hù)可以直接調(diào)用此模塊,用call語(yǔ)句就行。可以直接放在模塊中 '也可以復(fù)制代碼到大家做需要的窗體中進(jìn)行調(diào)用。
第一種:'創(chuàng)建了一個(gè)窗體,加上一個(gè)按鈕來(lái)觸發(fā),導(dǎo)入附件后就能使用
Sub UserForm1_CommandButton1_Click()'輸入賬號(hào) call getholdstr(803156) End Sub
'該模塊主要用來(lái)保存宏主執(zhí)行主函數(shù),不要拿做他用
function GetHoldStr(sAccount)'定義所需變量 dim i dim BuyHold dim BuyCost dim SellHold dim SellCost dim CurCode dim CurMarket On Error resume Next'索取持倉(cāng)合約數(shù) HoldingCount=Order.Holding2(sAccount)'遍歷所有持倉(cāng),索取多空頭和持倉(cāng)合約 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 HoldStr=HoldStr & CurCode'取得多頭持倉(cāng),按照事件返回的手?jǐn)?shù)和相關(guān)信息進(jìn)行平多 if BuyHold>0 then call order.sell(1,BuyHold,0,0,CurCode,CurMarket,sAccount,0) end if'取得空頭持倉(cāng),按照事件返回的手?jǐn)?shù)和相關(guān)信息進(jìn)行平空 if SellHold>0 then call order.sellshort(1,SellHold,0,0,CurCode,CurMarket,sAccount,0) end if Next End If End function
下載信息 [文件大小: 下載次數(shù): ]點(diǎn)擊瀏覽該文件:userform1.rar
第二種 適合用vba做日內(nèi)的,'大家也可把function函數(shù)直接放到大家已經(jīng)編輯好的代碼中加上定時(shí)器來(lái)讀取時(shí)間 (定時(shí)器到收盤(pán)15:00進(jìn)行全平操作)
sub application_vbastart() '設(shè)置定時(shí)器,每秒刷新 call application.SetTimer(1,1000)end sub
sub application_timer(id) application.MsgOut(right(now,8)) if id=1 then '輸入自己要日內(nèi)平倉(cāng)時(shí)間 ,now函數(shù)返回的時(shí)間是有日期的 我們用right方法去掉日期。就順利取得時(shí)分秒,^,^ if right(now,8)>="13:23:30" then '輸入自己的賬號(hào) call GetHoldStr(888) end if end if end sub
sub application_vbaend()'刪除定時(shí)器,釋放資源 call application.KillTimer(1) end sub
'插入模塊function GetHoldStr(sAccount)'定義所需變量 dim i dim BuyHold dim BuyCost dim SellHold dim SellCost dim CurCode dim CurMarket On Error resume Next'索取持倉(cāng)合約數(shù) HoldingCount=Order.Holding2(sAccount)'遍歷所有持倉(cāng),索取多空頭和持倉(cāng)合約 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 HoldStr=HoldStr & CurCode'取得多頭持倉(cāng),按照事件返回的手?jǐn)?shù)和相關(guān)信息進(jìn)行平多 if BuyHold>0 then call order.sell(1,BuyHold,0,0,CurCode,CurMarket,sAccount,0) end if'取得空頭持倉(cāng),按照事件返回的手?jǐn)?shù)和相關(guān)信息進(jìn)行平空 if SellHold>0 then call order.sellshort(1,SellHold,0,0,CurCode,CurMarket,sAccount,0) end if Next End If End function
下載信息 [文件大小: 下載次數(shù): ]點(diǎn)擊瀏覽該文件:userform2.rar
- 網(wǎng)友回復(fù): 看來(lái)我那個(gè)帖子已經(jīng)深入人心了,還能做舉一反三,進(jìn)行修改了,擴(kuò)展了,本人深感榮幸。希望有更多的人能熟練掌握vba開(kāi)發(fā)。
有思路,想編寫(xiě)各種指標(biāo)公式,程序化交易模型,選股公式,預(yù)警公式的朋友
可聯(lián)系技術(shù)人員 QQ: 1145508240 進(jìn)行 有償 編寫(xiě)!(不貴!點(diǎn)擊查看價(jià)格!)
相關(guān)文章
-
沒(méi)有相關(guān)內(nèi)容