Merge branch 'master' of git://repo.or.cz/mqlkit
[mqlkit.git] / indicators / Bears.mq4
blobd694b6119a6dfd2e25a333dd4f914f4d543f3b4e
1 //+------------------------------------------------------------------+\r
2 //|                                                        Bears.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 1\r
11 #property indicator_color1 Silver\r
12 //---- input parameters\r
13 extern int BearsPeriod=13;\r
14 //---- buffers\r
15 double BearsBuffer[];\r
16 double TempBuffer[];\r
17 //+------------------------------------------------------------------+\r
18 //| Custom indicator initialization function                         |\r
19 //+------------------------------------------------------------------+\r
20 int init()\r
21   {\r
22    string short_name;\r
23 //---- 1 additional buffer used for counting.\r
24    IndicatorBuffers(2);\r
25    IndicatorDigits(Digits);\r
26 //---- indicator line\r
27    SetIndexStyle(0,DRAW_HISTOGRAM);\r
28    SetIndexBuffer(0,BearsBuffer);\r
29    SetIndexBuffer(1,TempBuffer);\r
30 //---- name for DataWindow and indicator subwindow label\r
31    short_name="Bears("+BearsPeriod+")";\r
32    IndicatorShortName(short_name);\r
33    SetIndexLabel(0,short_name);\r
34 //----\r
35    return(0);\r
36   }\r
37 //+------------------------------------------------------------------+\r
38 //| Bears Power                                                      |\r
39 //+------------------------------------------------------------------+\r
40 int start()\r
41   {\r
42    int i,counted_bars=IndicatorCounted();\r
43 //----\r
44    if(Bars<=BearsPeriod) return(0);\r
45 //----\r
46    int limit=Bars-counted_bars;\r
47    if(counted_bars>0) limit++;\r
48    for(i=0; i<limit; i++)\r
49       TempBuffer[i]=iMA(NULL,0,BearsPeriod,0,MODE_EMA,PRICE_CLOSE,i);\r
50 //----\r
51    i=Bars-counted_bars-1;\r
52    while(i>=0)\r
53      {\r
54       BearsBuffer[i]=Low[i]-TempBuffer[i];\r
55       i--;\r
56      }\r
57 //----\r
58    return(0);\r
59   }\r
60 //+------------------------------------------------------------------+