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


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件交易策略发布专区 → [交易系统]菲阿里突破

   

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


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

主题:[交易系统]菲阿里突破

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


加好友 发短信
等级:新手上路 帖子:30 积分:165 威望:0 精华:0 注册:2012/5/18 13:32:38
  发帖心情 Post By:2012/11/28 17:25:44 [显示全部帖子]

非常感谢楼主的提供,学到了很多东西,我对源代码的一些编绎不过去的也进行了修整。有问题的话请指正O(∩_∩)O~。

以下内容为程序代码:

1 runmode:0;
2
3 variable:longtrade=0;
4 variable:shorttrade=0;
5 variable:stopline=0;
6
7 predayhigh:=callstock(stklabel,vthigh,6,-1); //昨天最高价
8 predaylow:=callstock(stklabel,vtlow,6,-1); //昨天最低价
9 predayrange:=(predayhigh-predaylow)*0.5; //
10 predayrange:=round(predayrange/mindiff)*mindiff;
11
12 dayopen:=callstock(stklabel,vtopen,6,0); //当天开盘价
13
14 trailingstop:=predayrange; //止损是(昨天最高价-昨天最低价)/2
15
16 dist:=barslast(date>ref(date,1))+1;
17
18 myentrytime:=time<=145500;
19 myexittime:=time>=150000;
20
21 upperband:=ref(hhv(high,dist),1);
22 lowerband:=ref(llv(low,dist),1);
23
24 hh:=ref(high,1);
25 ll:=ref(low,1);
26
27 if holding=0 then //没有持仓时,进行条件判断,开单,交易时间段为开盘到14:55分
28     begin
29         if myentrytime and dayopen<=predaylow then
30             begin
31              if high>=predayhigh and longtrade=0 then //今日开盘<昨日最低,最高价突破昨日最高价,开多单
32                     begin
33                         buy(1,1,limitr,max(open,predayhigh));
34                         longtrade:=1;
35                  end
36         
37                 if low<=predaylow and shorttrade=0 then //今日开盘<昨日最低,最低价突破昨日最低价,开空单
38                     begin
39                         buyshort(1,1,limitr,min(open,predaylow));
40                         shorttrade:=1;
41                     end
42         end
43     
44         if myentrytime and dayopen>=predayhigh then
45          begin
46                 if dist>=4 and high>=upperband and longtrade=0 then //今日开盘>昨日最高,当日K线的第四个周期之后,价格创当日新高,开多单
47                 begin
48                     buy(1,1,limitr,max(open,upperband));
49                     longtrade:=1;
50              end
51     end
52     
53         if myentrytime and dayopen<=predaylow then //今日开盘<=昨日最低,当日K线的第四个周期之后,价格创当日新低,开空单
54             begin
55                 if dist>=4 and low<=lowerband and shorttrade=0 then
56                 begin
57                     buyshort(1,1,limitr,min(open,lowerband));
58                     shorttrade:=1;
59                 end
60             end
61     end
62
63 if holding>0 and enterbars>=1 then //持多单进行平仓设置
64     begin
65         myexitprice:=0;
66         
67         if stopline=0 then
68         stopline:=enterprice-trailingstop; //初始止损价格为: 开仓价-(昨日最高-昨日最低)/2
69         
70         if hh-trailingstop>stopline then //当(前一根K线的最高价-trailingstop)>之前的stopline,则重新设置止损线
71         stopline:=hh-trailingstop;
72         
73         if low<=stopline then
74         myexitprice:=min(open,stopline); //跌破止损线,记录平仓价格
75         
76         if myexittime then
77         myexitprice:=close;
78         
79         if myexitprice>0 then //平多单
80             begin
81                 sell(1,holding,limitr,myexitprice);
82                 stopline:=0; //设置止损线为0
83             end
84     end
85
86 if holding<0 and enterbars>=1 then //持空单,进行平仓设置
87     begin
88         myexitprice:=0;
89         
90         if stopline=0 then
91         stopline:=enterprice+trailingstop; //初始止损价格为: 开仓价+(昨日最高-昨日最低)/2
92         
93         if ll+trailingstop<stopline then stopline:=ll+trailingstop; //当(前一根K线的最低价+trailingstop)<之前的stopline,则重新设置止损线
94         
95         if high>=stopline then
96         myexitprice:=max(open,stopline); //上穿止损线,记录平仓价格
97         
98         if myexittime then
99         myexitprice:=close;
100         
101         if myexitprice>0 then
102         begin
103             sellshort(1,holding,limitr,myexitprice);
104             stopline:=0;
105         end
106     end
107
108 if myexittime then
109     begin
110         longtrade:=0;
111         shorttrade:=0;
112     end
113
114

 


 回到顶部