Merge branch 'master' of git://repo.or.cz/mqlkit
[mqlkit.git] / indicators / CK_Speed.mq4
blob5769a87b78b565209be482463e06259b9a8bb7d0
1 //+------------------------------------------------------------------+\r
2 //|                                                   TrendJugde.mq4 |\r
3 //|                      Copyright © 2008, MetaQuotes Software Corp. |\r
4 //|                                        http://www.metaquotes.net |\r
5 //+------------------------------------------------------------------+\r
6 #property copyright "Copyright © 2008, MetaQuotes Software Corp."\r
7 #property link      "http://www.metaquotes.net"\r
8 extern int period=20;\r
9 extern double level=50;\r
10 //extern int ema1=34;\r
11 //extern int ema2=89;\r
12 #property indicator_separate_window\r
13 #property  indicator_buffers 3\r
14 #property  indicator_color1  Green\r
15 #property  indicator_color2  Red\r
16 #property  indicator_color3  Yellow\r
19 #property indicator_maximum 3\r
21 bool uptrend=false;\r
22 bool downtrend=false;\r
23 double fast[],medium[],slow[],atr[],std[],rsistd[],rsiatr[];\r
25 //+------------------------------------------------------------------+\r
26 //| Custom indicator initialization function                         |\r
27 //+------------------------------------------------------------------+\r
28 int init()\r
29   {\r
30 //---- indicators\r
31 IndicatorBuffers(7);   \r
32 //---- drawing settings\r
33       \r
34    SetIndexBuffer(0,fast);//bbMacd line\r
35    SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,1);\r
36    SetIndexBuffer(1,medium);//Upperband line\r
37    SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1);\r
38    SetIndexDrawBegin(0,period);\r
39    SetIndexDrawBegin(1,period);\r
40    \r
41    SetIndexBuffer(2,slow);//overbough\r
42    SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);\r
43     SetIndexDrawBegin(2,period);\r
44  \r
45   SetIndexBuffer(3,atr);//overbough\r
46   SetIndexBuffer(4,std);//overbough\r
47   SetIndexBuffer(5,rsistd);//overbough\r
48   SetIndexBuffer(6,rsiatr);//overbough\r
49   \r
50   IndicatorShortName("CK Speed "+ period);\r
51   SetIndexLabel(0,"Trend");\r
52   SetIndexLabel(1,"Correction");\r
53 SetIndexLabel(2,"Sleep");\r
54   \r
55 //----\r
56    return(0);\r
57   }\r
58 //+------------------------------------------------------------------+\r
59 //| Custom indicator deinitialization function                       |\r
60 //+------------------------------------------------------------------+\r
61 int deinit()\r
62   {\r
63 //----\r
64    \r
65 //----\r
66    return(0);\r
67   }\r
68 //+------------------------------------------------------------------+\r
69 //| Custom indicator iteration function                              |\r
70 //+------------------------------------------------------------------+\r
71 int start()\r
72   {\r
73    \r
74 //----\r
75 double prev,current,tmp;\r
76    int limit;\r
77    int counted_bars=IndicatorCounted();\r
78 //---- check for possible errors\r
79    if(counted_bars<0) return(-1);\r
80 //---- last counted bar will be recounted\r
81    if(counted_bars>0) counted_bars--;\r
82    limit=Bars-counted_bars;\r
83    //uptrend=true;\r
84    //owntrend=true;\r
85    double filterbuy=60;\r
86    double filtersell=40;\r
87 //----\r
88 for(int k=limit-1;k>=0;k--){\r
89    atr[k]=iATR(Symbol(),0,period,k);\r
90      std[k]=iStdDev(Symbol(),0,period,0,0,PRICE_MEDIAN,k);\r
91 }\r
92 //for(int t=limit-period;t>=0;t--){\r
93   \r
94 //}\r
95 for(int i=limit-1; i>=0; i--)\r
96  {\r
97      rsistd[i]=iRSIOnArray(std,0,period,i);\r
98      rsiatr[i]=iRSIOnArray(atr,0,period,i);\r
99      \r
100       if(rsistd[i]>=level&&rsiatr[i]>=level){\r
101          fast[i]=3;\r
102          medium[i]=0;\r
103          slow[i]=0;\r
104          \r
105        }else if(rsistd[i]<level&&rsiatr[i]<level){\r
106          fast[i]=0;\r
107          medium[i]=0;\r
108          slow[i]=1;\r
109       } else{\r
110          fast[i]=0;\r
111          medium[i]=2;\r
112          slow[i]=0;\r
113       }\r
114   }         \r
115    return(0);\r
116   }\r
117 //+------------------------------------------------------------------+