6评论

0收藏

EmacRectangle

avatar admin | 1324 人阅读 | 6 人评论 | 2018-01-19

GBPUSDH1.png

  1. //+-------------------------------------------------------------------+
  2. //|                                                EmacRectangle.mq4  |
  3. //|                                             3EMA Cross Rectangle  |
  4. //+-------------------------------------------------------------------+

  5. #property      indicator_chart_window
  6. #property      indicator_buffers 2

  7. #property      indicator_color1  clrLime
  8. #property      indicator_width1  2
  9. #property      indicator_color2  clrMagenta
  10. #property      indicator_width2  2

  11. extern int     EMA1                                = 3;
  12. extern int     EMA2                                = 21;
  13. extern int     EMA3                                = 63;
  14. extern double  arrowDistance                       = 0.0003;
  15. extern color   upRectColor                         = clrYellow;
  16. extern color   dnRectColor                         = clrDodgerBlue;
  17. extern color   touchRectColor                      = clrDarkGray;
  18. //---
  19. extern double  rectHigh                            = 0.0001;
  20. extern int     rectDays                            = 3;   
  21. extern int     bars_limit                          = 2000;  
  22. extern bool    showRectangle                       = true;                  
  23.       
  24. double upArrow[];
  25. double dnArrow[];
  26. double prev2EMA1, prev2EMA2, prev2EMA3;
  27. double prevEMA1, prevEMA2, prevEMA3;
  28. double curEMA1, curEMA2, curEMA3;
  29. double prevOpenPrc, prevClosePrc, prevLowPrc, prevHighPrc;
  30. string objRectName;
  31. string rectArray[];   
  32. string indiName                                    = "Emac";
  33. int    rectValidity                                = 0;  
  34. int    arrayMaxAmounts                             = 99999;
  35. int    arrayCurAmount                              = 0;
  36. int    arrayLastAmount                             = 0;

  37. //+------------------------------------------------------------------+
  38. //| INIT()                                                           |
  39. //+------------------------------------------------------------------+
  40. int init()  {
  41.    if (Period() != PERIOD_H1) {
  42.       Alert("Use only [url=home.php?mod=space&uid=73392]@[/url] TF: H1");
  43.       return(0);
  44.    }
  45.    ArrayResize(rectArray,arrayMaxAmounts,arrayMaxAmounts);
  46.    IndicatorBuffers(2);
  47.    SetIndexBuffer(0,upArrow);
  48.    SetIndexBuffer(1,dnArrow);
  49.    SetIndexStyle(0,DRAW_ARROW);
  50.    SetIndexStyle(1,DRAW_ARROW);
  51.    SetIndexArrow(0,233);
  52.    SetIndexArrow(1,234);
  53.    SetIndexEmptyValue(0,0.0);
  54.    SetIndexEmptyValue(1,0.0);
  55.    SetIndexLabel(0,"Up");
  56.    SetIndexLabel(1,"Dn");
  57.    return(0);
  58. }

  59. //+------------------------------------------------------------------+
  60. //| DEINIT()                                                         |
  61. //+------------------------------------------------------------------+
  62. int deinit() {
  63.   int k=0;
  64.   while (k<ObjectsTotal())   {
  65.     string objname = ObjectName(k);
  66.     if (StringSubstr(objname,0,StringLen("Emac")) == "Emac")  
  67.       ObjectDelete(objname);
  68.     else
  69.       k++;
  70.   }   
  71.   return(0);
  72. }

  73. //+------------------------------------------------------------------+
  74. //| START()                                                          |
  75. //+------------------------------------------------------------------+
  76. int start() {
  77.    if (Period() != PERIOD_H1) {
  78.       Alert("Use only @ TF: H1");
  79.       return(0);
  80.    }
  81.    int limit,i,k;
  82.    int counted_bars=IndicatorCounted();
  83.    //---- last counted bar will be recounted
  84.    if(counted_bars>0) counted_bars--;
  85.    limit=Bars-counted_bars;
  86.    //---
  87.    if (limit>bars_limit-1 && bars_limit!=0) limit=bars_limit-1;
  88.    if (Bars<EMA1 || Bars<EMA2 || Bars<EMA3 || (bars_limit>0 && bars_limit<EMA1) || (bars_limit>0 && bars_limit<EMA2) || (bars_limit>0 && bars_limit<EMA3))   {
  89.       Alert("Adjust limit settings or put more bars on your chart!");
  90.       return(0);
  91.    }
  92.    //---
  93.    for (i=0; i<limit; i++)    {
  94.       prev2EMA1      = iMA(NULL,0,EMA1,0,MODE_EMA,PRICE_CLOSE,i+2);
  95.       prev2EMA2      = iMA(NULL,0,EMA2,0,MODE_EMA,PRICE_CLOSE,i+2);
  96.       prev2EMA3      = iMA(NULL,0,EMA3,0,MODE_EMA,PRICE_CLOSE,i+2);
  97.       prevEMA1       = iMA(NULL,0,EMA1,0,MODE_EMA,PRICE_CLOSE,i+1);
  98.       prevEMA2       = iMA(NULL,0,EMA2,0,MODE_EMA,PRICE_CLOSE,i+1);
  99.       prevEMA3       = iMA(NULL,0,EMA3,0,MODE_EMA,PRICE_CLOSE,i+1);
  100.       curEMA1        = iMA(NULL,0,EMA1,0,MODE_EMA,PRICE_CLOSE,i);
  101.       curEMA2        = iMA(NULL,0,EMA2,0,MODE_EMA,PRICE_CLOSE,i);
  102.       curEMA3        = iMA(NULL,0,EMA3,0,MODE_EMA,PRICE_CLOSE,i);
  103.       prevOpenPrc    = iOpen(NULL,0,i+1);
  104.       prevClosePrc   = iClose(NULL,0,i+1);
  105.       prevLowPrc     = iLow(NULL,0,i+1);
  106.       prevHighPrc    = iHigh(NULL,0,i+1);
  107.       rectValidity   = rectDays*86400;
  108.          
  109.       if ( (prev2EMA1<prev2EMA2)&&(prevEMA1>=prevEMA2)&&(curEMA1>curEMA2)&&(prevEMA2>=prevEMA3)&&(curEMA2>curEMA3) ) {  // up
  110.          upArrow[i+1] = prevLowPrc - arrowDistance;
  111.          if (showRectangle == true) {
  112.             //-----------------------  Draw Rectangle ----------------------
  113.             objRectName = StringConcatenate(indiName,"_",FuncPeriodToStr(Period()),"_",DoubleToStr(Time[i+1],0));
  114.             if (ObjectFind(objRectName) == -1)    {    // not exists   
  115.                ObjectCreate(objRectName, OBJ_RECTANGLE, 0,Time[i+1],prevLowPrc,Time[i+1]+rectValidity,prevLowPrc+rectHigh);
  116.                ObjectSet(objRectName, OBJPROP_COLOR, upRectColor);
  117.                ObjectSet(objRectName, OBJPROP_WIDTH, 0);
  118.                ObjectSet(objRectName, OBJPROP_STYLE, STYLE_SOLID);
  119.                //--- put information to Array ---
  120.                arrayCurAmount             = ArraySize(rectArray);
  121.                rectArray[arrayCurAmount]  = StringConcatenate(objRectName,"$up$",Time[i+1],"$",prevClosePrc,"$0");  // 0=new, not yet touched
  122.       
  123.             }   // if
  124.          } // if
  125.       } // if
  126.          
  127.       if ( (prev2EMA1>prev2EMA2)&&(prevEMA1<=prevEMA2)&&(curEMA1<curEMA2)&&(prevEMA2<=prevEMA3)&&(curEMA2<curEMA3) ) {  // down
  128.          dnArrow[i+1] = prevHighPrc + arrowDistance;
  129.          if (showRectangle == true) {
  130.             //-----------------------  Draw Rectangle ----------------------
  131.             objRectName = StringConcatenate(indiName,"_",FuncPeriodToStr(Period()),"_",DoubleToStr(Time[i+1],0));
  132.             if (ObjectFind(objRectName) == -1)    {    // not exists   
  133.                ObjectCreate(objRectName, OBJ_RECTANGLE, 0, Time[i+1],prevHighPrc,Time[i+1]+rectValidity,prevHighPrc-rectHigh);
  134.                ObjectSet(objRectName, OBJPROP_COLOR, dnRectColor);
  135.                ObjectSet(objRectName, OBJPROP_WIDTH, 0);
  136.                ObjectSet(objRectName, OBJPROP_STYLE, STYLE_SOLID);
  137.                //--- put information to Array ---
  138.                arrayCurAmount             = ArraySize(rectArray);
  139.                rectArray[arrayCurAmount]  = StringConcatenate(objRectName,"$dn$",Time[i+1],"$",prevClosePrc,"$0");  // 0=new, not yet touched
  140.       
  141.             } // if  
  142.          } // if
  143.       } // if
  144.    }  // for  
  145.       
  146.    //-----------------------  Edit Rectangle, change time2 & color, if price touched ----------------------  
  147.    /***************************
  148.    if (showRectangle == true) {
  149.       arrayLastAmount = ArraySize(rectArray);
  150.       for (k=0; k<arrayLastAmount; k++) {  // get every element of Array
  151.          string sep = "$";  
  152.          ushort u_sep;
  153.          string result[];               // new array to get strings
  154.          
  155.          u_sep = StringGetCharacter(sep,0);
  156.          int n = StringSplit(rectArray[k],u_sep,result);
  157.       
  158.          //--- get rectangle price1, compare to ask/bid price
  159.          //--- if rectangle is touched, change time2 & rectangle color
  160.          
  161.          double askPrc = MarketInfo(Symbol(),MODE_ASK);
  162.          double bidPrc = MarketInfo(Symbol(),MODE_BID);
  163.          
  164.          if () {
  165.             for (i=0; i<limit; i++)  {   // redraw if price touched
  166.                //--- first, delete object
  167.                
  168.                
  169.                //--- then recreate object with new properties  
  170.             
  171.             
  172.             } // for
  173.          } // if  
  174.       }  // for
  175.    } // if
  176.    ********************************/
  177.       
  178.    return(0);
  179. } // start


  180. //+------------------------------------------------------------------+
  181. void DelObjects(string id)   {
  182.    int ot1=ObjectsTotal();
  183.    while(ot1>=0)   {
  184.       if (StringFind(ObjectName(ot1),id,0)>-1)    {
  185.          ObjectDelete(ObjectName(ot1));
  186.       }
  187.       ot1--;
  188.    }
  189.    return;
  190. }   
  191.       
  192. //+------------------------------------------------------------------+
  193. string FuncPeriodToStr(int thePeriod) {  
  194.    switch(thePeriod)  {
  195.       case 1: return("M1");
  196.       case 5: return("M5");
  197.       case 15: return("M15");
  198.       case 30: return("M30");
  199.       case 60: return("H1");
  200.       case 240: return("H4");
  201.       case 1440: return("D1");
  202.       case 10080: return("W1");
  203.       case 43200: return("MN1");
  204.       default: return("MN1");
  205.    }
  206. }

  207. //+------------------------------------------------------------------+
复制代码


EmacRectangle.mq4
""
还没有人打赏,支持一下

评论|共 6 个

传奇

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

学习了,不错

92469com

发表于 2020-7-31 15:57:36 | 显示全部楼层

谢谢楼主分享

李禹霏

发表于 2020-11-12 12:09:15 | 显示全部楼层

gf0402

发表于 2021-7-23 11:12:32 | 显示全部楼层

除非各部分

发表于 2021-7-31 20:09:07 | 显示全部楼层

顶下

wyrcjmlp

发表于 2021-8-6 13:25:25 | 显示全部楼层

谢谢

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

EA之家评论守则