ソースを参照

Ticket: 4436 Entry and Indicator Conditions

Huzaifa-MQLDev 9 ヶ月 前
コミット
afea98d7f0
共有2 個のファイルを変更した389 個の追加0 個の削除を含む
  1. BIN
      valFvgMt5.ex5
  2. 389 0
      valFvgMt5.mq5

BIN
valFvgMt5.ex5


+ 389 - 0
valFvgMt5.mq5

@@ -0,0 +1,389 @@
1
+//+------------------------------------------------------------------+
2
+//|                                                    valFvgMt5.mq5 |
3
+//|                                  Copyright 2025, MQL Development |
4
+//|                                  https://www.mqldevelopment.com/ |
5
+//+------------------------------------------------------------------+
6
+#property copyright "Copyright 2025, MQL Development"
7
+#property link      "https://www.mqldevelopment.com/"
8
+#property version   "1.00"
9
+#include <Trade\Trade.mqh>
10
+CTrade  trade;
11
+#resource "\\Indicators\\SequentialVolumeProfileWithFVG.ex5"
12
+//+------------------------------------------------------------------+
13
+//| Expert initialization function                                   |
14
+//+------------------------------------------------------------------+
15
+
16
+enum lotcalculator
17
+  {
18
+   fix, //Fixed Lot Size
19
+   rsk, //Risk Percentage
20
+  };
21
+enum tp_options
22
+  {
23
+   zone_based,
24
+   risk_reward_based,
25
+  };
26
+
27
+sinput       string                  string_0                   = "<><><><><><> General SETTINGS <><><><><><>";   //__
28
+input        int                     magic_no                   = 333;             // Magic no
29
+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
32
+
33
+input        string                  string_0_3                 = "<><><><><><> Lot Management<><><><><><>";   //__
34
+input        double                  lot_size                   = 0.1;             // Lot Size
35
+input        lotcalculator           lot_calculator             = fix;             // Lot Size Calculator
36
+input        double                  risk                       = 0.1;             // Risk in Percentage %
37
+
38
+input       string                time_setting               = "<><><><><> Time Filter Settings <><><><><>";             //_
39
+input       bool                  EnableTimeFilter           = false;         // Enable Time Filter
40
+input       string                startTime                  = "03:00";       // Start Time Session
41
+input       string                endTime                    = "09:00";       // End Time Session
42
+
43
+sinput       string                  string_1                   = "<><><><><><> Sequential Volume Indicator SETTINGS <><><><><><>";   //__
44
+input        int                     BinsCount                  = 100;              // Number of price bins
45
+input        double                  ValueAreaPercent           = 70;               // Value Area percentage (70% default)
46
+input        color                   VALColor                   = clrDarkBlue;      // Value Area Low color
47
+input        color                   VAHColor                   = clrDarkBlue;      // Value Area High color
48
+input        color                   AbsLowColor                = clrBlack;         // Absolute Low color
49
+input        color                   AbsHighColor               = clrBlack;         // Absolute High color
50
+input        color                   TimeLineColor              = clrRed;           // Time marker line color
51
+input        int                     LineWidth                  = 2;                // Line width for all value lines
52
+input        int                     TimeLineWidth              = 2;                // Line width for time marker lines
53
+input        int                     MaxDaysBack                = 30;               // Maximum number of trading days to look back
54
+input        ENUM_LINE_STYLE         VALStyle                   = STYLE_SOLID;      // Value Area Low line style
55
+input        ENUM_LINE_STYLE         VAHStyle                   = STYLE_SOLID;      // Value Area High line style
56
+input        ENUM_LINE_STYLE         AbsLowStyle                = STYLE_SOLID;      // Absolute Low line style
57
+input        ENUM_LINE_STYLE         AbsHighStyle               = STYLE_SOLID;      // Absolute High line style
58
+input        bool                    ShowLabels                 = true;             // Show price labels
59
+input        bool                    ShowComment                = true;             // Show comment with most recent levels
60
+input        bool                    ShowFVG                    = true;             // Enable Fair Value Gap detection
61
+input        color                   BullishFVGColor            = clrLime;          // Bullish FVG color
62
+input        color                   BearishFVGColor            = clrDeepPink;      // Bearish FVG color
63
+input        double                  MinFVGSize                 = 0.0;              // Minimum FVG size in points (0 = any size)
64
+input        int                     MaxBarsBack                = 300;              // How many bars to look back for FVG
65
+
66
+
67
+// Global Variables
68
+int sequential_handler;
69
+datetime  startTradingTime = 0, endTradingTime = 0;
70
+string sep  =  ":";                // A separator as a character
71
+ushort u_sep;                      // The code of the separator character
72
+string result1[];
73
+//+------------------------------------------------------------------+
74
+//|                                                                  |
75
+//+------------------------------------------------------------------+
76
+int OnInit()
77
+  {
78
+//---
79
+   trade.SetExpertMagicNumber(magic_no);
80
+   trade.SetDeviationInPoints(10);
81
+   trade.SetTypeFilling(ORDER_FILLING_IOC);
82
+   trade.LogLevel(LOG_LEVEL_ALL);
83
+   trade.SetAsyncMode(false);
84
+
85
+   sequential_handler = iCustom(Symbol(), PERIOD_CURRENT, "::Indicators\\SequentialVolumeProfileWithFVG.ex5",
86
+                                BinsCount,
87
+                                ValueAreaPercent,
88
+                                VALColor,
89
+                                VAHColor,
90
+                                AbsLowColor,
91
+                                AbsHighColor,
92
+                                TimeLineColor,
93
+                                LineWidth,
94
+                                TimeLineWidth,
95
+                                MaxDaysBack,
96
+                                VALStyle,
97
+                                VAHStyle,
98
+                                AbsLowStyle,
99
+                                AbsHighStyle,
100
+                                ShowLabels,
101
+                                ShowComment,
102
+                                ShowFVG,
103
+                                BullishFVGColor,
104
+                                BearishFVGColor,
105
+                                MinFVGSize,
106
+                                MaxBarsBack);
107
+
108
+
109
+//---
110
+   return(INIT_SUCCEEDED);
111
+  }
112
+//+------------------------------------------------------------------+
113
+//| Expert deinitialization function                                 |
114
+//+------------------------------------------------------------------+
115
+void OnDeinit(const int reason)
116
+  {
117
+//---
118
+
119
+  }
120
+//+------------------------------------------------------------------+
121
+//| Expert tick function                                             |
122
+//+------------------------------------------------------------------+
123
+void OnTick()
124
+  {
125
+//---
126
+   double values[];
127
+   CopyBuffer(sequential_handler,0,0,3,values);
128
+   double val = lines("VAL");
129
+   double vah = lines("VAH");
130
+   double absHigh = lines("AbsHigh");
131
+   double absLow = lines("AbsLow");
132
+
133
+
134
+
135
+
136
+// Print("Val: ", val, "  Vah: ", vah, "  AbsHigh: ", absHigh, "  AbsLow: ", absLow);
137
+   double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
138
+   double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
139
+   timeConversion();
140
+// Comment(" Start Time: ", startTradingTime, " Close time: ", endTradingTime);
141
+   if((EnableTimeFilter && TimeCurrent() >= startTradingTime && TimeCurrent() < endTradingTime) ||  !EnableTimeFilter)
142
+     {
143
+      if(todayTradesCount(DEAL_TYPE_BUY) == 0)
144
+        {
145
+         if(Ask < val && Ask > absLow)
146
+           {
147
+            //if(fvgOverLap("VProfFVG_up_", val))
148
+              {
149
+               placeBuyTrade();
150
+              }
151
+           }
152
+        }
153
+      if(todayTradesCount(DEAL_TYPE_SELL) == 0)
154
+        {
155
+         if(Bid > vah && Bid < absHigh)
156
+           {
157
+            //if(fvgOverLap("VProfFVG_dn_", vah))
158
+              {
159
+               placeSellTrade();
160
+              }
161
+           }
162
+        }
163
+     }
164
+  }
165
+//+------------------------------------------------------------------+
166
+//|                                                                  |
167
+//+------------------------------------------------------------------+
168
+void timeConversion()
169
+  {
170
+   MqlDateTime date, date1;
171
+
172
+   TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date);
173
+   u_sep=StringGetCharacter(sep,0);
174
+   StringSplit(startTime,u_sep,result1);
175
+   date.hour = (int)StringToInteger(result1[0]);
176
+   date.min = (int)StringToInteger(result1[1]);
177
+   startTradingTime = StructToTime(date);
178
+
179
+   TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date1);
180
+   StringSplit(endTime,u_sep,result1);
181
+   date.hour = (int)StringToInteger(result1[0]);
182
+   date.min = (int)StringToInteger(result1[1]);
183
+   endTradingTime = StructToTime(date);
184
+  }
185
+//+------------------------------------------------------------------+
186
+//|                                                                  |
187
+//+------------------------------------------------------------------+
188
+double lines(string name)
189
+  {
190
+   datetime todayStart = iTime(Symbol(), PERIOD_D1, 0);
191
+   datetime nextDayStart = todayStart + 86400;
192
+   datetime latestObjectTime = 0;
193
+   for(int i = 0; i < ObjectsTotal(0, 0, OBJ_TREND); i++)
194
+     {
195
+      string object_name = ObjectName(0, i, 0, OBJ_TREND);
196
+      datetime object_time = (datetime)ObjectGetInteger(0, object_name, OBJPROP_TIME, 1);
197
+
198
+      if(object_time > todayStart && object_time < nextDayStart)
199
+        {
200
+         // Print(" Object Name: ", object_name, " Day Start Time: ", todayStart, " Next Day Time: ", nextDayStart);
201
+         if((StringFind(object_name, name) != -1))
202
+           {
203
+            double objectPrice = ObjectGetDouble(0, object_name, OBJPROP_PRICE, 0);
204
+            return objectPrice;
205
+           }
206
+        }
207
+     }
208
+   return 0;
209
+  }
210
+//+------------------------------------------------------------------+
211
+//|                                                                  |
212
+//+------------------------------------------------------------------+
213
+bool fvgOverLap(string name, double price_overlap)
214
+  {
215
+   datetime todayStart = iTime(Symbol(), PERIOD_D1, 0);
216
+   datetime nextDayStart = todayStart + 86400;
217
+   for(int i = 0; i < ObjectsTotal(0, 0, OBJ_RECTANGLE); i++)
218
+     {
219
+      string object_name = ObjectName(0, i, 0, OBJ_RECTANGLE);
220
+      datetime object_time1 = (datetime)ObjectGetInteger(0, object_name, OBJPROP_TIME, 1);
221
+      datetime object_time0 = (datetime)ObjectGetInteger(0, object_name, OBJPROP_TIME, 0);
222
+      double object_price0  = ObjectGetDouble(0, object_name, OBJPROP_PRICE, 0);
223
+      double object_price1  = ObjectGetDouble(0, object_name, OBJPROP_PRICE, 1);
224
+
225
+      if(object_time1 > todayStart && object_time1 < nextDayStart)
226
+        {
227
+         if((StringFind(object_name, name) != -1))
228
+           {
229
+            double fvg_top = MathMax(object_price0, object_price1);
230
+            double fvg_bottom = MathMin(object_price0, object_price1);
231
+            if(fvg_top > price_overlap && fvg_bottom < price_overlap)
232
+              {
233
+               Print(" Called By: (", name, ") Object Name: ", object_name,
234
+                     " | Time 0: ", TimeToString(object_time0), " | Price 0: ", object_price0,
235
+                     " | Time 1: ", TimeToString(object_time1), " | Price 0: ", object_price0, " | Price 1: ", object_price1, " | \n FVG Top: ", fvg_top, " | FVG Bottom: ", fvg_bottom);
236
+               return true;
237
+              }
238
+           }
239
+        }
240
+     }
241
+   return false;
242
+  }
243
+//+------------------------------------------------------------------+
244
+//|                                                                  |
245
+//+------------------------------------------------------------------+
246
+int todayTradesCount(ENUM_DEAL_TYPE dealType)
247
+  {
248
+
249
+   int count = 0;
250
+   ulong ticket_deal_Out=0, ticket_deal_In = 0;
251
+   if(HistorySelect(iTime(Symbol(),PERIOD_D1,0), TimeCurrent()))
252
+     {
253
+      int total = HistoryDealsTotal();
254
+      for(int i = total-1; i >= 0 ; i--)
255
+        {
256
+         ticket_deal_In = HistoryDealGetTicket(i);
257
+         if((HistoryDealGetInteger(ticket_deal_In,DEAL_MAGIC) == magic_no) && HistoryDealGetInteger(ticket_deal_In,DEAL_ENTRY) == DEAL_ENTRY_IN
258
+            && HistoryDealGetString(ticket_deal_In,DEAL_SYMBOL) == Symbol()) // here is the problem solved after break
259
+           {
260
+            if(HistoryDealGetInteger(ticket_deal_In, DEAL_TYPE) == dealType)
261
+              {
262
+               count++;
263
+              }
264
+           }
265
+        }
266
+     }
267
+
268
+   return count;
269
+  }
270
+//+------------------------------------------------------------------+
271
+//|                                                                  |
272
+//+------------------------------------------------------------------+
273
+void placeBuyTrade()
274
+  {
275
+
276
+   double buySL = 0, buyTp=0;
277
+//openPrice = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
278
+   double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
279
+   double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
280
+
281
+   if(stoploss != 0)
282
+     {
283
+      buySL = Ask - (stoploss * 10 * Point());
284
+     }
285
+   if(select_tp == zone_based)
286
+     {
287
+      buyTp = lines("VAH");
288
+     }
289
+   //if(select_tp == risk_reward_based)
290
+   //  {
291
+   //distance = ((price - buySl) / Point());
292
+   //distance = (distance * tpMultiplier);
293
+   //  }
294
+//if(takeprofit != 0)
295
+//  {
296
+//   buyTp = Ask + (takeprofit * 10 * Point());
297
+//  }
298
+
299
+   if(trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,getlot(stoploss * 10),Ask,buySL,buyTp,"Buy Trade Placed"))
300
+     {
301
+      Print("Buy Trade Placed: ",trade.ResultOrder());
302
+     }
303
+   else
304
+     {
305
+      Print("Error in placing Buy: "+Symbol()+"  ",GetLastError());
306
+     }
307
+  }
308
+//+------------------------------------------------------------------+
309
+//|                                                                  |
310
+//+------------------------------------------------------------------+
311
+void placeSellTrade()
312
+  {
313
+
314
+   double sellSL = 0, sellTp = 0;
315
+//openPrice = SymbolInfoDouble(Symbol(),SYMBOL_BID);
316
+   double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
317
+   double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
318
+
319
+   if(stoploss != 0)
320
+     {
321
+      sellSL = Bid + (stoploss * 10 * Point());
322
+     }
323
+   if(takeprofit != 0)
324
+     {
325
+      sellTp = Bid - (takeprofit * 10 * Point());
326
+     }
327
+
328
+   if(trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,getlot(stoploss * 10),Bid,sellSL,sellTp,"Sell Trade Placed"))
329
+     {
330
+      Print("Sell Trade PLaced: ",trade.ResultOrder());
331
+     }
332
+   else
333
+     {
334
+      Print("Error in placing Sell: "+Symbol()+"  ",GetLastError());
335
+     }
336
+
337
+  }
338
+//+------------------------------------------------------------------+
339
+//|                                                                  |
340
+//+------------------------------------------------------------------+
341
+double getlot(double stop_loss)
342
+  {
343
+   Print("Tick Value: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE));
344
+   Print("Tick Size: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE));
345
+   double modeTickV=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)
346
+                    ,modeTickS=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE);
347
+// Print("Pip value: ", NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point))*10),2));
348
+   double pipvalue = NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point()))*10),2);
349
+// pipvalue=NormalizeDouble((modeTickV/modeTickS/Point()),)
350
+// pipvalue=
351
+   pipvalue = pipvalue / 10;
352
+   double lotSize = lot_size;
353
+   if(lot_calculator==rsk) //calculating risk
354
+     {
355
+      double riskamount=(risk/100)*AccountInfoDouble(ACCOUNT_BALANCE);
356
+      double pipvalue_required=riskamount/stop_loss;
357
+      lotSize = pipvalue_required/pipvalue;
358
+      //sl=riskamount/pipValuelot
359
+      int roundDigit=0;
360
+      double step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
361
+
362
+      while(step<1)
363
+        {
364
+         roundDigit++;
365
+         step=step*10;
366
+        }
367
+      Print("Round Digits:",roundDigit);
368
+      lotSize = NormalizeDouble(lotSize,roundDigit);
369
+      //
370
+     }
371
+   Print("Lot Size: ",lotSize);
372
+
373
+   if(lotSize > SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX))
374
+     {
375
+      lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
376
+     }
377
+   else
378
+      if(lotSize<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))
379
+        {
380
+         lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
381
+        }
382
+
383
+//---
384
+   return lotSize;
385
+  }
386
+//+------------------------------------------------------------------+
387
+//|                                                                  |
388
+//+------------------------------------------------------------------+
389
+//+------------------------------------------------------------------+