最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

双线MACD指标算法原理

来源:动视网 责编:小OO 时间:2025-09-29 21:42:02
文档

双线MACD指标算法原理

双线MACD指标算法原理#property indicator_separate_window#property indicator_buffers4#property indicator_color1 White#property indicator_color2 Yellow#property indicator_color3 Red#property indicator_color4 Lime***以上是双线MACD的一些初始化的设置,包括窗体,数据缓冲区区和呈现图像的线的颜色,colo
推荐度:
导读双线MACD指标算法原理#property indicator_separate_window#property indicator_buffers4#property indicator_color1 White#property indicator_color2 Yellow#property indicator_color3 Red#property indicator_color4 Lime***以上是双线MACD的一些初始化的设置,包括窗体,数据缓冲区区和呈现图像的线的颜色,colo
双线MACD指标算法原理

#property  indicator_separate_window

#property  indicator_buffers 4

#property  indicator_color1  White

#property  indicator_color2  Yellow

#property  indicator_color3  Red

#property  indicator_color4  Lime

***以上是双线MACD的一些初始化的设置,包括窗体,数据缓冲区区和呈现图像的线的颜色,color1以White色来表示DIF,color2以Yellow色来表示DEA,color3为红色的柱子,color4为绿色的柱子

 

//---- indicator parameters

extern int FastEMA=9;

extern int SlowEMA=20;

extern int SignalSMA=9;

***定义MACD的算法参数,FastEMA为通过K线收盘价做EMA加权平均线计算的参数,默认为12,也称为快线; SlowEMA为通过K线收盘价做EMA加权平均线计算的参数,默认为26,也称为慢线;SignalSMA为通过FastEMA-SlowEMA的差值做算术平均得到DIF值得参数,默认为9,即9日算术平均。

 

//---- indicator buffers

double     ind_buffer1[];

double     ind_buffer2[];

double     ind_buffer3[];

double     ind_buffer4[];

double     temp;

***定义数据缓冲区数组和变量

 

int init()

  {

//---- drawing settings

   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);

   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);

   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);

   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,1);

   SetIndexDrawBegin(1,SignalSMA);

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);

***定义绘图对象线、柱和绘图模板信息

 

//---- indicator buffers mapping

   if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2)&& !SetIndexBuffer(2,ind_buffer3)&& !SetIndexBuffer(3,ind_buffer4))

      Print("cannot set indicator buffers!");

***缓冲区数组到绘图对象的一一对应并作错误提示处理

 

//---- name for DataWindow and indicator subwindow label

   IndicatorShortName("MACD("+FastEMA+

   SetIndexLabel(0,"MACD");

   SetIndexLabel(1,"Signal");

//---- initialization done

   return(0);

  }

***定义绘图窗口的标签信息

 

int start()

  {

   int limit;

   int counted_bars=IndicatorCounted();

//---- 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;

//---- macd counted in the 1-st buffer

   for(int i=0; i      ind_buffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);

***以limit引用MT4系统设定的最大极限K线根数的参数,ind_buffer1[i]为记录每一根K线的DIF值的数组,DIF值得计算方式为每一个K线所对应的快线取值减去慢线取值(比如DIF=FastEMA12-SlowEMA26),然后将ind_buffer1[i]数组中的所有DIF值串联起来,便绘制出来了DIF曲线。

 

//---- signal line counted in the 2-nd buffer

   for(i=0; i      ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA,i);

***ind_buffer2[i]为记录了通过ind_buffer1数组进行SignalSMA的所有取值,即为DEA。通俗说,将DIF进行SMA9简单算术平均后得到的数值就是DEA的取值,将每一根K线对应的DEA的取值顺序排列,并绘串联起来,就得到了DEA曲线。

 

   for(i=0; i      {

       temp=1.3*(ind_buffer1[i]-ind_buffer2[i]);

***ind_buffer1代表的DIF,ind_buffer2代表的DEA,temp为DIF-DEA的取值乘以系数1.3进行差离放大的取值,这个系数通常大于1,也有的使用2作为系数。

 

       if(temp>0) {ind_buffer3[i]=temp;ind_buffer4[i]=0;}

       else       {ind_buffer3[i]=0;ind_buffer4[i]=temp;}

***ind_buffer3为出红柱的情况,ind_buffer4为出绿柱的情况,意思就是如果temp的取值大于0,那么将差值存入ind_buffer3,对应的就是所在K线的红柱;如果temp的取值小于0,那么将差值存入ind_buffer4,对应的就是所在K线的绿柱。

      }

//---- done

   return(0);

  }

 

以上是双线MACD指标算法原理的解释,适用于MT4平台可以直接使用。算法的非重要信息有删减,如果需要可以导入的完整算法,参见另一篇双线MACD指标的完整算法。

更多MACD指标用法和MACD交易系统请参见http://www.macd9.com

文档

双线MACD指标算法原理

双线MACD指标算法原理#property indicator_separate_window#property indicator_buffers4#property indicator_color1 White#property indicator_color2 Yellow#property indicator_color3 Red#property indicator_color4 Lime***以上是双线MACD的一些初始化的设置,包括窗体,数据缓冲区区和呈现图像的线的颜色,colo
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top