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

双线MACD———-MT4自定义指标



在MT4自带指标中MACD是单线,经常有新人要双线MACD指标,今天抽时间整理了下面这款双线MACD,放到自定义指标文件夹,有关MACD的详细用法,请在本站搜索或百度MACD指标用法

txmacdMAL4源码如下:

//+------------------------------------------------------------------+
//|                                                       TXMACD.mq4 |
//|                                    Copyright @2015, QQ:125808047 |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com/"
//---- indicator settings

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Gold
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 Yellow
#property indicator_color5 Red
#property indicator_color6 Lime
#property indicator_level1 0
//---- indicator parameters
//extern string Setup =  "Classic 12 26 9";
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalEMA=9;
extern int OsmaX=2;

double  Zero_level=0.0;
double minuse;
double Vol;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
double ind_buffer5[];
double ind_buffer6[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
   SetIndexDrawBegin(1,"OsMA");
//---- indicator buffers mapping
   SetIndexBuffer(0,ind_buffer1);
   SetIndexBuffer(1,ind_buffer2);
   SetIndexBuffer(2,ind_buffer3);
   SetIndexBuffer(3,ind_buffer4);
   SetIndexBuffer(4,ind_buffer5);
   SetIndexBuffer(5,ind_buffer6);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("www.125808047.com");
   SetIndexLabel(0,"OsMAW");
   SetIndexLabel(1,"OsMAS");
   SetIndexLabel(2,"OsMAB");
   SetIndexLabel(3,"OsMA");
   SetIndexLabel(4,"Signal");
   SetIndexLabel(5,"MACD");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit--;

   for(int i=0; i<limit; i++)
      ind_buffer6[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   for(i=0; i<limit; i++)
      ind_buffer5[i]=iMAOnArray(ind_buffer6,Bars,SignalEMA,0,MODE_EMA,i);
   for(i=0; i<limit; i++)
      ind_buffer4[i]=((iOsMA(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,i))*OsmaX);
   for(i=0; i<limit; i++)
      ind_buffer3[i]=ind_buffer4[i];
   for(i=0; i<limit; i++)
      ind_buffer2[i]=ind_buffer4[i];
   for(i=0; i<limit; i++)
      ind_buffer1[i]=ind_buffer4[i];
//---- done

//---- Three Colour MACD mapping 
   for(i=0; i<limit; i++)
     {   //for open

      if(ind_buffer6[i]>ind_buffer6[i+1])
        {
         ind_buffer2[i]=Zero_level;

         Vol=ind_buffer1[i];     minuse=Vol-ind_buffer1[i+1];

         if(minuse>0.0){ind_buffer3[i]=Vol; ind_buffer2[i]=0.0; ind_buffer1[i]=0.0;}
         else 
           {
            if(minuse<0.0){ind_buffer3[i]=0.0; ind_buffer2[i]=0.0; ind_buffer1[i]=Vol;}
            else{ind_buffer3[i]=0.0; ind_buffer2[i]=0.0; ind_buffer1[i]=Vol;}
           }
        } //if Close
      else 
        {
         ind_buffer2[i]=Zero_level;

         Vol=ind_buffer1[i];     minuse=Vol-ind_buffer1[i+1];

         if(minuse>0.0){ind_buffer3[i]=0.0; ind_buffer2[i]=0.0; ind_buffer1[i]=Vol;}
         else 
           {
            if(minuse<0.0){ind_buffer3[i]=0.0; ind_buffer2[i]=Vol; ind_buffer1[i]=0.0;}
            else{ind_buffer4[i]=0.0; ind_buffer2[i]=0.0; ind_buffer1[i]=Vol;}
           }

        }
     }//for Close
   return(0);
  } 
//+------------------------------------------------------------------+

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

评论 抢沙发

评论前必须登录!