标签:
杂谈 |
查看原文:http://www.125808047.com/?p=1885
MT4自带的MACD指标是单线,这款MACD指标是双线而且根据金叉死叉变色,用起来挺方便。
MT4插入MACD-2Line指标到图表效果如下:
http://www.125808047.com/fgp/wp-content/uploads/2016/02/2016021101-300x113.jpgMACD-2Line指标MQL4源码如下:
//+------------------------------------------------------------------+ //| MACD-2Line.mq4 | //| Copyright 2016, QQ:125808047 | //+------------------------------------------------------------------+ #property copyright "峰汇在线 QQ:125808047" #property link "http://www.125808047.com/" #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 Magenta #property indicator_color2 Lime #property indicator_color3 Red #property indicator_color4 Aqua #property indicator_level1 0 //---- 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,EMPTY, 2); SetIndexBuffer(2,ExtMapBuffer3); SetIndexStyle(3,DRAW_HISTOGRAM ,EMPTY, 2); SetIndexBuffer(3,ExtMapBuffer4); //---- //---- name for DataWindow and indicator subwindow label IndicatorShortName("MACD-2Line("+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; Comment("Bars=",Bars,"\nSL2=",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); } //+------------------------------------------------------------------+
前一篇:MACD优化指标BB_MACD