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

📄 www.forexstar.com.cn_macd.mq4

📁 用于MT4的自动交易系统(即expert)中的MACD指标,原系统自带MACD是单线的
💻 MQ4
字号:
//+------------------------------------------------------------------+
//|                                         www.forexstar.com.cn.mq4 |
//|                            Copyright ?2006, www.forexstar.com.cn |
//|                                      http://www.forexstar.com.cn |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2006, www.forexstar.com.cn"
#property link      "http://www.forexstar.com.cn"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Black
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 Blue
//---- input parameters
extern int       FastEMA=12;
extern int       SlowEMA=26;
extern int       SignalSMA=9;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexBuffer(3,ExtMapBuffer4);
//----

//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   SetIndexLabel(0,"DIFF");
   SetIndexLabel(1,"DEA");
   SetIndexLabel(2,"MACD");
//---- initialization done

   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//---- 
   int limit;
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- DIF counted in the 1-st buffer
   for(int i=0; i<limit; i++)
      ExtMapBuffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- MACD line counted in the 2-nd buffer
   for(i=0; i<limit; i++)
      ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer1,Bars,SignalSMA,0,MODE_EMA,i);
//---- BAR line counted in the 3,4 buffer
   for(i=0; i<limit; i++)
   {
      if(ExtMapBuffer1[i] > ExtMapBuffer2[i]) 
      {
          ExtMapBuffer3[i] = 2*(ExtMapBuffer1[i]-ExtMapBuffer2[i]); 
          ExtMapBuffer4[i] = 0;
      }
      else
      {
          ExtMapBuffer4[i] = 2*(ExtMapBuffer1[i]-ExtMapBuffer2[i]); 
          ExtMapBuffer3[i] = 0;
      }
   }      

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

⌨️ 快捷键说明

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