登陆/注册 搜索

USERCENTER

SEARCHSITE

搜索

查看: 2797

[其它] 股指专用量化交易源码

[复制链接]

271

主题

874

回帖

1万

活跃度

发贴达人回帖达人实名认证

交易家实盘认证 发表于 2019-11-11 15:46:12 | 显示全部楼层 | 关注 | 私信
老外的作品,国人的翻译。自1993 年公开发布以来,系统的交易法则没有改变过,该系统已经在市场上存活了14 年之久。该系统为日内交易策略,不持仓过夜。出场指令为止损或是收盘。该系统的特点是,交易量低,结合了趋势和反转两种交易方法,既进行趋势交易也进行反转交易。尤其是当指数的日内波动较大时,该系统的收益更好;

如下图,测试时间为2019年4月1日至2019年11月11日15点44分
if.png
源码如下:
  1. //------------------------------------------------------------------------
  2. // 简称: IF4
  3. // 名称: IF4
  4. // 类别: 公式应用
  5. // 类型: 用户应用
  6. // 输出:
  7. //------------------------------------------------------------------------
  8. // 简称: R_Breaker
  9. Params
  10. Numeric notbef(9.00);
  11. Numeric notaft(14.55);
  12. Numeric f1(0.35);
  13. Numeric f2(0.07);
  14. Numeric f3(0.25);
  15. Numeric reverse(1.00);
  16. Numeric rangemin(0.2);
  17. Numeric xdiv(3);
  18. Vars
  19. NumericSeries ssetup(0);
  20. NumericSeries bsetup(0);
  21. NumericSeries senter(0);
  22. NumericSeries benter(0);
  23. NumericSeries bbreak(0);
  24. NumericSeries sbreak(0);
  25. NumericSeries ltoday(0);
  26. NumericSeries hitoday(9999);
  27. NumericSeries startnow(0);
  28. NumericSeries div(0);
  29. BoolSeries rfilter(false);
  30. Numeric i_reverse;
  31. Numeric i_rangemin;
  32. Numeric i_vB;
  33. Numeric i_vS;
  34. Begin
  35. i_reverse = reverse*(OpenD(0)/100);
  36. i_rangemin = rangemin*(OpenD(0)/100);
  37. if(BarStatus==0)
  38. {
  39.          startnow=0;
  40.          div=max(xdiv,1);
  41. }
  42. if(Date != Date[1])
  43. {
  44.          SetGlobalVar(0,0);
  45.          SetGlobalVar(1,0);
  46.          startnow=startnow+1;
  47.          ssetup=hitoday[1]+f1*(Close[1]-ltoday[1]);
  48.          senter=((1+f2)/2)*(hitoday[1]+Close[1])-(f2)*ltoday[1];
  49.          benter=((1+f2)/2)*(ltoday[1]+Close[1])-(f2)*hitoday[1];
  50.          bsetup=ltoday[1]-f1*(hitoday[1]-Close[1]);
  51.          bbreak=ssetup+f3*(ssetup-bsetup);
  52.          sbreak=bsetup-f3*(ssetup-bsetup);

  53.         hitoday=High;
  54.          ltoday=Low;

  55.         rfilter=(hitoday[1]-ltoday[1])>=i_rangemin;
  56. }
  57. if(High>hitoday)
  58. {
  59.          hitoday=High;
  60. }
  61. if(Low<ltoday)
  62. {
  63.          ltoday=Low;
  64. }
  65. if(Time*100>=notbef and Time*100<notaft and startnow>=2 and rfilter)
  66. {
  67.         if(Time != GetGlobalVar(1) and GetGlobalVar(1) != 0)
  68.          {
  69.                  SetGlobalVar(1,10000);
  70.          }
  71.          if(hitoday>=ssetup and marketposition>-1 and GetGlobalVar(1)<1)
  72.          {
  73.                  If(Low<=(senter+(hitoday-ssetup)/div))
  74.                  {
  75.                          SellShort(1,senter+(hitoday-ssetup)/div);
  76.                          SetGlobalVar(1,Time);
  77.                          Return;
  78.                  }
  79.          }
  80.          if(ltoday<=bsetup and marketposition<1  and GetGlobalVar(1)<1)
  81.          {
  82.                  If(High>=(benter-(bsetup-ltoday)/div))
  83.                  {
  84.                          Buy(1,benter-(bsetup-ltoday)/div);
  85.                          SetGlobalVar(1,Time);
  86.                          Return;
  87.                  }
  88.          }
  89.         if(marketposition==-1)
  90.          {
  91.                  SetGlobalVar(0,1);
  92.                  if(High-EntryPrice>=i_reverse)
  93.                  {
  94.                          BuyToCover(1,entryprice+i_reverse);
  95.                          Return;
  96.                  }
  97.          }
  98.          if(marketposition==1)
  99.          {
  100.                  SetGlobalVar(0,1);
  101.                  if(EntryPrice-Low>=i_reverse)
  102.                  {
  103.                          Sell(1,entryprice-i_reverse);
  104.                          Return;
  105.                  }
  106.          }

  107.         if(marketposition==0)
  108.          {
  109.                  if(High>=bbreak and GetGlobalVar(0) == 0)
  110.                  {
  111.                          Buy(1,bbreak);
  112.                          Return;
  113.                  }
  114.          }
  115.          if(marketposition==0)
  116.          {
  117.                  if(low<=sbreak  and GetGlobalVar(0) == 0)
  118.                  {
  119.                          SellShort(1,sbreak);
  120.                          Return;
  121.                  }
  122.          }

  123. }
  124. if(Time*100>=notaft and Time<0.1600)
  125. {
  126.         if(marketposition==-1)
  127.          {
  128.                  BuyToCover(1,Open);
  129.          }
  130.          if(marketposition==1)
  131.          {
  132.                  Sell(1,Open);
  133.          }
  134. }
  135. End
  136. //------------------------------------------------------------------------
  137. // 编译版本        GS2015.12.25
  138. // 用户版本        2019/11/11 15:21:34
  139. // 版权所有        24KRMB
复制代码
头像被屏蔽

15

主题

124

回帖

137

活跃度

发贴达人回帖达人

zma 发表于 2019-11-14 14:37:34 | 显示全部楼层 | 关注 | 私信
提示: 由于存在违规,该用户被关进了小黑屋(拉黑)。内容自动屏蔽

0

主题

12

回帖

44

活跃度
asbenmao 发表于 2021-3-14 09:24:13 | 显示全部楼层 | 关注 | 私信
不知道适用于A股不

5

主题

266

回帖

1046

活跃度

回帖达人实盘认证实名认证

Kilig实盘认证 发表于 2022-7-9 07:23:31 | 显示全部楼层 | 关注 | 私信
已拜读,感谢分享

10

主题

537

回帖

6489

活跃度

回帖达人实盘认证实名认证

youbin9实盘认证 发表于 2022-9-20 12:02:53 | 显示全部楼层 | 关注 | 私信
虽然不太懂,但源码必顶

0

主题

906

回帖

2210

活跃度

回帖达人实盘认证实名认证

铅华浮尘实盘认证 发表于 2022-10-20 00:46:30 | 显示全部楼层 | 关注 | 私信
谢谢分享,好好学习下量化交易代码
温馨提示
无充值,无付费,唯一微信公众号24KRMB,珍惜账号,理性讨论 知道啦

评论管理|实名认证|黑名单|手机版|倡议书|版权声明|24KRMB ( 鄂ICP备19016902号 )

GMT+8, 2024-10-18 21:25 , Processed in 1.024866 second(s), 44 queries , Gzip On.

Copyright © 2012-2024 24KRMB.COM

Powered by 阿里云提供驱动 UI: 240701

快速回复 返回列表