设为首页收藏本站

 找回密码
 注册
查看: 2353|回复: 2
打印 上一主题 下一主题

公式含有全局变量为何优化不正确? [复制链接]

Rank: 5Rank: 5

精华
0
UID
26187
积分
863
帖子
173
主题
61
阅读权限
60
注册时间
2011-2-19
最后登录
2022-7-6
跳转到指定楼层
1#
发表于 2013-2-23 17:37:42 |只看该作者 |倒序浏览
用穿堂风的R-Breaker测试,优化结果见图:
而测试报告的结果是:
按理测试报告和优化结果第一行的数据一致,为何会不同?一致怀疑公式含有全局变量或数据库会导致优化不准。大家有无解决办法?附RB代码:
  1. //------------------------------------------------------------------------
  2. // 简称: R_Breaker
  3. // 名称:
  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. // 编译版本        GS2010.12.08
  138. // 用户版本        2011/06/27 14:29
  139. // 版权所有        
  140. // 更改声明        TradeBlazer Software保留对TradeBlazer平台
  141. //                        每一版本的TrabeBlazer公式修改和重写的权利
  142. //------------------------------------------------------------------------
复制代码
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
宁静思远

Rank: 3Rank: 3

精华
0
UID
112423
积分
147
帖子
105
主题
3
阅读权限
40
注册时间
2012-9-10
最后登录
2018-2-26
2#
发表于 2013-2-23 19:42:22 |只看该作者
测试结果都会有误差的,比如换台电脑,结果又不一样了,这个不必太纠结,上模拟盘测试看看

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
26187
积分
863
帖子
173
主题
61
阅读权限
60
注册时间
2011-2-19
最后登录
2022-7-6
3#
发表于 2013-2-23 21:14:52 |只看该作者
谢谢ls,从图上的数据可以看出绝非误差

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-5-13 02:18

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部