双线双色MACD指标

楼主  收藏   举报   帖子创建时间:  2019-05-05 04:59 回复:0 关注量:928
EURGBPM30.png

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

  7. #property  indicator_separate_window
  8. #property  indicator_buffers 6
  9. #property  indicator_color1  Red
  10. #property  indicator_color2  LimeGreen
  11. #property  indicator_color3  Red
  12. #property  indicator_color4  LimeGreen
  13. #property  indicator_color5  Blue
  14. #property  indicator_color6  Yellow
  15. #property  indicator_level1  0

  16. extern int FastEMA=12;
  17. extern int SlowEMA=26;
  18. extern int SignalSMA=9;

  19. double     ind_buffer1[];
  20. double     ind_buffer2[];
  21. double     ind_buffer1b[];
  22. double     ind_buffer2b[];
  23. double     ind_buffer3[];
  24. double     ind_buffer4[];
  25. double     b[999999];
  26. int init() {
  27.    SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2,indicator_color1);
  28.    SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2,indicator_color2);
  29.    SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2,indicator_color3);
  30.    SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,2,indicator_color4);
  31.    SetIndexStyle(4,DRAW_LINE,EMPTY,1,indicator_color5);
  32.    SetIndexStyle(5,DRAW_LINE,EMPTY,1,indicator_color6);
  33.    SetIndexBuffer(0,ind_buffer1);
  34.    SetIndexBuffer(1,ind_buffer2);
  35.    SetIndexBuffer(2,ind_buffer1b);
  36.    SetIndexBuffer(3,ind_buffer2b);
  37.    SetIndexBuffer(4,ind_buffer3);
  38.    SetIndexBuffer(5,ind_buffer4);
  39.    IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
  40.    Comment("www.eazhijia.com");
  41.    return(0);
  42. }

  43. int start(){
  44.    int limit;
  45.    int counted_bars=IndicatorCounted();
  46.    if(counted_bars<0) return(-1);
  47.    if(counted_bars>0) counted_bars--;
  48.    limit=Bars-counted_bars;
  49.    for(int i=limit; i>=0; i--) {
  50.       b[i] = iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
  51.       ind_buffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
  52.       
  53.       clearBuffers(i);
  54.       
  55.       if (b[i] < 0 ) {
  56.          if (b[i] > b[i+1]) {
  57.             ind_buffer1[i] = b[i];
  58.             ind_buffer1b[i] = 0;
  59.          } else if (b[i] < b[i+1]) {
  60.             ind_buffer1b[i] = b[i];
  61.             ind_buffer1[i] = 0;
  62.          }
  63.       } else if (b[i] > 0) {
  64.           if (b[i] < b[i+1]) {
  65.             ind_buffer2[i] = b[i];
  66.             ind_buffer2b[i] = 0;
  67.          } else if (b[i] > b[i+1]) {
  68.             ind_buffer2b[i] = b[i];
  69.             ind_buffer2[i] = 0;
  70.          }
  71.       }
  72.       ind_buffer3[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
  73.    }
  74.    for(i=0; i<limit; i++) {
  75.          ind_buffer4[i]=iMAonArray(ind_buffer3,Bars,SignalSMA,0,MODE_SMA,i);
  76.       }
  77.    return(0);
  78. }

  79. void clearBuffers (int i) {
  80.       ind_buffer1[i] = NULL;
  81.       ind_buffer1b[i] = NULL;
  82.       ind_buffer2[i] = NULL;
  83.       ind_buffer2b[i] = NULL;
  84. }
打赏