有您的持续关注
我们会做得更好

MT4自定义指标 Rads MACD



Rads MACD根据两根均线差显示出来的MACD柱子不同颜色,实际应用中不同周期选用不同参数MA比较好,可以辅助参考。

插入图表效果如下:

MACD指标MQL4源码如下:

//+------------------------------------------------------------------+
//|                                                     变色macd.mq4 |
//|                                                www.125808047.com |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com/"

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Red
#property  indicator_color2  Lime
//---- indicator buffers
double     ind_buffer1[];
double     ind_buffer2[];
double     ind_buffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 1 additional buffer used for counting.
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
   SetIndexDrawBegin(0,36);
   SetIndexDrawBegin(1,36);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,ind_buffer1);
   SetIndexBuffer(1,ind_buffer2);
   SetIndexBuffer(2,ind_buffer3);

//---- Set level Color and Style 
   SetLevelStyle(0, 2, RoyalBlue);
   SetLevelValue(0 , 0);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Rads MACD");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| 9Squared Oscillator                                              |
//+------------------------------------------------------------------+
int start()
  {
   int    limit;
   double prev,current;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars > 0)   counted_bars--;
   limit = Bars - counted_bars;
   if(counted_bars==0) limit-=1+1;
   
//---- macd counted in the 1-st additional buffer
   for(int i=0; i<limit; i++)
ind_buffer3[i]=
iMA(NULL,0,20,0,MODE_EMA,PRICE_WEIGHTED,i)-iMA(NULL,0,75,0,MODE_EMA,PRICE_WEIGHTED,i);
//---- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
      current=ind_buffer3[i];
      prev=ind_buffer3[i+1];
      if(current>prev) up=true;
      if(current<prev) up=false;
      if(!up)
        {
         ind_buffer2[i]=current;
         ind_buffer1[i]=0.0;
        }
      else
        {
         ind_buffer1[i]=current;
         ind_buffer2[i]=0.0;
        }
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

如您喜欢此文章请点下面分享按钮↴峰汇在线 » MT4自定义指标 Rads MACD
上一篇:
下一篇:
分享到:更多 ()