Huzaifa-MQLDev 9 місяців тому
батько
коміт
f0ab3268f0
2 змінених файлів з 38 додано та 6 видалено
  1. BIN
      valFvgMt5.ex5
  2. 38 6
      valFvgMt5.mq5

+ 38 - 6
valFvgMt5.mq5

@@ -11,6 +11,8 @@ CTrade  trade;
11
 #resource "\\Indicators\\SequentialVolumeProfileWithFVG.ex5"
11
 #resource "\\Indicators\\SequentialVolumeProfileWithFVG.ex5"
12
 #define previousBullish "previousBullish"
12
 #define previousBullish "previousBullish"
13
 #define previousBearish "previousBearish"
13
 #define previousBearish "previousBearish"
14
+#define buy "buy"
15
+#define sell "sell"
14
 //+------------------------------------------------------------------+
16
 //+------------------------------------------------------------------+
15
 //| Expert initialization function                                   |
17
 //| Expert initialization function                                   |
16
 //+------------------------------------------------------------------+
18
 //+------------------------------------------------------------------+
@@ -171,11 +173,14 @@ void OnTick()
171
                double close_2 = iClose(Symbol(), PERIOD_CURRENT, 2);
173
                double close_2 = iClose(Symbol(), PERIOD_CURRENT, 2);
172
                double upper_price = MathMax(open_2, close_2);
174
                double upper_price = MathMax(open_2, close_2);
173
                double lower_price = MathMin(open_2, close_2);
175
                double lower_price = MathMin(open_2, close_2);
174
-               if(((upper_price < absHigh) && (lower_price < absHigh)))
176
+               if(((upper_price > absLow) && (lower_price > absLow)))
175
                   if(((upper_price > val) && (lower_price < val)) || ((upper_price < val) && (lower_price < val)))
177
                   if(((upper_price > val) && (lower_price < val)) || ((upper_price < val) && (lower_price < val)))
176
                     {
178
                     {
177
-                     Print("Buy Trade. Val: ", val, "  Vah: ", vah, "  AbsHigh: ", absHigh, "  AbsLow: ", absLow);
178
-                     placeBuyTrade();
179
+                     if(candleNotTouchingHigh(absLow, buy))
180
+                       {
181
+                        Print("Buy Trade. Val: ", val, "  Vah: ", vah, "  AbsHigh: ", absHigh, "  AbsLow: ", absLow);
182
+                        placeBuyTrade();
183
+                       }
179
                     }
184
                     }
180
               }
185
               }
181
            }
186
            }
@@ -187,11 +192,14 @@ void OnTick()
187
                double close_2 = iClose(Symbol(), PERIOD_CURRENT, 2);
192
                double close_2 = iClose(Symbol(), PERIOD_CURRENT, 2);
188
                double upper_price = MathMax(open_2, close_2);
193
                double upper_price = MathMax(open_2, close_2);
189
                double lower_price = MathMin(open_2, close_2);
194
                double lower_price = MathMin(open_2, close_2);
190
-               if(((upper_price > absLow) && (lower_price > absLow)))
195
+               if(((upper_price < absHigh) && (lower_price < absHigh)))
191
                   if(((upper_price > vah) && (lower_price < vah)) || ((upper_price > vah) && (lower_price > vah)))
196
                   if(((upper_price > vah) && (lower_price < vah)) || ((upper_price > vah) && (lower_price > vah)))
192
                     {
197
                     {
193
-                     Print("Sell Trade. Val: ", val, "  Vah: ", vah, "  AbsHigh: ", absHigh, "  AbsLow: ", absLow);
194
-                     placeSellTrade();
198
+                     if(candleNotTouchingHigh(absHigh, sell))
199
+                       {
200
+                        Print("Sell Trade. Val: ", val, "  Vah: ", vah, "  AbsHigh: ", absHigh, "  AbsLow: ", absLow);
201
+                        placeSellTrade();
202
+                       }
195
                     }
203
                     }
196
               }
204
               }
197
            }
205
            }
@@ -577,4 +585,28 @@ bool newBar()
577
 //+------------------------------------------------------------------+
585
 //+------------------------------------------------------------------+
578
 //|                                                                  |
586
 //|                                                                  |
579
 //+------------------------------------------------------------------+
587
 //+------------------------------------------------------------------+
588
+bool candleNotTouchingHigh(double priceToBreak, string calledBy)
589
+  {
590
+   int index = iBarShift(Symbol(), PERIOD_CURRENT, iTime(Symbol(), PERIOD_D1, 0), false);
591
+   for(int i = 0; i <= index; i++)
592
+     {
593
+      if(calledBy == "buy")
594
+        {
595
+         double low = iLow(Symbol(), PERIOD_CURRENT, i);
596
+         if(low < priceToBreak)
597
+            return false;
598
+        }
599
+      else
600
+         if(calledBy == "sell")
601
+           {
602
+            double high = iHigh(Symbol(), PERIOD_CURRENT, i);
603
+            if(high > priceToBreak)
604
+               return false;
605
+           }
606
+     }
607
+   return true;
608
+  }
609
+//+------------------------------------------------------------------+
610
+//|                                                                  |
611
+//+------------------------------------------------------------------+
580
 //+------------------------------------------------------------------+
612
 //+------------------------------------------------------------------+