AhtashamShahzad3 2 lat temu
rodzic
commit
f772e3c1cf
2 zmienionych plików z 193 dodań i 70 usunięć
  1. BIN
      MK_BOS_CHOCH.ex5
  2. 193 70
      MK_BOS_CHOCH.mq5

BIN
MK_BOS_CHOCH.ex5


+ 193 - 70
MK_BOS_CHOCH.mq5

@@ -13,132 +13,224 @@ input string object_name = "line";
13
 string trend;
13
 string trend;
14
 bool bearish_found = false;
14
 bool bearish_found = false;
15
 bool bullish_found = false;
15
 bool bullish_found = false;
16
+
17
+int index_of_low = 0;
18
+int high_index=0;
19
+double high,low,low1,high1;
16
 //+------------------------------------------------------------------+
20
 //+------------------------------------------------------------------+
17
 //| Expert initialization function                                   |
21
 //| Expert initialization function                                   |
18
 //+------------------------------------------------------------------+
22
 //+------------------------------------------------------------------+
19
 void foo(int index)
23
 void foo(int index)
20
   {
24
   {
21
-   if(checkCandle(index) == "Bullish")
25
+
26
+   for(int i=index; i > 0; i--)
22
      {
27
      {
23
-      trend = "uptrend";
24
-      double high,low = 0.0;
25
 
28
 
29
+      if(checkCandle(index) == "Bullish")
30
+        {
31
+
32
+         trend = "uptrend";
26
 
33
 
27
-      // to store high and low of the value after the object
28
-      high = iHigh(Symbol(),PERIOD_CURRENT,index-1);
34
+         //double high,low = 0.0;
29
 
35
 
30
-      //low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
36
+         // to store high and low of the value after the object
37
+         high = iHigh(Symbol(),PERIOD_CURRENT,index);
31
 
38
 
32
-      for(int i=index - 2 ; i > 0; i--)
33
-        {
34
-         double high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
39
+         //low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
35
 
40
 
36
-         //double low1  = iLow(Symbol(),PERIOD_CURRENT,i);
37
 
41
 
38
-         if(high1 > high)
42
+         if(trend == "uptrend")
39
            {
43
            {
40
-            high = high1;
41
-            int count = (index-1) - i;
42
 
44
 
43
-            Print("count",count);
44
 
45
 
45
 
46
 
46
-            for(int j=1; j < count; j++)
47
+
48
+            high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
49
+
50
+            //double low1  = iLow(Symbol(),PERIOD_CURRENT,i);
51
+
52
+            if(high1 > high)
47
               {
53
               {
54
+               high = high1;
55
+
56
+               //  Print("high break at index value",i);
57
+               // Print("index is ",index);
58
+
59
+               int count = (index-1) - i;
60
+               Print("count is ", count);
61
+
62
+               // Print("index updated ",index);
48
 
63
 
49
-               if(checkCandle(index-j) == "Bearish")
64
+               // Print("count",count);
65
+
66
+               for(int j=1; j <= count; j++)
50
                  {
67
                  {
51
-                  low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
52
-                  bearish_found = true;
68
+
69
+                  if(checkCandle(index-j) == "Bearish")
70
+                    {
71
+                     low =  iLow(Symbol(),PERIOD_CURRENT,index-j);
72
+                     bearish_found = true;
73
+                    }
74
+
53
                  }
75
                  }
54
 
76
 
55
-              }
77
+               if(bearish_found == true)
78
+                 {
79
+                  //double low1 ;
80
+                  //Print("where");
81
+                  for(int k=1; k <= count; k++)
82
+                    {
56
 
83
 
57
-            if(bearish_found == true)
58
-              {
59
-               double low1;
60
-               for(int k=1; k <= count; k++)
84
+                     low1 = iLow(Symbol(),PERIOD_CURRENT,index - k);
85
+                     if(low1 <= low)
86
+                       {
87
+                        //Print("here");
88
+                        low = low1;
89
+                        index_of_low = index - k;
90
+                        Print("low is updated at index : ",index - k);
91
+
92
+                       }
93
+                    }
94
+                  bearish_found = false;
95
+
96
+                 }
97
+
98
+               Print(" high price is ", high);
99
+               Print("low price is ", low);
100
+               Print("index of low is ", index_of_low);
101
+
102
+               for(int l=index_of_low; l > 0; l--)
61
                  {
103
                  {
62
-                  low1 = iLow(Symbol(),PERIOD_CURRENT,index - k);
63
-                  if(low1 < low)
104
+                  // print("hi");
105
+                  double close = iClose(Symbol(),PERIOD_CURRENT,l);
106
+
107
+                  if(close < low)
64
                     {
108
                     {
65
-                     low = low1;
109
+                     double price_low = iLow(Symbol(),PERIOD_CURRENT,l+1);
110
+                     double time = iTime(Symbol(),PERIOD_CURRENT,l+1);
111
+                     double time1 = iTime(Symbol(),PERIOD_CURRENT,l+1);
112
+                     ObjectCreate(0,"tline1",OBJ_TREND,0,time,price_low,time1,price_low);
113
+                     trend = "downtrend";
114
+                     Print("choch");
115
+
116
+                     Print("close", close);
117
+                     break;
118
+
66
                     }
119
                     }
120
+
67
                  }
121
                  }
68
-               bearish_found = false;
122
+               index = i;
69
 
123
 
70
               }
124
               }
71
 
125
 
72
-
73
            }
126
            }
127
+         //
74
 
128
 
75
 
129
 
76
         }
130
         }
77
 
131
 
78
-      Print(" high price is ", high);
79
-      Print("low price is ", low);
132
+      if(checkCandle(index) == "Bearish")
133
+        {
80
 
134
 
81
-     }
135
+         trend = "downtrend";
82
 
136
 
83
-   if(checkCandle(index) == "Bearish")
84
-     {
85
-      trend = "downtrend";
86
-      double high,low = 0.0;
137
+         // double high,low = 0.0;
87
 
138
 
139
+         // to store high and low of the value after the object
140
+         low = iLow(Symbol(),PERIOD_CURRENT,index);
88
 
141
 
89
-      // to store high and low of the value after the object
90
-      low = iLow(Symbol(),PERIOD_CURRENT,index-1);
142
+         //low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
91
 
143
 
92
-      //low =  iLow(Symbol(),PERIOD_CURRENT,index-1);
144
+         if(trend == "downtrend")
145
+           {
93
 
146
 
94
-      for(int i=index - 2 ; i > 0; i--)
95
-        {
96
-         double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
97
 
147
 
98
-         //double low1  = iLow(Symbol(),PERIOD_CURRENT,i);
99
 
148
 
100
-         if(low1 < low)
101
-           {
102
-            low = low1;
103
-            int count = (index-1) - i;
104
 
149
 
105
-            Print("count",count);
150
+            low1 = iLow(Symbol(),PERIOD_CURRENT,i);
106
 
151
 
152
+            //double low1  = iLow(Symbol(),PERIOD_CURRENT,i);
107
 
153
 
108
-            for(int j=1; j < count; j++)
154
+            if(low1 < low)
109
               {
155
               {
156
+               low = low1;
157
+
158
+               //  Print("high break at index value",i);
159
+               // Print("index is ",index);
160
+
161
+               int count = (index-1) - i;
162
+               Print("count is ", count);
163
+
164
+               // Print("index updated ",index);
165
+
166
+               // Print("count",count);
110
 
167
 
111
-               if(checkCandle(index-j) == "Bullish")
168
+               for(int j=1; j <= count; j++)
112
                  {
169
                  {
113
-                  high =  iHigh(Symbol(),PERIOD_CURRENT,index-1);
114
-                  bullish_found = true;
170
+
171
+                  if(checkCandle(index-j) == "Bullish")
172
+                    {
173
+                     high =  iHigh(Symbol(),PERIOD_CURRENT,index-j);
174
+                     bullish_found = true;
175
+                    }
176
+
115
                  }
177
                  }
116
 
178
 
117
-              }
179
+               if(bullish_found == true)
180
+                 {
181
+                  high1;
182
+                  //Print("where");
183
+                  for(int k=1; k <= count; k++)
184
+                    {
118
 
185
 
119
-            if(bullish_found == true)
120
-              {
121
-               double high1;
122
-               for(int k=1; k <= count; k++)
186
+                     high1 = iHigh(Symbol(),PERIOD_CURRENT,index - k);
187
+                     if(high1 > high)
188
+                       {
189
+                        //Print("here");
190
+                        high = high1;
191
+                        index_of_low = index - k;
192
+                        Print("high is updated at index : ",index - k);
193
+
194
+                       }
195
+                    }
196
+                  bullish_found = false;
197
+
198
+                 }
199
+
200
+               Print(" high price is ", high);
201
+               Print("low price is ", low);
202
+               Print("index of low is ", index_of_low);
203
+
204
+               for(int l=index_of_low; l > 0; l--)
123
                  {
205
                  {
124
-                  high1 = iHigh(Symbol(),PERIOD_CURRENT,index - k);
125
-                  if(high1 > high)
206
+                  // print("hi");
207
+                  double close = iClose(Symbol(),PERIOD_CURRENT,l);
208
+                  if(close > high)
126
                     {
209
                     {
127
-                     high = high1;
210
+
211
+                     double price_high = iLow(Symbol(),PERIOD_CURRENT,l+1);
212
+                     double time = iTime(Symbol(),PERIOD_CURRENT,l+1);
213
+                     double time1 = iTime(Symbol(),PERIOD_CURRENT,l+1);
214
+                     ObjectCreate(0,"tline2",OBJ_TREND,0,time,price_high,time1,price_high);
215
+
216
+                     trend = "uptrend";
217
+                     Print("choch");
218
+                     Print(l);
219
+
220
+                     Print("close", close);
221
+                     break;
222
+
128
                     }
223
                     }
224
+
129
                  }
225
                  }
130
-               bullish_found = false;
226
+               index = i;
131
 
227
 
132
               }
228
               }
133
 
229
 
134
-
135
            }
230
            }
136
-
231
+         //
137
 
232
 
138
         }
233
         }
139
-      Print(" high price is ", high);
140
-      Print("low price is ", low);
141
-
142
      }
234
      }
143
 
235
 
144
   }
236
   }
@@ -148,19 +240,25 @@ void foo(int index)
148
 int OnInit()
240
 int OnInit()
149
   {
241
   {
150
 
242
 
151
-   //ObjectCreate(0,"line",OBJ_VLINE,0,D'2023.08.01 10:00:27',0);
243
+   ObjectCreate(0,"line",OBJ_VLINE,0,D'2023.07.01 10:00:27',0);
152
    object_find(object_name);
244
    object_find(object_name);
153
 //Print(ObjectFind(0,"line"));  // to find the object drawn on the chart
245
 //Print(ObjectFind(0,"line"));  // to find the object drawn on the chart
154
 
246
 
155
    if(object_find(object_name) == true)
247
    if(object_find(object_name) == true)
156
      {
248
      {
157
 
249
 
158
-
159
       datetime time_of_candle = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0);
250
       datetime time_of_candle = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0);
160
-      Print("time is " , time_of_candle);
161
 
251
 
162
-      int index = iBarShift(0, PERIOD_CURRENT,time_of_candle, true);
163
-      Print("index is " , index);
252
+      Print("line time: ",time_of_candle);
253
+      int index = iBarShift(Symbol(), PERIOD_CURRENT, time_of_candle, false);
254
+      Print(index);
255
+
256
+      //      datetime time_of_candle = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0);
257
+      //      Print("time is " , time_of_candle);
258
+      //
259
+      //      int index = iBarShift(0, PERIOD_CURRENT,time_of_candle, true);
260
+
261
+      //  Print("index is " , index);
164
       foo(index);
262
       foo(index);
165
 
263
 
166
      }
264
      }
@@ -186,12 +284,35 @@ void OnDeinit(const int reason)
186
 //+------------------------------------------------------------------+
284
 //+------------------------------------------------------------------+
187
 void OnTick()
285
 void OnTick()
188
   {
286
   {
287
+   if(NewBar())
288
+     {
289
+      ObjectSetInteger(0,"tline1",OBJPROP_TIME,iTime(Symbol(), PERIOD_CURRENT,0));
189
 
290
 
291
+      ObjectSetInteger(0,"tline2",OBJPROP_TIME,iTime(Symbol(), PERIOD_CURRENT,0));
292
+     }
190
 
293
 
191
 
294
 
192
   }
295
   }
193
 
296
 
194
 
297
 
298
+//+------------------------------------------------------------------+
299
+//|                                                                  |
300
+//+------------------------------------------------------------------+
301
+bool NewBar()
302
+  {
303
+   static datetime Last_bar ;
304
+   datetime Current_bar = iTime(Symbol(), PERIOD_CURRENT,0);
305
+   if(Current_bar != Last_bar)
306
+     {
307
+      Last_bar = Current_bar;
308
+      return (true);
309
+     }
310
+   else
311
+     {
312
+      return (false);
313
+     }
314
+  }
315
+
195
 //+------------------------------------------------------------------+
316
 //+------------------------------------------------------------------+
196
 //|                                                                  |
317
 //|                                                                  |
197
 //+------------------------------------------------------------------+
318
 //+------------------------------------------------------------------+
@@ -224,3 +345,5 @@ string checkCandle(int i)  // to check the candle is bullish or bearish
224
    return "empty";
345
    return "empty";
225
   }
346
   }
226
 //+------------------------------------------------------------------+
347
 //+------------------------------------------------------------------+
348
+
349
+//+------------------------------------------------------------------+