bleh
[mqlkit.git] / indicators / mc.mq4
blobbaae83427862ae87f275779c6f998f8a0c9c5650
1 //+------------------------------------------------------------------+\r
2 //|                                                           mc.mq4 |\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
8 \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
24 int init()\r
25   {\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
38    return(0);\r
39   }\r
40 //+------------------------------------------------------------------+\r
41 //| Moving Averages Convergence/Divergence                           |\r
42 //+------------------------------------------------------------------+\r
43 int start()\r
44   {\r
45    int limit;\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
58 //---- done\r
59    return(0);\r
60   }