⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macd.mq4

📁 MACD指标
💻 MQ4
字号:

#property  indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1  Orange
#property  indicator_color2  White
#property  indicator_color3  Green
#property  indicator_color4  DeepPink
#property  indicator_color5  Lime
#property  indicator_color6  Crimson

#property  indicator_level1  0

#property indicator_width3  2
#property indicator_width4  2
#property indicator_width5  2
#property indicator_width6  2

extern int SlowEMA=34;
extern int FastEMA=13;
extern int SignalSMA=5;


double     DifBuffer[];
double     DeaBuffer[];
double     MacdBuffer1[];
double     MacdBuffer2[];
double     MacdBuffer3[];
double     MacdBuffer4[];


int init()
  {
   IndicatorBuffers(6);
  
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,DifBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,DeaBuffer);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,MacdBuffer1);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexBuffer(3,MacdBuffer2);
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexBuffer(4,MacdBuffer3);
   SetIndexStyle(5,DRAW_HISTOGRAM);
   SetIndexBuffer(5,MacdBuffer4);
        
   
   SetIndexDrawBegin(0,SignalSMA);
   SetIndexDrawBegin(1,SignalSMA);
   SetIndexDrawBegin(2,SignalSMA);
   SetIndexDrawBegin(3,SignalSMA);
   SetIndexDrawBegin(4,SignalSMA);
   SetIndexDrawBegin(5,SignalSMA);
      
   
   IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   SetIndexLabel(0,"Dif");
   SetIndexLabel(1,"Dea");
   SetIndexLabel(2,"Macd");
   SetIndexLabel(3,"Macd"); 
   SetIndexLabel(4,"Macd");
   SetIndexLabel(5,"Macd");      

            
   return(0);
  }




int start()
  {
   int i,limit,counted_bars=IndicatorCounted();


   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
   for(i=0; i<limit; i++)
      DifBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
   for(i=0; i<limit; i++)   
      DeaBuffer[i]=iMAOnArray(DifBuffer,Bars,SignalSMA,0,MODE_SMA,i);
    
   for(i=0; i<limit; i++)
      MacdBuffer1[i]=2*(DifBuffer[i]-DeaBuffer[i]);
   for(i=0; i<limit; i++)
      { 
      MacdBuffer2[i]=EMPTY_VALUE;
      MacdBuffer3[i]=EMPTY_VALUE;
      MacdBuffer4[i]=EMPTY_VALUE;   
            
      if(MacdBuffer1[i]>0 && MacdBuffer1[i]>=MacdBuffer1[i+1])  MacdBuffer2[i]=MacdBuffer1[i];
      if(MacdBuffer1[i]>0 && MacdBuffer1[i]< MacdBuffer1[i+1])  MacdBuffer4[i]=MacdBuffer1[i];
      if(MacdBuffer1[i]<0 && MacdBuffer1[i]>=MacdBuffer1[i+1])  MacdBuffer3[i]=MacdBuffer1[i];
      }
      
   return(0);
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -