//+------------------------------------------------------------------+ //| MACD.mq4 | //| Copyright © 2006, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 LimeGreen #property indicator_color2 Crimson #property indicator_color3 Aqua #property indicator_color4 Yellow #property indicator_width1 4 #property indicator_width2 4 #property indicator_width3 2 #property indicator_width4 1 #property indicator_style4 STYLE_DASH #property indicator_level1 0 #property indicator_levelcolor White #property indicator_levelstyle STYLE_DOT //---- indicator parameters extern int FastMA = 12; extern int SlowMA = 26; extern int SignalMA = 9; extern int MAMode = MODE_SMA //---- indicator buffers double ind_Buffer1[]; double ind_Buffer2[]; double ind_buffer3a[]; double ind_buffer3b[]; double ind_buffer4[]; double ind_buffer5[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 2 additional buffers are used for counting. IndicatorBuffers(6); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2); SetIndexDrawBegin(0,SignalSMA); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexDrawBegin(1,SignalMA); SetIndexStyle(4,DRAW_LINE); SetIndexBuffer(4,ind_Buffer1); SetIndexStyle(5,DRAW_LINE); SetIndexBuffer(5,ind_Buffer2); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2); //---- 5 indicator buffers mapping if(!SetIndexBuffer(0,ind_buffer3a) && !SetIndexBuffer(1,ind_buffer3b) && !SetIndexBuffer(2,ind_buffer4) && !SetIndexBuffer(3,ind_buffer5) && !SetIndexBuffer(4,ind_Buffer1) && !SetIndexBuffer(5,ind_Buffer2)) Print("cannot set indicator buffers!"); //---- name for DataWindow and indicator subwindow label IndicatorShortName("MACD"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Moving Average of Oscillator | //+------------------------------------------------------------------+ int start() { string PERIOD; PERIOD = Period(); ObjectCreate("MACD", OBJ_LABEL, WindowFind("MACD"), 0, 0); ObjectSetText("MACD","MACD", 12, "Arial Bold", Black); ObjectSet("MACD", OBJPROP_CORNER, 0); ObjectSet("MACD", OBJPROP_XDISTANCE, 250); ObjectSet("MACD", OBJPROP_YDISTANCE, 0); ObjectCreate("MACD1", OBJ_LABEL, WindowFind("MACD"), 0, 0); ObjectSetText("MACD1",StringSubstr(PERIOD,0),12, "Arial Bold", Red); ObjectSet("MACD1", OBJPROP_CORNER, 0); ObjectSet("MACD1", OBJPROP_XDISTANCE, 300); ObjectSet("MACD1", OBJPROP_YDISTANCE, 0); 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 additional buffer for(int i=0; i0) ind_buffer3a[i]=value; if (value<0) ind_buffer3b[i]=value; } //---- done return(0); } //+------------------------------------------------------------------+