Przeglądaj źródła

Ticket: 4436 Complete

Huzaifa-MQLDev 9 miesięcy temu
rodzic
commit
c9df2c5590
2 zmienionych plików z 207 dodań i 31 usunięć
  1. BIN
      valFvgMt5.ex5
  2. 207 31
      valFvgMt5.mq5

BIN
valFvgMt5.ex5


+ 207 - 31
valFvgMt5.mq5

@@ -9,6 +9,8 @@
9 9
 #include <Trade\Trade.mqh>
10 10
 CTrade  trade;
11 11
 #resource "\\Indicators\\SequentialVolumeProfileWithFVG.ex5"
12
+#define previousBullish "previousBullish"
13
+#define previousBearish "previousBearish"
12 14
 //+------------------------------------------------------------------+
13 15
 //| Expert initialization function                                   |
14 16
 //+------------------------------------------------------------------+
@@ -20,15 +22,21 @@ enum lotcalculator
20 22
   };
21 23
 enum tp_options
22 24
   {
23
-   zone_based,
24
-   risk_reward_based,
25
+   zone_based,          // Zone Based Tp
26
+   risk_reward_based,   // Risk to Reward
27
+  };
28
+enum sl_options
29
+  {
30
+   zone_based_sl,       // Zone Based Sl
31
+   fvg_third,           // FVG third candle high and low + buffer
25 32
   };
26 33
 
27 34
 sinput       string                  string_0                   = "<><><><><><> General SETTINGS <><><><><><>";   //__
28 35
 input        int                     magic_no                   = 333;             // Magic no
29 36
 input        tp_options              select_tp                  = zone_based;      // Select Tp
30
-input        double                  stoploss                   = 10;              // Fixed Stop Loss in Pips
31
-input        double                  takeprofit                 = 10;              // Fixed Take Profit in Pips
37
+input        sl_options              select_sl                  = zone_based_sl;   // Select Sl
38
+input        double                  stoploss                   = 4;               // FVG Third High/Low Stop Loss in Buffer
39
+input        double                  tpMultiplier               = 2;               // Take Profit Multiplier Risk to Reward
32 40
 
33 41
 input        string                  string_0_3                 = "<><><><><><> Lot Management<><><><><><>";   //__
34 42
 input        double                  lot_size                   = 0.1;             // Lot Size
@@ -63,6 +71,10 @@ input        color                   BearishFVGColor            = clrDeepPink;
63 71
 input        double                  MinFVGSize                 = 0.0;              // Minimum FVG size in points (0 = any size)
64 72
 input        int                     MaxBarsBack                = 300;              // How many bars to look back for FVG
65 73
 
74
+input       string                fvg_setting                = "<><><><><> FVG Color Setting <><><><><>";             //_
75
+input       color                 bullish_color              = clrAqua;     // Bullish FVG Color
76
+input       color                 bearish_color              = clrYellow;   // Bearish FVG Color
77
+
66 78
 
67 79
 // Global Variables
68 80
 int sequential_handler;
@@ -130,33 +142,42 @@ void OnTick()
130 142
    double absHigh = lines("AbsHigh");
131 143
    double absLow = lines("AbsLow");
132 144
 
133
-
134
-
135
-
136 145
 // Print("Val: ", val, "  Vah: ", vah, "  AbsHigh: ", absHigh, "  AbsLow: ", absLow);
137 146
    double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
138 147
    double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
139 148
    timeConversion();
140
-// Comment(" Start Time: ", startTradingTime, " Close time: ", endTradingTime);
149
+
141 150
    if((EnableTimeFilter && TimeCurrent() >= startTradingTime && TimeCurrent() < endTradingTime) ||  !EnableTimeFilter)
142 151
      {
143
-      if(todayTradesCount(DEAL_TYPE_BUY) == 0)
152
+      if(newBar())
144 153
         {
145
-         if(Ask < val && Ask > absLow)
154
+         string gapCreated = fvg_gap();
155
+         if(todayTradesCount(DEAL_TYPE_BUY) == 0)
146 156
            {
147
-            //if(fvgOverLap("VProfFVG_up_", val))
157
+            if(gapCreated == previousBullish)
148 158
               {
149
-               placeBuyTrade();
159
+               double open_2 = iOpen(Symbol(), PERIOD_CURRENT, 2);
160
+               double close_2 = iClose(Symbol(), PERIOD_CURRENT, 2);
161
+               double upper_price = MathMax(open_2, close_2);
162
+               double lower_price = MathMin(open_2, close_2);
163
+               if(((upper_price > val) && (lower_price < val)) || ((upper_price < val) && (lower_price < val)))
164
+                 {
165
+                  placeBuyTrade();
166
+                 }
150 167
               }
151 168
            }
152
-        }
153
-      if(todayTradesCount(DEAL_TYPE_SELL) == 0)
154
-        {
155
-         if(Bid > vah && Bid < absHigh)
169
+         if(todayTradesCount(DEAL_TYPE_SELL) == 0)
156 170
            {
157
-            //if(fvgOverLap("VProfFVG_dn_", vah))
171
+            if(gapCreated == previousBearish)
158 172
               {
159
-               placeSellTrade();
173
+               double open_2 = iOpen(Symbol(), PERIOD_CURRENT, 2);
174
+               double close_2 = iClose(Symbol(), PERIOD_CURRENT, 2);
175
+               double upper_price = MathMax(open_2, close_2);
176
+               double lower_price = MathMin(open_2, close_2);  
177
+               if(((upper_price > vah) && (lower_price < vah)) || ((upper_price > vah) && (lower_price > vah)))
178
+                 {
179
+                  placeSellTrade();
180
+                 }
160 181
               }
161 182
            }
162 183
         }
@@ -278,25 +299,38 @@ void placeBuyTrade()
278 299
    double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
279 300
    double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
280 301
 
281
-   if(stoploss != 0)
302
+//if(stoploss != 0)
303
+//  {
304
+//   buySL = Ask - (stoploss * 10 * Point());
305
+//  }
306
+   if(select_sl == zone_based_sl)
282 307
      {
283
-      buySL = Ask - (stoploss * 10 * Point());
308
+      buySL = lines("AbsLow");
309
+     }
310
+   if(select_sl == fvg_third)
311
+     {
312
+      //if(stoploss != 0)
313
+        {
314
+         buySL = iLow(Symbol(), PERIOD_CURRENT, 3) - (stoploss * 10 * Point());
315
+        }
284 316
      }
285 317
    if(select_tp == zone_based)
286 318
      {
287 319
       buyTp = lines("VAH");
288 320
      }
289
-   //if(select_tp == risk_reward_based)
290
-   //  {
291
-   //distance = ((price - buySl) / Point());
292
-   //distance = (distance * tpMultiplier);
293
-   //  }
321
+   if(select_tp == risk_reward_based)
322
+     {
323
+      double distance = MathAbs((Ask - buySL) / Point());
324
+      distance  = (distance * tpMultiplier);
325
+      buyTp    = Ask + (distance * Point());
326
+     }
294 327
 //if(takeprofit != 0)
295 328
 //  {
296 329
 //   buyTp = Ask + (takeprofit * 10 * Point());
297 330
 //  }
298 331
 
299
-   if(trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,getlot(stoploss * 10),Ask,buySL,buyTp,"Buy Trade Placed"))
332
+   double distance_sl = MathAbs((Ask - buySL) / Point());
333
+   if(trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,getlot(distance_sl),Ask,buySL,buyTp,"Buy Trade Placed"))
300 334
      {
301 335
       Print("Buy Trade Placed: ",trade.ResultOrder());
302 336
      }
@@ -316,16 +350,40 @@ void placeSellTrade()
316 350
    double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
317 351
    double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
318 352
 
319
-   if(stoploss != 0)
353
+//if(stoploss != 0)
354
+//  {
355
+//   sellSL = Bid + (stoploss * 10 * Point());
356
+//  }
357
+   if(select_sl == zone_based_sl)
358
+     {
359
+      sellSL = lines("AbsHigh");
360
+     }
361
+
362
+   if(select_sl == fvg_third)
363
+     {
364
+      //if(stoploss != 0)
365
+        {
366
+         sellSL = iHigh(Symbol(), PERIOD_CURRENT, 3) + (stoploss * 10 * Point());
367
+        }
368
+     }
369
+//if(takeprofit != 0)
370
+//  {
371
+//   sellTp = Bid - (takeprofit * 10 * Point());
372
+//  }
373
+
374
+   if(select_tp == zone_based)
320 375
      {
321
-      sellSL = Bid + (stoploss * 10 * Point());
376
+      sellTp = lines("VAL");
322 377
      }
323
-   if(takeprofit != 0)
378
+   if(select_tp == risk_reward_based)
324 379
      {
325
-      sellTp = Bid - (takeprofit * 10 * Point());
380
+      double distance = MathAbs((Bid - sellSL) / Point());
381
+      distance  = (distance * tpMultiplier);
382
+      sellTp    = Bid - (distance * Point());
326 383
      }
327 384
 
328
-   if(trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,getlot(stoploss * 10),Bid,sellSL,sellTp,"Sell Trade Placed"))
385
+   double distance_sl = MathAbs((Bid - sellSL) / Point());
386
+   if(trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,getlot(distance_sl),Bid,sellSL,sellTp,"Sell Trade Placed"))
329 387
      {
330 388
       Print("Sell Trade PLaced: ",trade.ResultOrder());
331 389
      }
@@ -386,4 +444,122 @@ double getlot(double stop_loss)
386 444
 //+------------------------------------------------------------------+
387 445
 //|                                                                  |
388 446
 //+------------------------------------------------------------------+
447
+string check_bearish_bullish()
448
+  {
449
+
450
+   int bullishCount = 0;
451
+   int bearishCount = 0;
452
+
453
+   for(int i = 1; i <= 3; i++)
454
+     {
455
+      double open = iOpen(Symbol(), PERIOD_CURRENT, i);
456
+      double close = iClose(Symbol(), PERIOD_CURRENT, i);
457
+
458
+      if(close > open)
459
+        {
460
+         bullishCount++;
461
+        }
462
+      else
463
+         if(close < open)
464
+           {
465
+            bearishCount++;
466
+           }
467
+     }
468
+
469
+// Output the result
470
+   if(bullishCount > bearishCount)
471
+     {
472
+      return previousBullish;
473
+     }
474
+   else
475
+      if(bearishCount > bullishCount)
476
+        {
477
+         return previousBearish;
478
+        }
479
+      else
480
+        {
481
+         return NULL;
482
+        }
483
+
484
+  }
485
+//+------------------------------------------------------------------+
486
+//|                                                                  |
487
+//+------------------------------------------------------------------+
488
+string fvg_gap()
489
+  {
490
+//Print("Imbalance: ");
491
+   if(check_bearish_bullish() == previousBullish)
492
+     {
493
+      if(iLow(Symbol(), PERIOD_CURRENT, 1) > iHigh(Symbol(), PERIOD_CURRENT, 3))
494
+        {
495
+         //double fvg_body = imbalance_gap * 10; // FVG Body
496
+         double fvg_size = MathAbs((iLow(Symbol(), PERIOD_CURRENT, 1) - iHigh(Symbol(), PERIOD_CURRENT, 3))/Point());
497
+         //fvg_size = fvg_size * 10 * Point();
498
+
499
+         //if(fvg_size > fvg_body)
500
+           {
501
+            if(!ObjectCreate(0, "Buy" + (string) TimeCurrent(), OBJ_RECTANGLE, 0, iTime(Symbol(), PERIOD_CURRENT, 3), iHigh(Symbol(), PERIOD_CURRENT, 3), iTime(Symbol(), PERIOD_CURRENT, 1), iLow(Symbol(), PERIOD_CURRENT, 1)))
502
+              {
503
+               Print(" Error in Drawing Buy Rectangle : "," rectangle "+(string)iTime(Symbol(),PERIOD_CURRENT,1)," ",GetLastError());
504
+              }
505
+            else
506
+              {
507
+               ObjectSetInteger(0, "Buy"+ (string) TimeCurrent(), OBJPROP_COLOR, bullish_color);
508
+               ObjectSetInteger(0,"Buy"+ (string) TimeCurrent(), OBJPROP_FILL, true);
509
+               //ObjectSetInteger(0,"Range",OBJPROP_BACK,false);
510
+               Print("Bullish Fvg Body Size: ", fvg_size, " Name: ", "Buy" + (string) TimeCurrent());
511
+               return previousBullish;
512
+              }
513
+           }
514
+        }
515
+     }
516
+   if(check_bearish_bullish() == previousBearish)
517
+     {
518
+      if(iLow(Symbol(), PERIOD_CURRENT, 3) > iHigh(Symbol(), PERIOD_CURRENT, 1))
519
+        {
520
+         //double fvg_body = imbalance_gap * 10; // FVG Body
521
+         double fvg_size = MathAbs((iLow(Symbol(), PERIOD_CURRENT, 3) - iHigh(Symbol(), PERIOD_CURRENT, 1))/Point());
522
+         //fvg_size = fvg_size * 10 * Point();
523
+
524
+         //if(fvg_size > fvg_body)
525
+           {
526
+
527
+            if(!ObjectCreate(0, "Sell" + (string) TimeCurrent(), OBJ_RECTANGLE, 0, iTime(Symbol(), PERIOD_CURRENT, 3), iLow(Symbol(), PERIOD_CURRENT, 3), iTime(Symbol(), PERIOD_CURRENT, 1), iHigh(Symbol(), PERIOD_CURRENT, 1)))
528
+              {
529
+               Print(" Error in Drawing Sell Rectangle : "," rectangle "+(string)iTime(Symbol(),PERIOD_CURRENT,1)," ",GetLastError());
530
+              }
531
+            else
532
+              {
533
+               ObjectSetInteger(0, "Sell"+ (string) TimeCurrent(), OBJPROP_COLOR, bearish_color);
534
+               ObjectSetInteger(0,"Sell"+ (string) TimeCurrent(), OBJPROP_FILL, true);
535
+               //ObjectSetInteger(0,"Range",OBJPROP_BACK,false);
536
+               Print("Bearish Fvg Body Size: ", fvg_size, " Name: ", "Buy" + (string) TimeCurrent());
537
+               return previousBearish;
538
+              }
539
+           }
540
+        }
541
+     }
542
+   return NULL;
543
+  }
544
+//+------------------------------------------------------------------+
545
+//|                                                                  |
546
+//+------------------------------------------------------------------+
547
+bool newBar()
548
+  {
549
+   static datetime lastbar;
550
+   datetime curbar = iTime(Symbol(), PERIOD_CURRENT, 0);
551
+   if(lastbar != curbar)
552
+     {
553
+      lastbar = curbar;
554
+      Print("<<<<<<<<>>>>>>>>>>>>New Bar Time V1.1. ", curbar, "<<<<<<<<>>>>>>>>>>>>");
555
+      return (true);
556
+     }
557
+   else
558
+     {
559
+      return (false);
560
+     }
561
+  }
562
+//+------------------------------------------------------------------+
563
+//|                                                                  |
564
+//+------------------------------------------------------------------+
389 565
 //+------------------------------------------------------------------+