13评论

0收藏

MACD_LSMA_EMA

avatar 老王吧 | 3303 人阅读 | 13 人评论 | 2017-12-27

EURGBPM30.png

  1. //+------------------------------------------------------------------+
  2. //|                                                MACD_LSMA_EMA.mq4 |
  3. //|                                     Copyright @2007, Robert Hill |
  4. //+------------------------------------------------------------------+
  5. #property copyright "下载更多外汇EA,外汇指标,交易系统,就到【外汇EA之家】"
  6. #property link      "http://www.eazhijia.com"

  7. #property  indicator_separate_window
  8. #property  indicator_buffers 4
  9. #property  indicator_color1  Aqua
  10. #property  indicator_color2  Red
  11. #property  indicator_color3  Green
  12. #property  indicator_color4  Red

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

  16. double     MACD_buffer[];
  17. double     Signal_buffer[];
  18. double HistogramBufferUp[];
  19. double HistogramBufferDown[];
  20. bool   ExtParameters=false;
  21. //+------------------------------------------------------------------+
  22. //| Custom indicator initialization function                         |
  23. //+------------------------------------------------------------------+
  24. int OnInit(void)
  25.   {
  26.    IndicatorDigits(Digits+1);
  27.    SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
  28.    SetIndexBuffer(0,MACD_buffer);
  29.    SetIndexDrawBegin(0,SlowEMA);
  30.    SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
  31.    SetIndexBuffer(1,Signal_buffer);
  32.    SetIndexDrawBegin(1,SignalSMA);
  33.    SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
  34.    SetIndexBuffer(2,HistogramBufferUp);
  35.    SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
  36.    SetIndexBuffer(3,HistogramBufferDown);
  37.    IndicatorDigits(Digits+1);

  38.    IndicatorShortName("MACD_LSMA_EMA("+IntegerToString(FastEMA)+","+IntegerToString(SlowEMA)+","+IntegerToString(SignalSMA)+")");
  39.    SetIndexLabel(0,"MACD");
  40.    SetIndexLabel(1,"Signal");
  41.    SetIndexLabel(2,"Histogram");
  42.    if(FastEMA<=1 || SlowEMA<=1 || SignalSMA<=1 || FastEMA>=SlowEMA)
  43.      {
  44.       Print("Wrong input parameters");
  45.       ExtParameters=false;
  46.       return(INIT_FAILED);
  47.      }
  48.    else
  49.       ExtParameters=true;
  50.    Comment("www.eazhijia.com");
  51.     return(INIT_SUCCEEDED);
  52.   }
  53. //+------------------------------------------------------------------------+
  54. //| LSMA - Least Squares Moving Average function calculation               |
  55. //| LSMA_In_Color Indicator plots the end of the linear regression line    |
  56. //+------------------------------------------------------------------------+
  57. double LSMA(int Rperiod, int shift)
  58. {
  59.    int i;
  60.    double sum;
  61.    int length;
  62.    double lengthvar;
  63.    double tmp;
  64.    double wt;

  65.    length = Rperiod;
  66.    sum = 0;
  67.    for(i = length; i >= 1  ; i--)
  68.    {
  69.      lengthvar = length + 1;
  70.      lengthvar /= 3;
  71.      tmp = 0;
  72.      tmp = ( i - lengthvar)*Close[length-i+shift];
  73.      sum+=tmp;
  74.     }
  75.     wt = MathFloor(sum*6/(length*(length+1))/Point)*Point;
  76.     return(wt);
  77. }
  78. //+------------------------------------------------------------------+
  79. //| Moving Averages Convergence/Divergence                           |
  80. //+------------------------------------------------------------------+
  81. int OnCalculate(const int rates_total,
  82.                 const int prev_calculated,
  83.                 const datetime &time[],
  84.                 const double &open[],
  85.                 const double &high[],
  86.                 const double &low[],
  87.                 const double &close[],
  88.                 const long &tick_volume[],
  89.                 const long &volume[],
  90.                 const int &spread[])
  91.   {
  92.    double temp;
  93.    int i,limit;
  94. //---
  95.    if(rates_total<=SignalSMA || !ExtParameters)
  96.       return(0);
  97. //--- last counted bar will be recounted
  98.    limit=rates_total-prev_calculated;
  99.    if(prev_calculated>0)
  100.       limit++;

  101.    for(i=0; i<limit; i++)
  102.       MACD_buffer[i]=LSMA(FastEMA,i)-LSMA(SlowEMA,i);

  103.    for(i=0; i<limit; i++)
  104.       Signal_buffer[i]=iMAOnArray(MACD_buffer,Bars,SignalSMA,0,MODE_EMA,i);

  105.    for(i=0; i<limit; i++)
  106.    {
  107.       HistogramBufferUp[i] = 0;
  108.       HistogramBufferDown[i] = 0;
  109.       temp = MACD_buffer[i] - Signal_buffer[i];
  110.       if (temp >= 0)
  111.         HistogramBufferUp[i] = temp;
  112.       else
  113.         HistogramBufferDown[i] = temp;
  114.    }
  115.     return(rates_total);
  116.   }
复制代码


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

评论|共 13 个

hnut060

发表于 2018-5-25 00:39:39 | 显示全部楼层

好东西!!!!!!!!!!

xing5202

发表于 2018-9-18 11:00:36 | 显示全部楼层

貌似有点意思

hov33snu

发表于 2020-6-5 22:21:35 | 显示全部楼层

相当不错,感谢无私分享精神!

亮台凯

发表于 2020-7-16 12:55:45 | 显示全部楼层

学习了,不错

王┢┦apΡy

发表于 2020-7-20 22:55:24 | 显示全部楼层

帮你顶下哈!!

medley

发表于 2020-7-24 12:25:25 | 显示全部楼层

帮你顶下哈!!

你的太在乎

发表于 2020-8-16 11:02:16 | 显示全部楼层

谢谢楼主分享

QQ1397379127

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

学习了,不错

cvllt74614

发表于 2020-9-1 11:49:10 | 显示全部楼层

学习了,不错

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

EA之家评论守则