bleh
[mqlkit.git] / templates / Accelerator.mqt
bloba7cc62cfc7f0199e2a67e4c4d6cdd7fbe4c775a4
1 <expert>\r
2 type=INDICATOR_ADVISOR\r
3 description=Accelerator Oscilator\r
4 separate_window=1\r
5 used_buffers=4\r
6 <ind>\r
7 color=Green\r
8 type=DRAW_HISTOGRAM\r
9 </ind>\r
10 <ind>\r
11 color=Red\r
12 type=DRAW_HISTOGRAM\r
13 </ind>\r
14 </expert>\r
15 #header#\r
16 #property copyright "#copyright#"\r
17 #property link      "#link#"\r
19 #indicator_properties#\r
20 #extern_variables#\r
21 #mapping_buffers#\r
22 //---- indicator buffers\r
23 double ExtGreenBuffer[];\r
24 double ExtRedBuffer[];\r
25 double ExtMABuffer[];\r
26 double ExtBuffer[];\r
27 //+------------------------------------------------------------------+\r
28 //| Custom indicator initialization function                         |\r
29 //+------------------------------------------------------------------+\r
30 int init()\r
31   {\r
32    #buffers_used#;\r
33 //---- indicator buffers mapping\r
34    SetIndexBuffer(0, ExtGreenBuffer);\r
35    SetIndexBuffer(1, ExtRedBuffer);\r
36    SetIndexBuffer(2, ExtMABuffer);\r
37    SetIndexBuffer(3, ExtBuffer);\r
38 //---- drawing settings\r
39    #indicators_init#\r
40 //----\r
41    IndicatorDigits(6);\r
42    SetIndexDrawBegin(0,38);\r
43    SetIndexDrawBegin(1,38);\r
44 //---- name for DataWindow and indicator subwindow label\r
45    IndicatorShortName("AC");\r
46 //---- initialization done\r
47    return(0);\r
48   }\r
49 //+------------------------------------------------------------------+\r
50 //| Accelerator/Decelerator Oscillator                               |\r
51 //+------------------------------------------------------------------+\r
52 int start()\r
53   {\r
54    int    limit;\r
55    int    counted_bars=IndicatorCounted();\r
56    double prev,current;\r
57 //---- check for possible errors\r
58    if(counted_bars<0) return(-1);\r
59 //---- last counted bar will be recounted\r
60    if(counted_bars>0) counted_bars--;\r
61    limit=Bars-counted_bars;\r
62 //---- macd counted in the 1-st additional buffer\r
63    for(int i=0; i<limit; i++)\r
64       ExtMABuffer[i]=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN,i);\r
65 //---- signal line counted in the 2-nd additional buffer\r
66    for(i=0; i<limit; i++)\r
67       ExtBuffer[i]=iMAOnArray(ExtMABuffer,Bars,5,0,MODE_SMA,i);\r
68 //---- dispatch values between 2 buffers\r
69    bool up=true;\r
70    for(i=limit-1; i>=0; i--)\r
71      {\r
72       current=ExtMABuffer[i]-ExtBuffer[i];\r
73       prev=ExtMABuffer[i+1]-ExtBuffer[i+1];\r
74       if(current>prev) up=true;\r
75       if(current<prev) up=false;\r
76       if(!up)\r
77         {\r
78          ExtRedBuffer[i]=current;\r
79          ExtGreenBuffer[i]=0.0;\r
80         }\r
81       else\r
82         {\r
83          ExtGreenBuffer[i]=current;\r
84          ExtRedBuffer[i]=0.0;\r
85         }\r
86      }\r
87 //---- done\r
88    return(0);\r
89   }\r
90 //+------------------------------------------------------------------+\r