Merge branch 'master' of git://repo.or.cz/mqlkit
[mqlkit.git] / indicators / Momentum.mq4
blob3c9aec130404cefece58aeaab94a23e0c26b7f9e
1 //+------------------------------------------------------------------+\r
2 //|                                                     Momentum.mq4 |\r
3 //|                      Copyright © 2004, MetaQuotes Software Corp. |\r
4 //|                                       http://www.metaquotes.net/ |\r
5 //+------------------------------------------------------------------+\r
6 #property copyright "Copyright © 2004, MetaQuotes Software Corp."\r
7 #property link      "http://www.metaquotes.net/"\r
8 \r
9 #property indicator_separate_window\r
10 #property indicator_buffers 1\r
11 #property indicator_color1 DodgerBlue\r
12 //---- input parameters\r
13 extern int MomPeriod=14;\r
14 //---- buffers\r
15 double MomBuffer[];\r
16 //+------------------------------------------------------------------+\r
17 //| Custom indicator initialization function                         |\r
18 //+------------------------------------------------------------------+\r
19 int init()\r
20   {\r
21    string short_name;\r
22 //---- indicator line\r
23    SetIndexStyle(0,DRAW_LINE);\r
24    SetIndexBuffer(0,MomBuffer);\r
25 //---- name for DataWindow and indicator subwindow label\r
26    short_name="Mom("+MomPeriod+")";\r
27    IndicatorShortName(short_name);\r
28    SetIndexLabel(0,short_name);\r
29 //----\r
30    SetIndexDrawBegin(0,MomPeriod);\r
31 //----\r
32    return(0);\r
33   }\r
34 //+------------------------------------------------------------------+\r
35 //| Momentum                                                         |\r
36 //+------------------------------------------------------------------+\r
37 int start()\r
38   {\r
39    int i,counted_bars=IndicatorCounted();\r
40 //----\r
41    if(Bars<=MomPeriod) return(0);\r
42 //---- initial zero\r
43    if(counted_bars<1)\r
44       for(i=1;i<=MomPeriod;i++) MomBuffer[Bars-i]=0.0;\r
45 //----\r
46    i=Bars-MomPeriod-1;\r
47    if(counted_bars>=MomPeriod) i=Bars-counted_bars-1;\r
48    while(i>=0)\r
49      {\r
50       MomBuffer[i]=Close[i]*100/Close[i+MomPeriod];\r
51       i--;\r
52      }\r
53    return(0);\r
54   }\r
55 //+------------------------------------------------------------------+