14评论

1收藏

3shadeopen

avatar 老王吧 | 6935 人阅读 | 14 人评论 | 2016-04-22

EURUSDM30.png

  1. //+------------------------------------------------------------------+
  2. //|                                                      3shadeopen.mq4 |
  3. //|                                         Copyright © 2006, sx ted |
  4. //| Purpose: shade New York or other sessions for chart time frames  |
  5. //|          M1 to H4 (at a push).                                   |
  6. //| version: 2 - enhanced for speed but with MT4 beeing so fast no   |
  7. //|              difference will be noticed, all the sessions are    |
  8. //|              shaded in the init(), last session if it is current |
  9. //|              is widened in the start() in lieu of repainting all.|
  10. //+------------------------------------------------------------------+
  11. #property copyright "Copyright © 2006, sx ted"
  12. #property link      ""

  13. #property indicator_chart_window

  14. //---- input parameters
  15. extern color     ShadeColor=Gold;

  16. /*
  17. // if in Moscow
  18. #define NY_OPEN_HH   17 // NY session open hour
  19. #define NY_OPEN_MM   30 // NY session open minutes
  20. #define NY_CLOSE_HH  00 // NY session close hour
  21. #define NY_CLOSE_MM  05 // NY session close minutes
  22. */


  23. /* if in London
  24. #define NY_OPEN_HH   14 // NY session open hour
  25. #define NY_OPEN_MM   30 // NY session open minutes
  26. #define NY_CLOSE_HH  21 // NY session close hour
  27. #define NY_CLOSE_MM  05 // NY session close minutes
  28. */


  29. // if in New York
  30. #define NY_OPEN_HH   06 // NY session open hour
  31. #define NY_OPEN_MM   30 // NY session open minutes
  32. #define NY_CLOSE_HH  13 // NY session close hour
  33. #define NY_CLOSE_MM  05 // NY session close minutes


  34. #define MAX_DAYS_TO_SHADE  5 // maximum number of days back from last chart date to be shaded

  35. //---- global variables to program
  36. string obj[]; //array of object names
  37. int    iPrevious=0, iStart=-1, iEnd;
  38. double dLow, dHigh;

  39. //+------------------------------------------------------------------+
  40. //| Custom indicator initialization function                         |
  41. //+------------------------------------------------------------------+
  42. int init()
  43.   {
  44.    if(Period()>PERIOD_H4) return(0); // no shading required
  45.    int iMaxBarsOnChart=iBars(NULL,0), i, iBarDay, iBarTime;
  46.    // find approximate start of first day to shade
  47.    int iBarsToDo=MathMin((MAX_DAYS_TO_SHADE*PERIOD_D1)/Period(),iMaxBarsOnChart);
  48.    // find start of first day to shade
  49.    for(i=iBarsToDo; i<iMaxBarsOnChart; i++)
  50.      {
  51.       iBarDay=TimeYear(Time[i])*PERIOD_MN1*12+TimeMonth(Time[i])*PERIOD_MN1+TimeDay(Time[i])*PERIOD_D1;
  52.       iBarTime=iBarDay+TimeHour(Time[i])*60+TimeMinute(Time[i]);
  53.       if(iBarTime>=iBarDay+NY_OPEN_HH*60+NY_OPEN_MM && iBarTime<=iBarDay+NY_CLOSE_HH*60+NY_CLOSE_MM) iStart=i;
  54.       else if(iStart>-1) break;
  55.      }
  56.    if(iStart>-1) iBarsToDo=iStart;
  57.    iStart=-1;
  58.    // shade previous sessions and current session if started
  59.    for(i=iBarsToDo; i>=0; i--)
  60.      {
  61.       iBarDay=TimeYear(Time[i])*PERIOD_MN1*12+TimeMonth(Time[i])*PERIOD_MN1+TimeDay(Time[i])*PERIOD_D1;
  62.       iBarTime=iBarDay+TimeHour(Time[i])*60+TimeMinute(Time[i]);
  63.       if(iBarTime>=iBarDay+NY_OPEN_HH*60+NY_OPEN_MM && iBarTime<=iBarDay+NY_CLOSE_HH*60+NY_CLOSE_MM)
  64.         {
  65.          if(iBarDay==iPrevious)   // current NY session
  66.            {
  67.             dLow =MathMin(dLow,  Low[i]);
  68.             dHigh=MathMax(dHigh, High[i]);
  69.            }
  70.          else                     // new NY session
  71.            {
  72.             dLow=Low[i];
  73.             dHigh=High[i];
  74.             iStart=i;
  75.             iPrevious=iBarDay;
  76.            }      
  77.          iEnd=i;
  78.         }
  79.       else if(iStart>-1)
  80.         {
  81.          PaintRectangle();
  82.          iStart=-1;
  83.         }  
  84.      }
  85.    if(iStart>-1) PaintRectangle(); // paint the last one if session not closed
  86.    return(0);
  87.   }
  88. //+------------------------------------------------------------------+
  89. //| Custom indicator deinitialization function                       |
  90. //+------------------------------------------------------------------+
  91. int deinit()
  92.   {
  93.    int iaCount=ArraySize(obj);
  94.    for(int i=0; i<iaCount; i++)
  95.      {
  96.       if(ObjectFind(obj[i])>-1) ObjectDelete(obj[i]);
  97.      }
  98.    return(0);
  99.   }
  100. //+------------------------------------------------------------------+
  101. //| Custom indicator iteration function                              |
  102. //+------------------------------------------------------------------+
  103. int start()
  104.   {
  105.    int i=0, iBarDay, iBarTime;
  106.    iBarDay=TimeYear(Time[i])*PERIOD_MN1*12+TimeMonth(Time[i])*PERIOD_MN1+TimeDay(Time[i])*PERIOD_D1;
  107.    iBarTime=iBarDay+TimeHour(Time[i])*60+TimeMinute(Time[i]);
  108.    if(iBarTime>=iBarDay+NY_OPEN_HH*60+NY_OPEN_MM && iBarTime<=iBarDay+NY_CLOSE_HH*60+NY_CLOSE_MM)
  109.      {
  110.       if(iBarDay==iPrevious)   // current NY session
  111.         {
  112.          dLow =MathMin(dLow,  Low[i]);
  113.          dHigh=MathMax(dHigh, High[i]);
  114.         }
  115.       else                     // new NY session
  116.         {
  117.          dLow=Low[i];
  118.          dHigh=High[i];
  119.          iStart=i;
  120.          iPrevious=iBarDay;
  121.         }      
  122.       iEnd=i;
  123.       PaintRectangle();
  124.      }
  125.    return(0);
  126.   }
  127. //+------------------------------------------------------------------+
  128. //| Paint rectangle                                                  |
  129. //+------------------------------------------------------------------+
  130. void PaintRectangle()
  131.   {
  132.    string sObj="ShadeNY_"+DoubleToStr(iPrevious, 0); // name for the object
  133.    if(ObjectFind(sObj)>-1)
  134.      {
  135.       // current session object found, so just widen it
  136.       ObjectSet(sObj,OBJPROP_PRICE1,dLow-Point);
  137.       ObjectSet(sObj,OBJPROP_TIME2 ,Time[iEnd]);
  138.       ObjectSet(sObj,OBJPROP_PRICE2,dHigh+Point);
  139.      }
  140.    else
  141.      {
  142.       // otherwise create new object for the session
  143.       int iaCount=ArraySize(obj);
  144.       ArrayResize(obj, iaCount+1);
  145.       obj[iaCount]=sObj;
  146.       ObjectCreate(sObj,OBJ_RECTANGLE,0,Time[iStart],dLow-Point,Time[iEnd],dHigh+Point);
  147.       ObjectSet(sObj,OBJPROP_COLOR,ShadeColor);
  148.      }
  149.   }     
  150. //+------------------------------------------------------------------+
复制代码


3shadeopen.zip
""
还没有人打赏,支持一下

评论|共 14 个

abiao915659

发表于 2016-5-18 15:05:40 | 显示全部楼层


瞬间的光辉 的全套EA教程视频(带讲课源码和讲义)
土豆可以搜到部分视频教程,我花钱买了全套的,
加Q2011108529 免费送

hijk345

发表于 2018-6-5 06:53:20 | 显示全部楼层

好哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈和

awcyj

发表于 2020-4-12 22:08:46 | 显示全部楼层

过来看看的

相依爲命

发表于 2020-6-16 19:57:17 | 显示全部楼层

学习了,谢谢分享、、、

飞火流星

发表于 2020-6-24 19:39:33 | 显示全部楼层

好好 学习了 确实不错

故乡

发表于 2020-7-11 10:00:47 | 显示全部楼层

学习了,不错

淡定哥

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

帮你顶下哈!!

赵四

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

帮你顶下哈!!

btclyb85

发表于 2020-7-31 14:03:48 | 显示全部楼层

谢谢楼主分享

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

EA之家评论守则