bleh
[mqlkit.git] / include / INDICATOR_COUNTED.mqh
blob0485f617e5bfeca8f1c7bc2cdb9c2200417663ab
1  /*\r
2 //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+\r
3 //|                                            INDICATOR_COUNTED.mqh |\r
4 //|                           Copyright © 2006,     Nikolay Kositsin |\r
5 //|                              Khabarovsk,   farria@mail.redcom.ru | \r
6 //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+\r
7 /*\r
8 //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+\r
9  INDICATOR_COUNTED() - Ýòî äîïîëíèòåëüíàÿ ôóíêöèÿ äëÿ âîçâðàòà êîëè÷åñòâà óæå ïîäñ÷èòàííûõ áàðîâ  | \r
10  èíäèêàòîðà. Å¸ ãëàâíàÿ îñîáåííîñòü çàêëþ÷àåòñÿ â òîì, ÷òî îíà ïîçâîëÿåò íå ïåðåñ÷èòûâàòü         |\r
11  èíäèêàòîð íà âñåõ áàðàõ ïðè ïîäêëþ÷åíèè ê èíòåðíåòó. Òî åñòü ïðè ïîäêëþ÷åíèè ê èíòåðíåòó ýòà     |\r
12  ôóíêöèÿ â îòëè÷èå îò  ñòàíäàðòíîé ôóíêöèè IndicatorCounted() âñ¸ ðàâíî âîçâðàùàåò êîëè÷åñòâî     |\r
13  ïîäñ÷èòàííûõ äî ïîäêëþ÷åíèÿ ê èíòåðíåòó áàðîâ, à íå íîëü!          Ôóíêöèÿ  INDICATOR_COUNTED()  | \r
14  ïðåäíàçíà÷åíà äëÿ çàìåíû ôóíêöèè IndicatorCounted() Ïðè çíà÷åíèè ïàðàìåòðà                       |\r
15  INDICATOR_COUNTED.Input=0; ôóíêöèÿ âîçâðàùàåò êîëè÷åñòâî óæå ïîäñ÷èòàííûõ áàðîâ, ïðè çíà÷åíèè    |\r
16  ïàðàìåòðà INDICATOR_COUNTED.Input = 1; ïðîèñõîäèò ôèêñàöèÿ âðåìåíè íóëåâîãî áàðà, äëÿ ðàñ÷¸òà    |\r
17  ïî åãî íîìåðó ïðè ñëåäóþùåì ñòàðòå ôóíêöèè int start() èñòèííîãî çíà÷åíèÿ êîëè÷åñòâà óæå         | \r
18  ïîäñ÷èòàííûõ áàðîâ.    Ïðè çíà÷åíèè ïàðàìåòðà INDICATOR_COUNTED.Input = -1; ïðîèñõîäèò           |       \r
19  îáíóëåíèå âðåìåíè íóëåâîãî áàðà, åñëè ýòî íåîáõîäèìî, ïðè èñïîëüçîâàíèè îïåðàòîðà return(-1);    |\r
20  äëÿ ôóíêöèè int start().                                                                         |\r
21  Ïðèìåð îáðàùåíèÿ:                                                                                |\r
22                                                                                                   |\r
23 //----+ Ââåäåíèå öåëûõ ïåðåìåííûõ è ïîëó÷åíèå óæå ïîäñ÷èòàííûõ áàðîâ                              |\r
24 //---- áëîêèðîâàíèå ïåðåñ÷¸òà âñåõ ïîäñ÷èòàííûõ è îòðèñîâàííûõ áàðîâ ïðè ïîäêëþ÷åíèè ê èíòåðíåòó  |\r
25 incounted_bars=INDICATOR_COUNTED(0); INDICATOR_COUNTED(1);                                        |\r
26 //---- ïðîâåðêà íà âîçìîæíûå îøèáêè                                                               |\r
27 if (counted_bars<0){INDICATOR_COUNTED(-1); return(-1);}                                           |\r
28 //---- ïîñëåäíèé ïîäñ÷èòàííûé áàð äîëæåí áûòü ïåðåñ÷èòàí                                          |\r
29 if (counted_bars>0) counted_bars--;                                                               |\r
30 //---- îïðåäåëåíèå íîìåðà ñàìîãî ñòàðîãî áàðà, íà÷èíàÿ ñ êîòîðîãî áóäåò ïðîèçåä¸í ïåðåñ÷¸ò  áàðîâ |\r
31 int limit=Bars-1-counted_bars;                                                                    |\r
32 //----                                                                                            |\r
33 for(bar=limit;bar>=0;bar--) { êîä âàøåãî èíäèêàòîðà }                                             |\r
34 Åñëè â òåêñòå èíäèêàòîðà åñòü âûðàæåíèå return(-1) äëÿ ôóíêöèè int start(); òî åãî ñëåäóåò        |\r
35 çàìåíèòü íà {INDICATOR_COUNTED(-1);return(-1);}                                                   |\r
36 //+SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS+\r
37 */\r
38 int  INDICATOR_COUNTED(int INDICATOR_COUNTED.Input) \r
39 //----+ \r
40 {   \r
41   int INDICATOR_COUNTED.counted_bars;\r
42   //----+ xxxxxxxxxxx\r
43   if (INDICATOR_COUNTED.Input == 1)\r
44     {\r
45       //---- ââåäåíèå ïåðåìåííûõ è ïîëó÷åíèå èõ çíà÷åíèé\r
46       static int INDICATOR_COUNTED.T2, INDICATOR_COUNTED.Period; \r
47       INDICATOR_COUNTED.counted_bars=IndicatorCounted(); \r
48       if (INDICATOR_COUNTED.counted_bars<0)\r
49        {\r
50         //INDICATOR_COUNTED.T2=0; \r
51         return(INDICATOR_COUNTED.counted_bars);\r
52        }\r
53        //----+ ôèêñàöèÿ âðåìåíè îòêðûòèÿ ïðåäïîñëåäíåãî ïîäñ÷èòàííîãî áàðà \r
54       INDICATOR_COUNTED.T2 =Time[2]; \r
55       INDICATOR_COUNTED.Period=Period();\r
56       return(INDICATOR_COUNTED.counted_bars);\r
57     }\r
58   INDICATOR_COUNTED.counted_bars=IndicatorCounted(); \r
59   if (INDICATOR_COUNTED.counted_bars<0)\r
60     {\r
61     INDICATOR_COUNTED.T2=0; \r
62     return(INDICATOR_COUNTED.counted_bars);\r
63     }\r
64   //----+\r
65   if((INDICATOR_COUNTED.counted_bars!=0)&&(IsConnected()==TRUE)&&(INDICATOR_COUNTED.T2==0))\r
66          {\r
67           //Ïå÷àòü ðåçóëüòàòà îáðàùåíèÿ ê ôóíêöèè INDICATOR_COUNTED ïðè íåêîððåêòíîé ðàáîòå èíäèêàòîðà \r
68           Print("INDICATOR_COUNTED: Òîðãîâûé Òåðìèíàë òîëüêî ÷òî ïîäêëþ÷èëñÿ ê èíòåðíåòó");\r
69           Print("INDICATOR_COUNTED: Ïðåäïîñëåäíèé ïîäñ÷èòàííûé áàð íå íàéäåí");\r
70           Print("INDICATOR_COUNTED: Èñòèííîå êîëè÷åñòâî óæå ïîäñ÷èòàííûõ áàðîâ îïðåäåëèòü íåâîçìîæíî ");\r
71           Print("INDICATOR_COUNTED: Ôóíêöèÿ âåðí¸ò êîëè÷åñòâî óæå ïîäñ÷èòàííûõ áàðîâ ðàâíîå íóëþ");\r
72           Print("INDICATOR_COUNTED: Áóäåò ïðîèçâåä¸í ïîëíûé ïåðåñ÷¸ò èíäèêàòîðà íà âñåõ áàðàõ");\r
73         //PlaySound("wait.wav");\r
74           return(0); \r
75          }\r
76   //----+ xxxxxxxxxxx\r
77   if ((INDICATOR_COUNTED.Input==0)&&(INDICATOR_COUNTED.Period==Period()))\r
78     {\r
79      if((INDICATOR_COUNTED.counted_bars==0)&&(IsConnected()==TRUE))\r
80       { \r
81        //Print("INDICATOR_COUNTED: Òîðãîâûé Òåðìèíàë òîëüêî ÷òî ïîäêëþ÷èëñÿ ê èíòåðíåòó");  \r
82        //Print("INDICATOR_COUNTED: Ñåé÷àñ Ôóíêöèÿ INDICATOR_COUNTED() îïðåäåëèò êîëè÷åñòâî ôàêòè÷åñêè ïîäñ÷èòàííûõ áàðîâ");\r
83        if (INDICATOR_COUNTED.T2 == 0)\r
84          {\r
85           //Ïå÷àòü ðåçóëüòàòà îáðàùåíèÿ ê ôóíêöèè INDICATOR_COUNTED ïðè íåêîððåêòíîé ðàáîòå èíäèêàòîðà \r
86           Print("INDICATOR_COUNTED: Òîðãîâûé Òåðìèíàë òîëüêî ÷òî ïîäêëþ÷èëñÿ ê èíòåðíåòó");\r
87           Print("INDICATOR_COUNTED: Ïðåäïîñëåäíèé ïîäñ÷èòàííûé áàð íå íàéäåí");\r
88           Print("INDICATOR_COUNTED: Èñòèííîå êîëè÷åñòâî óæå ïîäñ÷èòàííûõ áàðîâ îïðåäåëèòü íåâîçìîæíî ");\r
89           Print("INDICATOR_COUNTED: Ôóíêöèÿ âåðí¸ò êîëè÷åñòâî óæå ïîäñ÷èòàííûõ áàðîâ ðàâíîå íóëþ");\r
90           Print("INDICATOR_COUNTED: Áóäåò ïðîèçâåä¸í ïîëíûé ïåðåñ÷¸ò èíäèêàòîðà íà âñåõ áàðàõ");\r
91         //PlaySound("wait.wav");\r
92           return(0); \r
93          }\r
94         //----+ ïîèñê ïðåäïîñëåäíåãî ïîäñ÷èòàííîãî áàðà ïî âðåìåíè åãî îòêðûòèÿ \r
95        int  INDICATOR_COUNTED.BarShift=iBarShift(NULL,0,INDICATOR_COUNTED.T2,TRUE); \r
96        if ((INDICATOR_COUNTED.BarShift<2)||(INDICATOR_COUNTED.T2!=Time[INDICATOR_COUNTED.BarShift]))\r
97          {\r
98           //Ïå÷àòü ðåçóëüòàòà îáðàùåíèÿ ê ôóíêöèè INDICATOR_COUNTED ïðè íåêîððåêòíîé ðàáîòå èíäèêàòîðà \r
99           Print("INDICATOR_COUNTED: Òîðãîâûé Òåðìèíàë òîëüêî ÷òî ïîäêëþ÷èëñÿ ê èíòåðíåòó");\r
100           Print("INDICATOR_COUNTED: Ïðåäïîñëåäíèé ïîäñ÷èòàííûé áàð íå íàéäåí");\r
101           Print("INDICATOR_COUNTED: Èñòèííîå êîëè÷åñòâî óæå ïîäñ÷èòàííûõ áàðîâ îïðåäåëèòü íåâîçìîæíî ");\r
102           Print("INDICATOR_COUNTED: Ôóíêöèÿ âåðí¸ò êîëè÷åñòâî óæå ïîäñ÷èòàííûõ áàðîâ ðàâíîå íóëþ");\r
103           Print("INDICATOR_COUNTED: Áóäåò ïðîèçâåä¸í ïîëíûé ïåðåñ÷¸ò èíäèêàòîðà íà âñåõ áàðàõ");\r
104         //PlaySound("wait.wav");\r
105           return(0); \r
106          }\r
107        int INDICATOR_COUNTED.Resalt=Bars-1-INDICATOR_COUNTED.BarShift+2;\r
108        //Ïå÷àòü ðåçóëüòàòà îáðàùåíèÿ ê ôóíêöèè INDICATOR_COUNTED ïðè êîððåêòíîé ðàáîòå èíäèêàòîðà \r
109      //Print("INDICATOR_COUNTED: Òîðãîâûé Òåðìèíàë òîëüêî ÷òî ïîäêëþ÷èëñÿ ê èíòåðíåòó"); \r
110      //Print("INDICATOR_COUNTED: Ñåé÷àñ Ôóíêöèÿ îïðåäåëèò êîëè÷åñòâî ôàêòè÷åñêè ïîäñ÷èòàííûõ áàðîâ"); \r
111      //Print("INDICATOR_COUNTED: Ïðåäïîñëåäíèé ïîäñ÷èòàííûé áàð íàéäåí");\r
112      //Print("INDICATOR_COUNTED: Êîëè÷åñòâî óæå ïîäñ÷èòàííûõ áàðîâ áóäåò ðàâíî "+INDICATOR_COUNTED.Resalt+"");\r
113      //Print("INDICATOR_COUNTED: Áóäåò ïðîèçâåä¸í ïåðåñ÷¸ò èíäèêàòîðà âñåãî íà "+INDICATOR_COUNTED.BarShift+" áàðàõ");\r
114      //Print("INDICATOR_COUNTED: BarShift ="+INDICATOR_COUNTED.BarShift+" INDICATOR_COUNTED.T2 ="+INDICATOR_COUNTED.T2+""); \r
115        return(INDICATOR_COUNTED.Resalt); \r
116       }\r
117      else return(INDICATOR_COUNTED.counted_bars);\r
118     }\r
119    //----+ xxxxxxxxxxx\r
120   if (INDICATOR_COUNTED.Input ==-1)\r
121    { \r
122     INDICATOR_COUNTED.T2 =0; \r
123     INDICATOR_COUNTED.Period=-1; \r
124     Print("INDICATOR_COUNTED: Îøèáêà â ðàñ÷¸òå èíäèêàòîðà");\r
125     Print("INDICATOR_COUNTED: Ðàáîòà ôóíêöèè int start() áóäåò ïðåðâàíà îïåðàòîðîì return(-1)");\r
126   //PlaySound("stops.wav");  \r
127     return(0); \r
128    }\r
129   return(INDICATOR_COUNTED.counted_bars);\r
131 //--+ --------------------------------------------------------------------------------------------+\r