1 //+------------------------------------------------------------------+
\r
2 //| Accelerator.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 //---- indicator settings
\r
9 #property indicator_separate_window
\r
10 #property indicator_buffers 3
\r
11 #property indicator_color1 Black
\r
12 #property indicator_color2 Green
\r
13 #property indicator_color3 Red
\r
14 //---- indicator buffers
\r
15 double ExtBuffer0[];
\r
16 double ExtBuffer1[];
\r
17 double ExtBuffer2[];
\r
18 double ExtBuffer3[];
\r
19 double ExtBuffer4[];
\r
20 //+------------------------------------------------------------------+
\r
21 //| Custom indicator initialization function |
\r
22 //+------------------------------------------------------------------+
\r
25 //---- 2 additional buffers are used for counting.
\r
26 IndicatorBuffers(5);
\r
27 //---- drawing settings
\r
28 SetIndexStyle(0,DRAW_NONE);
\r
29 SetIndexStyle(1,DRAW_HISTOGRAM);
\r
30 SetIndexStyle(2,DRAW_HISTOGRAM);
\r
31 IndicatorDigits(Digits+2);
\r
32 SetIndexDrawBegin(0,38);
\r
33 SetIndexDrawBegin(1,38);
\r
34 SetIndexDrawBegin(2,38);
\r
35 //---- 4 indicator buffers mapping
\r
36 SetIndexBuffer(0,ExtBuffer0);
\r
37 SetIndexBuffer(1,ExtBuffer1);
\r
38 SetIndexBuffer(2,ExtBuffer2);
\r
39 SetIndexBuffer(3,ExtBuffer3);
\r
40 SetIndexBuffer(4,ExtBuffer4);
\r
41 //---- name for DataWindow and indicator subwindow label
\r
42 IndicatorShortName("AC");
\r
43 SetIndexLabel(1,NULL);
\r
44 SetIndexLabel(2,NULL);
\r
45 //---- initialization done
\r
48 //+------------------------------------------------------------------+
\r
49 //| Accelerator/Decelerator Oscillator |
\r
50 //+------------------------------------------------------------------+
\r
54 int counted_bars=IndicatorCounted();
\r
55 double prev,current;
\r
56 //---- last counted bar will be recounted
\r
57 if(counted_bars>0) counted_bars--;
\r
58 limit=Bars-counted_bars;
\r
59 //---- macd counted in the 1-st additional buffer
\r
60 for(int i=0; i<limit; i++)
\r
61 ExtBuffer3[i]=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN,i);
\r
62 //---- signal line counted in the 2-nd additional buffer
\r
63 for(i=0; i<limit; i++)
\r
64 ExtBuffer4[i]=iMAOnArray(ExtBuffer3,Bars,5,0,MODE_SMA,i);
\r
65 //---- dispatch values between 2 buffers
\r
67 for(i=limit-1; i>=0; i--)
\r
69 current=ExtBuffer3[i]-ExtBuffer4[i];
\r
70 prev=ExtBuffer3[i+1]-ExtBuffer4[i+1];
\r
71 if(current>prev) up=true;
\r
72 if(current<prev) up=false;
\r
75 ExtBuffer2[i]=current;
\r
80 ExtBuffer1[i]=current;
\r
83 ExtBuffer0[i]=current;
\r
88 //+------------------------------------------------------------------+
\r