12评论

3收藏

breakout-zones

avatar admin | 2396 人阅读 | 12 人评论 | 2018-01-19

GBPUSDM30.png

  1. //+------------------------------------------------------------------+
  2. //|  TZ-Breaktout.mq4                                                |
  3. //|  Shimodax                                                        |
  4. //|                                                                  |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright Shimodax"
  7. #property link      "http://www.strategybuilderfx.com/forums/showthread.php?t=15439"

  8. #property indicator_chart_window
  9. #property indicator_buffers 5
  10. #property indicator_color1 Red
  11. #property indicator_color2 Red
  12. #property indicator_color3 LightGray
  13. #property indicator_color4 LightGray
  14. #property indicator_color5 Blue
  15. //----
  16. extern int LocalTimeZone= 2;
  17. extern int DestTimeZone= 6;
  18. extern int PipsForEntry= 5;
  19. //----
  20. double Zone1Upper[];
  21. double Zone2Upper[];
  22. double Zone1Lower[];
  23. double Zone2Lower[];
  24. double SignalsBuffer[];
  25. //+------------------------------------------------------------------+
  26. //| Custom indicator initialization function                         |
  27. //+------------------------------------------------------------------+
  28. int init()
  29.   {
  30.    SetIndexStyle(0,DRAW_LINE);
  31.    SetIndexBuffer(0,Zone1Upper);
  32.    SetIndexEmptyValue(0, 0.0);
  33.    SetIndexStyle(1,DRAW_LINE);
  34.    SetIndexBuffer(1,Zone1Lower);
  35.    SetIndexEmptyValue(1, 0.0);
  36.    SetIndexStyle(2,DRAW_NONE);
  37.    SetIndexBuffer(2,Zone2Upper);
  38.    SetIndexEmptyValue(2, 0.0);
  39.    SetIndexStyle(3,DRAW_NONE);
  40.    SetIndexBuffer(3,Zone2Lower);
  41.    SetIndexEmptyValue(3, 0.0);
  42.    SetIndexStyle(4,DRAW_ARROW);
  43.    SetIndexArrow(4, 156);
  44.    SetIndexBuffer(4, SignalsBuffer);
  45.    return(0);
  46.   }
  47. //+------------------------------------------------------------------+
  48. //|                                                                  |
  49. //+------------------------------------------------------------------+
  50. int deinit()
  51.   {
  52.    return(0);
  53.   }
  54. //+------------------------------------------------------------------+
  55. //| Custom indicator iteration function                              |
  56. //+------------------------------------------------------------------+
  57. int start()
  58.   {
  59.    int counted_bars= IndicatorCounted(),
  60.    lastbar, result;
  61. //----
  62.    if (Bars<=100)
  63.       return(0);
  64.    if (counted_bars>0)
  65.       counted_bars--;
  66. //----
  67.    lastbar= Bars - counted_bars;
  68. //----
  69.    BreakoutRanges(0, lastbar, LocalTimeZone, DestTimeZone);
  70.    return(0);
  71.   }
  72. //+------------------------------------------------------------------+
  73. //| Compute index of first/last bar of yesterday and today           |
  74. //+------------------------------------------------------------------+
  75. int BreakoutRanges(int offset, int lastbar, int tzlocal, int tzdest)
  76.   {
  77.    int i, j, k,
  78.    tzdiff= tzlocal - tzdest,
  79.    tzdiffsec= tzdiff*3600,
  80.    tidxstart[2]= { 0, 0},
  81.    tidxend[2]= { 0, 0 };
  82.    double thigh[2]= { 0.0, 0.0 },
  83.    tlow[2]= { 99999.9, 99999.9 };
  84.    string tfrom[3]= { "04:00", "08:00" ,  /*rest of day: */ "12:00"},
  85.           tto[3]=   { "08:00", "12:00",   /*rest of day: */ "24:00" },
  86.    tday;
  87.    bool inperiod= -1;
  88.    datetime timet;
  89.    // search back for the beginning of the day
  90.    tday= TimeToStr(Time[lastbar]-tzdiffsec, TIME_DATE);
  91.      for( ;lastbar<Bars; lastbar++)
  92.      {
  93.         if (TimeToStr(Time[lastbar] - tzdiffsec, TIME_DATE)!=tday)
  94.         {
  95.          lastbar--;
  96.          break;
  97.         }
  98.      }
  99.    // find the high/low for the two periods and carry them forward through the day
  100.    tday= "XXX";
  101.      for(i= lastbar; i>=offset; i--)
  102.      {
  103.       timet= Time[i] - tzdiffsec;   // time of this bar
  104. //----
  105.       string timestr= TimeToStr(timet, TIME_MINUTES),    // current time HH:MM
  106.       thisday= TimeToStr(timet, TIME_DATE);       // current date
  107.       // for all three periods (first period, second period, rest of day)
  108.         for(j= 0; j<3; j++)
  109.         {
  110.            if (tfrom[j]<=timestr && timestr<tto[j])
  111.            {   // Bar[i] in this period
  112.               if (inperiod!=j)
  113.               { // entered new period, so last one is completed
  114.                  if (j>0)
  115.                  {      // now draw high/low back over the recently completed period
  116.                     for(k= tidxstart[j-1]; k>=tidxend[j-1]; k--)
  117.                     {
  118.                        if (j-1==0)
  119.                        {
  120.                         Zone1Upper[k]= thigh[j-1];
  121.                         Zone1Lower[k]= tlow[j-1];
  122.                        }
  123.                        if (j-1==1)
  124.                        {
  125.                         Zone2Upper[k]= thigh[j-1];
  126.                         Zone2Lower[k]= tlow[j-1];
  127.                        }
  128.                     }
  129.                  }
  130.                inperiod= j;   // remember current period
  131.               }
  132.             if (inperiod==2)   // inperiod==2 (end of day) is just to check completion of zone 2
  133.                break;
  134.             // for the current period find idxstart, idxend and compute high/low
  135.               if (tidxstart[j]==0)
  136.               {
  137.                tidxstart[j]= i;
  138.                tday= thisday;
  139.               }
  140.             tidxend[j]= i;
  141. //----
  142.             thigh[j]= MathMax(thigh[j], High[i]);
  143.             tlow[j]= MathMin(tlow[j], Low[i]);
  144.            }
  145.         }
  146.       // carry forward the periods for which we have definite high/lows
  147.         if (inperiod>=1 && tday==thisday)
  148.         { // first time period completed
  149.          Zone1Upper[i]= thigh[0] + PipsForEntry*Point;
  150.          Zone1Lower[i]= tlow[0] - PipsForEntry*Point;
  151. //----
  152.            if (inperiod>=2)
  153.            {   // second period completed
  154.             Zone2Upper[i]= thigh[1] + PipsForEntry*Point;
  155.             Zone2Lower[i]= tlow[1] - PipsForEntry*Point;
  156.            }
  157.         }
  158.         else
  159.         {   // none yet to carry forward (zero to clear old values, e.g. from switching timeframe)
  160.          Zone1Upper[i]= 0;
  161.          Zone1Lower[i]= 0;
  162.          Zone2Upper[i]= 0;
  163.          Zone2Lower[i]= 0;
  164.         }
  165.       // at the beginning of a new day reset everything
  166.         if (tday!="XXX" && tday!=thisday)
  167.         {
  168.          Print("#", i, "new day ", thisday, "/", tday);
  169. //----
  170.          tday= "XXX";
  171. //----
  172.          inperiod= -1;
  173. //----
  174.            for(j= 0; j<2; j++)
  175.            {
  176.             tidxstart[j]= 0;
  177.             tidxend[j]= 0;
  178.             thigh[j]= 0;
  179.             tlow[j]= 99999;
  180.            }
  181.         }
  182.      }
  183.    return(0);
  184.   }
  185. //+------------------------------------------------------------------+
复制代码
breakout-zones.mq4
""
还没有人打赏,支持一下

评论|共 12 个

依依

发表于 2020-6-10 17:17:27 | 显示全部楼层

路过,学习下

dslapu

发表于 2020-6-22 16:09:44 | 显示全部楼层

学习了,不错,讲的太有道理了

花心的男人

发表于 2020-6-23 14:39:46 | 显示全部楼层

路过,支持一下啦

十项全男

发表于 2020-6-26 10:27:01 | 显示全部楼层

我是来刷分的,嘿嘿

wagiejw

发表于 2020-6-29 20:29:22 | 显示全部楼层

找到好贴不容易,我顶你了,谢了

信和赢汇

发表于 2020-7-2 17:46:15 | 显示全部楼层

我是个凑数的。。。

该死的企鹅

发表于 2020-7-5 10:42:17 | 显示全部楼层

谢谢楼主分享

伊方兰朵

发表于 2020-7-21 18:34:43 | 显示全部楼层

帮你顶下哈!!

用户名

发表于 2020-8-17 22:33:53 | 显示全部楼层

学习了,不错

12下一页
您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则