9评论

5收藏

MACD金叉死叉提示

avatar 老王吧 | 3272 人阅读 | 9 人评论 | 2017-12-27

USDJPYM30.png

  1. //+------------------------------------------------------------------+
  2. //|                                           MACD with crossing.mq4 |
  3. //|                       Copyright @2004, MetaQuotes Software Corp. |
  4. //+------------------------------------------------------------------+
  5. #property copyright "下载更多外汇EA,外汇指标,交易系统,就到【外汇EA之家】"
  6. #property link      "http://www.eazhijia.com"
  7. #property strict

  8. #property  indicator_separate_window
  9. #property  indicator_buffers 3
  10. #property  indicator_color1  Gold
  11. #property  indicator_color2  Red
  12. #property  indicator_color3  Gray
  13. #property  indicator_width1  2

  14. input int FastEMA=12;
  15. input int SlowEMA=26;
  16. input int SignalSMA=9;

  17. double     MacdBuffer[];
  18. double     SignalBuffer[];
  19. double     HistogramBuffer[];

  20. int        maxLines;
  21. //+------------------------------------------------------------------+
  22. //| Custom indicator initialization function                         |
  23. //+------------------------------------------------------------------+
  24. int OnInit(void)
  25.   {
  26.    SetIndexStyle(0,DRAW_LINE);
  27.    SetIndexStyle(1,DRAW_LINE);
  28.    SetIndexStyle(2,DRAW_HISTOGRAM);

  29.    SetIndexBuffer(0,MacdBuffer);
  30.    SetIndexBuffer(1,SignalBuffer);
  31.    SetIndexBuffer(2,HistogramBuffer);

  32.    SetIndexLabel(0,"MACD");
  33.    SetIndexLabel(1,"Signal");
  34.    SetIndexLabel(2,"MACD-Signal");

  35.    SetIndexDrawBegin(1,SignalSMA);
  36.    IndicatorDigits(Digits+1);
  37.    IndicatorShortName("MACD("+IntegerToString(FastEMA)+","+IntegerToString(SlowEMA)+","+IntegerToString(SignalSMA)+")");
  38.    return(0);
  39.   }
  40. //+------------------------------------------------------------------+
  41. //|                                                                  |
  42. //+------------------------------------------------------------------+
  43. void OnDeinit(const int reason)
  44.   {
  45.    DeleteLines();
  46.    Comment("www.eazhijia.com");
  47.   }
  48. //+------------------------------------------------------------------+
  49. //| Moving Averages Convergence/Divergence                           |
  50. //+------------------------------------------------------------------+
  51. int OnCalculate (const int rates_total,
  52.                  const int prev_calculated,
  53.                  const datetime& time[],
  54.                  const double& open[],
  55.                  const double& high[],
  56.                  const double& low[],
  57.                  const double& close[],
  58.                  const long& tick_volume[],
  59.                  const long& volume[],
  60.                  const int& spread[])
  61.   {
  62.    double crossing;
  63.    int limit,i;
  64.    int counted_bars=IndicatorCounted();

  65.    if(counted_bars>0) counted_bars--;
  66.    limit=Bars-counted_bars;

  67.    for(i=0; i<limit; i++) MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
  68.      for(i=0; i<limit; i++)
  69.      {
  70.       SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
  71.       HistogramBuffer[i]=MacdBuffer[i] - SignalBuffer[i];
  72.      }

  73.    DeleteLines();
  74.    for(i=WindowBarsPerChart(); i>0 ;i--)
  75.      {
  76.       crossing=(MacdBuffer[i]-SignalBuffer[i])*(MacdBuffer[i+1]-SignalBuffer[i+1]);
  77.       if (crossing < 0)
  78.         {
  79.          maxLines+=1;
  80.          ObjectCreate("MacdCross"+IntegerToString(maxLines),0,0,Time[i],0);
  81.          ObjectSet("MacdCross"+IntegerToString(maxLines),OBJPROP_COLOR,DimGray);
  82.          ObjectSet("MacdCross"+IntegerToString(maxLines),OBJPROP_STYLE,STYLE_DOT);
  83.         }
  84.      }
  85.    return(rates_total);
  86.   }
  87. //+------------------------------------------------------------------+
  88. //|                                                                  |
  89. //+------------------------------------------------------------------+
  90. void DeleteLines()
  91.   {
  92.    for(int i=1;i<=maxLines;i++) ObjectDelete("MacdCross"+IntegerToString(i)); maxLines=0;
  93.   }
  94. //+------------------------------------------------------------------+
复制代码



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

评论|共 9 个

jinle

发表于 2018-1-20 00:24:12 | 显示全部楼层

双线双色MACD指标
MACD多周期共振

ZQM686899

发表于 2018-4-21 14:39:55 | 显示全部楼层

无念法师

发表于 2018-10-17 08:02:53 | 显示全部楼层

非常好的指标

yuanxun

发表于 2020-2-24 11:40:35 | 显示全部楼层

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

金裕良言

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

帮你顶下哈!!

ebsvfefuk

发表于 2020-11-8 18:54:24 | 显示全部楼层

wmjqwe

发表于 2021-7-5 13:56:49 | 显示全部楼层

李建玉儿

发表于 2021-7-12 12:18:58 | 显示全部楼层

谢谢

why

发表于 2021-7-25 15:47:56 | 显示全部楼层

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

EA之家评论守则