1评论

4收藏

MACD.mq4

avatar 老王吧 | 3603 人阅读 | 1 人评论 | 2016-04-21

QQ截图20160421130830.png

  1. /////////////////////////////////////////////////////////////////////////////////////////////
  2. //| mymacd v2 12/11/05
  3. /////////////////////////////////////////////////////////////////////////////////////////////
  4. #property link "jpygbp@yahoo.com"
  5. #property indicator_buffers 5
  6. #property indicator_separate_window
  7. #property indicator_color1 HotPink    //macd
  8. #property indicator_color2 Lime     //signal
  9. #property indicator_color3 Gray  //histogram
  10. #property indicator_color4 Blue  //macd[1]
  11. #property indicator_color5 Black     //zero line
  12. //---- buffers
  13. double Buffer1[]; //macd
  14. double Buffer2[]; //signal
  15. double Buffer3[]; //histogram
  16. double Buffer4[]; //macd[1]
  17. double Buffer5[]; //zero line
  18. //
  19. extern int FastEMA = 9;
  20. extern int SlowEMA = 64;
  21. extern int SignalSMA = 112;
  22. //extern bool plotMACD = true;
  23. //extern bool plotSignalLine = true;
  24. //extern bool plotHistogram = true;
  25. //extern bool plotMACDOneBarAgo = true;
  26. //extern bool plotZeroLine = true;
  27. extern bool plotArrows = false;
  28. extern double HistThreshold = 0;
  29. //
  30. //
  31. int limit = 0;
  32. int fontsize=10;
  33. int i = 0;
  34. bool InLTrade = false;
  35. bool InSTrade = false;
  36. /////////////////////////////////////////////////////////////////////////////////////////////
  37. int init()
  38. {
  39.    ObjectsDeleteAll();
  40.    //---- indicators
  41.    SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);//macd
  42.    SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);//signal
  43.    SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);//hist
  44.    SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2);//macd[1]
  45.    SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);//zero
  46.    //
  47.    SetIndexBuffer(0,Buffer1);
  48.    SetIndexBuffer(1,Buffer2);
  49.    SetIndexBuffer(2,Buffer3);
  50.    SetIndexBuffer(3,Buffer4);
  51.    SetIndexBuffer(4,Buffer5);
  52.    //
  53.    SetIndexDrawBegin(1,SignalSMA);
  54.    //
  55.    IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
  56.    //
  57.    IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
  58.    //
  59.    SetIndexLabel(0,"MACD");
  60.    SetIndexLabel(1,"Signal");
  61.    SetIndexLabel(2,"Histogram");
  62.    SetIndexLabel(3,"MACD[1]");
  63.    SetIndexLabel(4,"Zero");
  64.    //
  65.    return(0);
  66. }
  67. /////////////////////////////////////////////////////////////////////////////////////////////
  68. string NewArrow(datetime T1, double P1, color collor)
  69. {
  70.    string N=StringConcatenate("A",collor,"-",TimeToStr(T1));
  71.    int AC=SYMBOL_STOPSIGN;
  72.    if(collor==Blue)
  73.       AC=SYMBOL_ARROWUP;
  74.    if(collor==Red)
  75.       AC=SYMBOL_ARROWDOWN;
  76.    //
  77.    ObjectCreate(N, OBJ_ARROW, 0, T1, P1);
  78.    ObjectSet(N, OBJPROP_ARROWCODE, AC);
  79.    ObjectSet(N, OBJPROP_COLOR, collor);
  80.    ObjectSet(N, OBJPROP_WIDTH, 1);
  81.    ObjectsRedraw();
  82.    return(N);
  83. }
  84. /////////////////////////////////////////////////////////////////////////////////////////////
  85. int deinit()
  86. {
  87.    ObjectsRedraw();
  88.    return(0);
  89. }
  90. /////////////////////////////////////////////////////////////////////////////////////////////
  91. int start()
  92. {
  93.    int counted_bars=IndicatorCounted();
  94.    if(counted_bars<0) return(-1);//---- check for possible errors
  95.    if(counted_bars>0) counted_bars--;//---- last counted bar will be recounted
  96.    limit=Bars-counted_bars;
  97.    //
  98.    for(i=0; i<limit; i++)//---- macd counted in the 1-st buffer histogram
  99.       Buffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
  100.    //
  101.    for(i=0; i<limit; i++)//---- signal line counted in the 2-nd buffer line
  102.       Buffer2[i]=iMAOnArray(Buffer1,Bars,SignalSMA,0,MODE_SMA,i);
  103.    //
  104.    for(i=0; i<limit; i++)//---- histogram is the difference between macd and signal line
  105.    {
  106.       Buffer3[i]=Buffer1[i]-Buffer2[i];
  107.       Buffer5[i]=0;
  108.    }
  109.    //
  110.    for(i=1; i<limit; i++)//---- macd[1]
  111.       Buffer4[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i-1)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i-1);
  112.    //
  113.    if (plotArrows)
  114.    {
  115.       ObjectsDeleteAll();
  116.       InLTrade = false;
  117.       InSTrade = false;
  118.       for(int i=Bars;i>=0;i--)
  119.       {
  120.          if ((Buffer3[i-1]  > 0) && (Buffer3[i] < 0) && Buffer3[i-1] > HistThreshold)//Long Begin
  121.          {
  122.            string upArrow1=NewArrow(Time[i-1], High[i-1]+0.0005, Blue);
  123.             InLTrade = true;
  124.          }
  125.          if ((Buffer3[i-1]  < 0) && (Buffer3[i] > 0) && Buffer3[i-1] < -HistThreshold)//Short Begin
  126.          {
  127.             string dnArrow1=NewArrow(Time[i-1], Low[i-1]-0.0003, Red);
  128.             InSTrade = true;
  129.             InLTrade = false;  
  130.          }
  131.          if ((InSTrade  == true) && (Buffer3[i-1] > Buffer3[i]))//Short End
  132.          {
  133.             string upArrow2=NewArrow(Time[i-1], Low[i-1]-0.0003, Aqua);
  134.             InSTrade = false;
  135.          }
  136.          if ((InLTrade == true) && (Buffer3[i-1] < Buffer3[i]))//Long End
  137.          {
  138.             string dnArrow2=NewArrow(Time[i-1], High[i-1]+0.0005, Aqua);
  139.             InLTrade = false;   
  140.          }
  141.       }
  142.    }
  143.    //
  144.    //
  145.    return(0);
  146. }
  147. /////////////////////////////////////////////////////////////////////////////////////////////
复制代码


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

评论|共 1 个

我爱sqq

发表于 2020-6-13 17:29:35 | 显示全部楼层

写的真的很不错

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

EA之家评论守则