|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+//+------------------------------------------------------------------+
|
|
|
2
|
+//| MK_BOS_CHOCH.mq5 |
|
|
|
3
|
+//| Copyright 2023, MetaQuotes Ltd. |
|
|
|
4
|
+//| https://www.mql5.com |
|
|
|
5
|
+//+------------------------------------------------------------------+
|
|
|
6
|
+#property copyright "Copyright 2023, MetaQuotes Ltd."
|
|
|
7
|
+#property link "https://www.mql5.com"
|
|
|
8
|
+#property version "1.00"
|
|
|
9
|
+
|
|
|
10
|
+sinput string str = "<><><><><><> Object Name <><><><><><>";
|
|
|
11
|
+input string object_name = "line";
|
|
|
12
|
+
|
|
|
13
|
+string trend;
|
|
|
14
|
+bool bearish_found = false;
|
|
|
15
|
+bool bullish_found = false;
|
|
|
16
|
+//+------------------------------------------------------------------+
|
|
|
17
|
+//| Expert initialization function |
|
|
|
18
|
+//+------------------------------------------------------------------+
|
|
|
19
|
+void foo(int index)
|
|
|
20
|
+ {
|
|
|
21
|
+ if(checkCandle(index) == "Bullish")
|
|
|
22
|
+ {
|
|
|
23
|
+ trend = "uptrend";
|
|
|
24
|
+ double high,low = 0.0;
|
|
|
25
|
+
|
|
|
26
|
+
|
|
|
27
|
+ // to store high and low of the value after the object
|
|
|
28
|
+ high = iHigh(Symbol(),PERIOD_CURRENT,index-1);
|
|
|
29
|
+
|
|
|
30
|
+ //low = iLow(Symbol(),PERIOD_CURRENT,index-1);
|
|
|
31
|
+
|
|
|
32
|
+ for(int i=index - 2 ; i > 0; i--)
|
|
|
33
|
+ {
|
|
|
34
|
+ double high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
|
|
|
35
|
+
|
|
|
36
|
+ //double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
|
|
|
37
|
+
|
|
|
38
|
+ if(high1 > high)
|
|
|
39
|
+ {
|
|
|
40
|
+ high = high1;
|
|
|
41
|
+ int count = (index-1) - i;
|
|
|
42
|
+
|
|
|
43
|
+ Print("count",count);
|
|
|
44
|
+
|
|
|
45
|
+
|
|
|
46
|
+ for(int j=1; j < count; j++)
|
|
|
47
|
+ {
|
|
|
48
|
+
|
|
|
49
|
+ if(checkCandle(index-j) == "Bearish")
|
|
|
50
|
+ {
|
|
|
51
|
+ low = iLow(Symbol(),PERIOD_CURRENT,index-1);
|
|
|
52
|
+ bearish_found = true;
|
|
|
53
|
+ }
|
|
|
54
|
+
|
|
|
55
|
+ }
|
|
|
56
|
+
|
|
|
57
|
+ if(bearish_found == true)
|
|
|
58
|
+ {
|
|
|
59
|
+ double low1;
|
|
|
60
|
+ for(int k=1; k <= count; k++)
|
|
|
61
|
+ {
|
|
|
62
|
+ low1 = iLow(Symbol(),PERIOD_CURRENT,index - k);
|
|
|
63
|
+ if(low1 < low)
|
|
|
64
|
+ {
|
|
|
65
|
+ low = low1;
|
|
|
66
|
+ }
|
|
|
67
|
+ }
|
|
|
68
|
+ bearish_found = false;
|
|
|
69
|
+
|
|
|
70
|
+ }
|
|
|
71
|
+
|
|
|
72
|
+
|
|
|
73
|
+ }
|
|
|
74
|
+
|
|
|
75
|
+
|
|
|
76
|
+ }
|
|
|
77
|
+
|
|
|
78
|
+ Print(" high price is ", high);
|
|
|
79
|
+ Print("low price is ", low);
|
|
|
80
|
+
|
|
|
81
|
+ }
|
|
|
82
|
+
|
|
|
83
|
+ if(checkCandle(index) == "Bearish")
|
|
|
84
|
+ {
|
|
|
85
|
+ trend = "downtrend";
|
|
|
86
|
+ double high,low = 0.0;
|
|
|
87
|
+
|
|
|
88
|
+
|
|
|
89
|
+ // to store high and low of the value after the object
|
|
|
90
|
+ low = iLow(Symbol(),PERIOD_CURRENT,index-1);
|
|
|
91
|
+
|
|
|
92
|
+ //low = iLow(Symbol(),PERIOD_CURRENT,index-1);
|
|
|
93
|
+
|
|
|
94
|
+ for(int i=index - 2 ; i > 0; i--)
|
|
|
95
|
+ {
|
|
|
96
|
+ double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
|
|
|
97
|
+
|
|
|
98
|
+ //double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
|
|
|
99
|
+
|
|
|
100
|
+ if(low1 < low)
|
|
|
101
|
+ {
|
|
|
102
|
+ low = low1;
|
|
|
103
|
+ int count = (index-1) - i;
|
|
|
104
|
+
|
|
|
105
|
+ Print("count",count);
|
|
|
106
|
+
|
|
|
107
|
+
|
|
|
108
|
+ for(int j=1; j < count; j++)
|
|
|
109
|
+ {
|
|
|
110
|
+
|
|
|
111
|
+ if(checkCandle(index-j) == "Bullish")
|
|
|
112
|
+ {
|
|
|
113
|
+ high = iHigh(Symbol(),PERIOD_CURRENT,index-1);
|
|
|
114
|
+ bullish_found = true;
|
|
|
115
|
+ }
|
|
|
116
|
+
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
|
119
|
+ if(bullish_found == true)
|
|
|
120
|
+ {
|
|
|
121
|
+ double high1;
|
|
|
122
|
+ for(int k=1; k <= count; k++)
|
|
|
123
|
+ {
|
|
|
124
|
+ high1 = iHigh(Symbol(),PERIOD_CURRENT,index - k);
|
|
|
125
|
+ if(high1 > high)
|
|
|
126
|
+ {
|
|
|
127
|
+ high = high1;
|
|
|
128
|
+ }
|
|
|
129
|
+ }
|
|
|
130
|
+ bullish_found = false;
|
|
|
131
|
+
|
|
|
132
|
+ }
|
|
|
133
|
+
|
|
|
134
|
+
|
|
|
135
|
+ }
|
|
|
136
|
+
|
|
|
137
|
+
|
|
|
138
|
+ }
|
|
|
139
|
+ Print(" high price is ", high);
|
|
|
140
|
+ Print("low price is ", low);
|
|
|
141
|
+
|
|
|
142
|
+ }
|
|
|
143
|
+
|
|
|
144
|
+ }
|
|
|
145
|
+//+------------------------------------------------------------------+
|
|
|
146
|
+//| |
|
|
|
147
|
+//+------------------------------------------------------------------+
|
|
|
148
|
+int OnInit()
|
|
|
149
|
+ {
|
|
|
150
|
+
|
|
|
151
|
+ //ObjectCreate(0,"line",OBJ_VLINE,0,D'2023.08.01 10:00:27',0);
|
|
|
152
|
+ object_find(object_name);
|
|
|
153
|
+//Print(ObjectFind(0,"line")); // to find the object drawn on the chart
|
|
|
154
|
+
|
|
|
155
|
+ if(object_find(object_name) == true)
|
|
|
156
|
+ {
|
|
|
157
|
+
|
|
|
158
|
+
|
|
|
159
|
+ datetime time_of_candle = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0);
|
|
|
160
|
+ Print("time is " , time_of_candle);
|
|
|
161
|
+
|
|
|
162
|
+ int index = iBarShift(0, PERIOD_CURRENT,time_of_candle, true);
|
|
|
163
|
+ Print("index is " , index);
|
|
|
164
|
+ foo(index);
|
|
|
165
|
+
|
|
|
166
|
+ }
|
|
|
167
|
+ else
|
|
|
168
|
+ {
|
|
|
169
|
+ Print("Object Not Found");
|
|
|
170
|
+ }
|
|
|
171
|
+
|
|
|
172
|
+
|
|
|
173
|
+
|
|
|
174
|
+ return(INIT_SUCCEEDED);
|
|
|
175
|
+ }
|
|
|
176
|
+//+------------------------------------------------------------------+
|
|
|
177
|
+//| Expert deinitialization function |
|
|
|
178
|
+//+------------------------------------------------------------------+
|
|
|
179
|
+void OnDeinit(const int reason)
|
|
|
180
|
+ {
|
|
|
181
|
+//---
|
|
|
182
|
+
|
|
|
183
|
+ }
|
|
|
184
|
+//+------------------------------------------------------------------+
|
|
|
185
|
+//| Expert tick function |
|
|
|
186
|
+//+------------------------------------------------------------------+
|
|
|
187
|
+void OnTick()
|
|
|
188
|
+ {
|
|
|
189
|
+
|
|
|
190
|
+
|
|
|
191
|
+
|
|
|
192
|
+ }
|
|
|
193
|
+
|
|
|
194
|
+
|
|
|
195
|
+//+------------------------------------------------------------------+
|
|
|
196
|
+//| |
|
|
|
197
|
+//+------------------------------------------------------------------+
|
|
|
198
|
+bool object_find(string obj) // to find object placed by user in the chart
|
|
|
199
|
+ {
|
|
|
200
|
+ if(ObjectFind(0,obj) >= 0)
|
|
|
201
|
+ {
|
|
|
202
|
+ return true;
|
|
|
203
|
+ }
|
|
|
204
|
+ return false;
|
|
|
205
|
+
|
|
|
206
|
+ }
|
|
|
207
|
+//+------------------------------------------------------------------+
|
|
|
208
|
+//| |
|
|
|
209
|
+//+------------------------------------------------------------------+
|
|
|
210
|
+string checkCandle(int i) // to check the candle is bullish or bearish
|
|
|
211
|
+ {
|
|
|
212
|
+ double close = iClose(Symbol(),PERIOD_CURRENT,i);
|
|
|
213
|
+ double open = iOpen(Symbol(),PERIOD_CURRENT,i);
|
|
|
214
|
+
|
|
|
215
|
+ if(close > open)
|
|
|
216
|
+ {
|
|
|
217
|
+ return "Bullish";
|
|
|
218
|
+ }
|
|
|
219
|
+ else
|
|
|
220
|
+ if(close < open)
|
|
|
221
|
+ {
|
|
|
222
|
+ return "Bearish";
|
|
|
223
|
+ }
|
|
|
224
|
+ return "empty";
|
|
|
225
|
+ }
|
|
|
226
|
+//+------------------------------------------------------------------+
|