1 //+------------------------------------------------------------------+
\r
3 //| Copyright © 2005, MetaQuotes Software Corp. |
\r
4 //| http://www.metaquotes.net |
\r
5 //+------------------------------------------------------------------+
\r
6 #property copyright "Copyright © 2005, MetaQuotes Software Corp."
\r
7 #property link "http://www.metaquotes.net"
\r
9 #property indicator_separate_window
\r
10 #property indicator_buffers 2
\r
11 #property indicator_color1 Blue
\r
12 #property indicator_color2 Red
\r
13 //---- indicator parameters
\r
14 extern int FastEMA=12;
\r
15 extern int SlowEMA=26;
\r
16 extern int SignalSMA=9;
\r
17 //---- indicator buffers
\r
18 double ind_buffer1[];
\r
19 double ind_buffer2[];
\r
21 //+------------------------------------------------------------------+
\r
22 //| Custom indicator initialization function |
\r
23 //+------------------------------------------------------------------+
\r
26 //---- drawing settings
\r
27 SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
\r
28 SetIndexDrawBegin(1,SignalSMA);
\r
29 IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
\r
30 //---- indicator buffers mapping
\r
31 if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2))
\r
32 Print("cannot set indicator buffers!");
\r
33 //---- name for DataWindow and indicator subwindow label
\r
34 IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
\r
35 SetIndexLabel(0,"MACD");
\r
36 SetIndexLabel(1,"Signal");
\r
37 //---- initialization done
\r
40 //+------------------------------------------------------------------+
\r
41 //| Moving Averages Convergence/Divergence |
\r
42 //+------------------------------------------------------------------+
\r
46 int counted_bars=IndicatorCounted();
\r
47 //---- check for possible errors
\r
48 if(counted_bars<0) return(-1);
\r
49 //---- last counted bar will be recounted
\r
50 if(counted_bars>0) counted_bars--;
\r
51 limit=Bars-counted_bars;
\r
52 //---- macd counted in the 1-st buffer
\r
53 for(int i=0; i<limit; i++)
\r
54 ind_buffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
\r
55 //---- signal line counted in the 2-nd buffer
\r
56 for(i=0; i<limit; i++)
\r
57 ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA,i);
\r