-- 作者:klc
-- 发布时间:2013/10/23 13:32:58
--
第二部分为金字塔VBA代码,可复制并放入金字塔的任何一个VBA模块中:
dim StartTime dim StartTrade dim HasDoClose
Sub APPLICATION_Start() \'\'\'\'\'\'\'自动启动相应的框架(分日盘、夜盘调出相应图表,请自行叠加相应策略公式) if cdate(time)>cdate("06:00:00") and cdate(time)<cdate("18:00:00") then \'\'\'\'\'\'\'日盘交易,打开框架名“Frame1” application.ActivateFrame "Frame1" else \'\'\'\'\'\'\'夜盘交易,打开框架名“Frame2” application.ActivateFrame "Frame2" end if call application.Settimer(100,30000) \'30秒时钟循环 StartTime = cdate(time) StartTrade = 0 HasDoClose = 0 End Sub
Sub APPLICATION_Timer(ID) if ID=100 then if StartTrade=0 then \'\'\'\'\'\'\'\'\'\'\'\'\'\'启动图表交易 Set Wrap = CreateObject("DynamicWrapper") Wrap.Register "user32.dll","FindWindowA","i=ss","f=s", "r=l" Wrap.Register "user32.dll","FindWindowExA","i=llss","f=s", "r=l" Wrap.Register "user32.dll","SendMessageA","i=lull","f=s", "r=l" WM_LBUTTONDOWN=513 WM_LBUTTONUP=514 h = Wrap.FindWindowA("#32770","图表程式化交易 - 日盘框架 - 交易中") \'框架名称请自行定义,下同 if h=0 then h = Wrap.FindWindowA("#32770","图表程式化交易 - 夜盘框架 - 交易中") if h<>0 then Wrap.PostMessageA h,WM_CLOSE,0,0 StartTrade=1 else h = Wrap.FindWindowA("#32770","金字塔") if h<>0 then h2 = Wrap.FindWindowExA(h,0,"Button","是(&Y)") if h2<>0 then Wrap.SendMessageA h2,WM_LBUTTONDOWN,0,0 Wrap.SendMessageA h2,WM_LBUTTONUP,0,0 end if else h = Wrap.FindWindowA("#32770","图表程式化交易 - 日盘框架 - 已停止") if h=0 then h = Wrap.FindWindowA("#32770","图表程式化交易 - 夜盘框架 - 已停止") if h<>0 then h2 = Wrap.FindWindowExA(h,0,"Button","启动交易") if h2<>0 then Wrap.SendMessageA h2,WM_LBUTTONDOWN,0,0 Wrap.SendMessageA h2,WM_LBUTTONUP,0,0 end if else application.PostMessage(33873) end if end if end if elseif HasDoClose=0 and cdate(time)>cdate("17:30:00") and cdate(time)<cdate("18:00:00") then \'\'\'\'\'\'\'\'17:30~18:00启动收盘 HasDoClose=1 call application.Settimer(5,2000) application.PostMessage(454)\'收盘 elseif (StartTime<cdate("16:00:00") and cdate(time)>cdate("19:00:00") and cdate(time)<cdate("19:30:00")) or ((StartTime<cdate("2:30:00") or StartTime>cdate("6:30:00")) and cdate(time)>cdate("06:00:00") and cdate(time)<cdate("06:30:00")) then \'\'\'\'\'\'\'\'\'\'\'\'\'关闭金字塔程序(早上2:30前或前一日6:30后开启的凌晨6点关闭,下午16点前开启的19点关闭) Set Wrap = CreateObject("DynamicWrapper") Wrap.Register "user32.dll","FindWindowA","i=ss","f=s", "r=l" Wrap.Register "user32.dll","FindWindowExA","i=llss","f=s", "r=l" Wrap.Register "user32.dll","SendMessageA","i=lull","f=s", "r=l" WM_LBUTTONDOWN=513 WM_LBUTTONUP=514 h = Wrap.FindWindowA("#32770","金字塔") if h<>0 then h2 = Wrap.FindWindowExA(h,0,"Button","是(&Y)") if h2<>0 then Wrap.SendMessageA h2,WM_LBUTTONDOWN,0,0 Wrap.SendMessageA h2,WM_LBUTTONUP,0,0 end if else application.PostMessage(57665) end if end if elseif ID=5 then \'\'\'\'\'\'\'\'\'\'\'开始收盘 call application.killtimer(5) Set Wrap = CreateObject("DynamicWrapper") Wrap.Register "user32.dll","FindWindowA","i=ss","f=s", "r=l" Wrap.Register "user32.dll","FindWindowExA","i=llss","f=s", "r=l" Wrap.Register "user32.dll","PostMessageA","i=lull","f=s", "r=l" WM_CLOSE=16 call application.Settimer(7,600000)\'10分钟后关闭收盘窗口 h = Wrap.FindWindowA("#32770","数据管理器") tab=Wrap.FindWindowExA(h,0,"SysTabControl32","Tab1") BM_CLICK=245 h1=Wrap.FindWindowExA(tab,0,"#32770","") do while h1<>0 bt=Wrap.FindWindowExA(h1,0,"Button","执行收盘(&X)") if bt<>0 then Wrap.PostMessageA bt,BM_CLICK,0,0 h1=0 else h1=Wrap.FindWindowExA(tab,h1,"#32770","") end if loop call application.Settimer(6,2000) elseif ID=6 then call application.killtimer(6) BM_CLICK=245 Set Wrap = CreateObject("DynamicWrapper") Wrap.Register "user32.dll","FindWindowA","i=ss","f=s", "r=l" Wrap.Register "user32.dll","FindWindowExA","i=llss","f=s", "r=l" Wrap.Register "user32.dll","PostMessageA","i=lull","f=s", "r=l" h = Wrap.FindWindowA("#32770","金字塔") bt=Wrap.FindWindowExA(h,0,"Button","是(&Y)") Wrap.PostMessageA bt,BM_CLICK,0,0 elseif ID=7 then \'\'\'\'\'\'\'结束收盘 Set Wrap = CreateObject("DynamicWrapper") Wrap.Register "user32.dll","FindWindowA","i=ss","f=s", "r=l" Wrap.Register "user32.dll","FindWindowExA","i=llss","f=s", "r=l" Wrap.Register "user32.dll","PostMessageA","i=lull","f=s", "r=l" WM_CLOSE=16 BM_CLICK=245 h = Wrap.FindWindowA("#32770","金字塔") bt = 0 bt = Wrap.FindWindowExA(h,0,"Button","确定") st = 0 st = Wrap.FindWindowExA(h,0,"Static","收盘作业结束。") if bt<>0 and st<>0 then Wrap.PostMessageA h,WM_CLOSE,0,0 h = Wrap.FindWindowA("#32770","数据管理器") Wrap.PostMessageA h,WM_CLOSE,0,0 call application.killtimer(7) \'SendMail "收盘作业完成","收盘作业完成" \'\'\'\'发信息通知收盘完成,是否需要个人决定 end if end if end sub
|
-- 作者:klc
-- 发布时间:2013/10/24 16:00:17
--
第二部分为金字塔VBA代码,可复制并放入金字塔的任何一个VBA模块中:
dim StartTime dim StartTrade dim HasDoClose
Sub APPLICATION_Start() \'\'\'\'\'\'\'自动启动相应的框架(分日盘、夜盘调出相应图表,请自行叠加相应策略公式) if cdate(time)>cdate("06:00:00") and cdate(time)<cdate("18:00:00") then \'\'\'\'\'\'\'日盘交易,打开框架名“Frame1” application.ActivateFrame "Frame1" else \'\'\'\'\'\'\'夜盘交易,打开框架名“Frame2” application.ActivateFrame "Frame2" end if call application.Settimer(100,30000) \'30秒时钟循环 StartTime = cdate(time) StartTrade = 0 HasDoClose = 0 End Sub
Sub APPLICATION_Timer(ID) if ID=100 then if StartTrade=0 then \'\'\'\'\'\'\'\'\'\'\'\'\'\'启动图表交易 Set Wrap = CreateObject("DynamicWrapper") Wrap.Register "user32.dll","FindWindowA","i=ss","f=s", "r=l" Wrap.Register "user32.dll","FindWindowExA","i=llss","f=s", "r=l" Wrap.Register "user32.dll","SendMessageA","i=lull","f=s", "r=l"
Wrap.Register "user32.dll","PostMessageA","i=lull","f=s", "r=l" WM_LBUTTONDOWN=513 WM_LBUTTONUP=514 h = Wrap.FindWindowA("#32770","图表程式化交易 - 日盘框架 - 交易中") \'框架名称请自行定义,下同 if h=0 then h = Wrap.FindWindowA("#32770","图表程式化交易 - 夜盘框架 - 交易中") if h<>0 then Wrap.PostMessageA h,WM_CLOSE,0,0 StartTrade=1 else h = Wrap.FindWindowA("#32770","金字塔") if h<>0 then h2 = Wrap.FindWindowExA(h,0,"Button","是(&Y)") if h2<>0 then Wrap.SendMessageA h2,WM_LBUTTONDOWN,0,0 Wrap.SendMessageA h2,WM_LBUTTONUP,0,0 end if else h = Wrap.FindWindowA("#32770","图表程式化交易 - 日盘框架 - 已停止") if h=0 then h = Wrap.FindWindowA("#32770","图表程式化交易 - 夜盘框架 - 已停止") if h<>0 then h2 = Wrap.FindWindowExA(h,0,"Button","启动交易") if h2<>0 then Wrap.SendMessageA h2,WM_LBUTTONDOWN,0,0 Wrap.SendMessageA h2,WM_LBUTTONUP,0,0 end if else application.PostMessage(33873) end if end if end if elseif HasDoClose=0 and cdate(time)>cdate("17:30:00") and cdate(time)<cdate("18:00:00") then \'\'\'\'\'\'\'\'17:30~18:00启动收盘 HasDoClose=1 call application.Settimer(5,2000) application.PostMessage(454)\'收盘 elseif (StartTime<cdate("16:00:00") and cdate(time)>cdate("19:00:00") and cdate(time)<cdate("19:30:00")) or ((StartTime<cdate("2:30:00") or StartTime>cdate("6:30:00")) and cdate(time)>cdate("06:00:00") and cdate(time)<cdate("06:30:00")) then \'\'\'\'\'\'\'\'\'\'\'\'\'关闭金字塔程序(早上2:30前或前一日6:30后开启的凌晨6点关闭,下午16点前开启的19点关闭) Set Wrap = CreateObject("DynamicWrapper") Wrap.Register "user32.dll","FindWindowA","i=ss","f=s", "r=l" Wrap.Register "user32.dll","FindWindowExA","i=llss","f=s", "r=l" Wrap.Register "user32.dll","SendMessageA","i=lull","f=s", "r=l" WM_LBUTTONDOWN=513 WM_LBUTTONUP=514 h = Wrap.FindWindowA("#32770","金字塔") if h<>0 then h2 = Wrap.FindWindowExA(h,0,"Button","是(&Y)") if h2<>0 then Wrap.SendMessageA h2,WM_LBUTTONDOWN,0,0 Wrap.SendMessageA h2,WM_LBUTTONUP,0,0 end if else application.PostMessage(57665) end if end if elseif ID=5 then \'\'\'\'\'\'\'\'\'\'\'开始收盘 call application.killtimer(5) Set Wrap = CreateObject("DynamicWrapper") Wrap.Register "user32.dll","FindWindowA","i=ss","f=s", "r=l" Wrap.Register "user32.dll","FindWindowExA","i=llss","f=s", "r=l" Wrap.Register "user32.dll","PostMessageA","i=lull","f=s", "r=l" WM_CLOSE=16 call application.Settimer(7,600000)\'10分钟后关闭收盘窗口 h = Wrap.FindWindowA("#32770","数据管理器") tab=Wrap.FindWindowExA(h,0,"SysTabControl32","Tab1") BM_CLICK=245 h1=Wrap.FindWindowExA(tab,0,"#32770","") do while h1<>0 bt=Wrap.FindWindowExA(h1,0,"Button","执行收盘(&X)") if bt<>0 then Wrap.PostMessageA bt,BM_CLICK,0,0 h1=0 else h1=Wrap.FindWindowExA(tab,h1,"#32770","") end if loop call application.Settimer(6,2000) elseif ID=6 then call application.killtimer(6) BM_CLICK=245 Set Wrap = CreateObject("DynamicWrapper") Wrap.Register "user32.dll","FindWindowA","i=ss","f=s", "r=l" Wrap.Register "user32.dll","FindWindowExA","i=llss","f=s", "r=l" Wrap.Register "user32.dll","PostMessageA","i=lull","f=s", "r=l" h = Wrap.FindWindowA("#32770","金字塔") bt=Wrap.FindWindowExA(h,0,"Button","是(&Y)") Wrap.PostMessageA bt,BM_CLICK,0,0 elseif ID=7 then \'\'\'\'\'\'\'结束收盘 Set Wrap = CreateObject("DynamicWrapper") Wrap.Register "user32.dll","FindWindowA","i=ss","f=s", "r=l" Wrap.Register "user32.dll","FindWindowExA","i=llss","f=s", "r=l" Wrap.Register "user32.dll","PostMessageA","i=lull","f=s", "r=l" WM_CLOSE=16 BM_CLICK=245 h = Wrap.FindWindowA("#32770","金字塔") bt = 0 bt = Wrap.FindWindowExA(h,0,"Button","确定") st = 0 st = Wrap.FindWindowExA(h,0,"Static","收盘作业结束。") if bt<>0 and st<>0 then Wrap.PostMessageA h,WM_CLOSE,0,0 h = Wrap.FindWindowA("#32770","数据管理器") Wrap.PostMessageA h,WM_CLOSE,0,0 call application.killtimer(7) \'SendMail "收盘作业完成","收盘作业完成" \'\'\'\'发信息通知收盘完成,是否需要个人决定 end if end if end sub
注:第一个红色的代码段,是打开夜盘的图表(这里假设日盘和夜盘的图表是不一样的),如果不交易夜盘可以去掉
其他红色字体的东西是你们可能需要修改的,Frame1、日盘图表。。。。这些,需要根据你实际的框架名称来设定
绿色字体部分,是原来代码中漏掉的一句,必须加上,否则会vba出错
橙色字体的是自动收盘的,如果不需要就删除。
|