Pārlūkot izejas kodu

Indicator version 2 file added and EA is configured with it

WajeehSaqib-MQL 8 mēneši atpakaļ
vecāks
revīzija
d57726666b

BIN
indicator/SequentialVolumeProfileWithFVG.ex5


+ 40 - 64
indicator/SequentialVolumeProfileWithFVG.mq5

@@ -31,19 +31,13 @@ input color    BullishFVGColor=clrLime;      // Bullish FVG color
31
 input color    BearishFVGColor=clrDeepPink;  // Bearish FVG color
31
 input color    BearishFVGColor=clrDeepPink;  // Bearish FVG color
32
 input double   MinFVGSize=0.0;         // Minimum FVG size in points (0 = any size)
32
 input double   MinFVGSize=0.0;         // Minimum FVG size in points (0 = any size)
33
 input int      MaxBarsBack=300;        // How many bars to look back for FVG
33
 input int      MaxBarsBack=300;        // How many bars to look back for FVG
34
-input     string                startHour            = "23";                                     // Start Hour
35
-input     string                startMin             = "59";                                     // Start Minutes
36
-input     string                endHour              = "00";                                     // End Hour
37
-input     string                endMin               = "05";                                     // End Minutes
38
-
39
-datetime expiry=D'2025.05.30 12:30:27';
40
 
34
 
41
 // Structure to hold volume profile data for a day
35
 // Structure to hold volume profile data for a day
42
 struct VolumeProfileData
36
 struct VolumeProfileData
43
   {
37
   {
44
    datetime          date;          // Trading day date
38
    datetime          date;          // Trading day date
45
-   datetime          startTime;     // Start time for calculation (23:59 previous day)
46
-   datetime          endTime;       // End time for calculation (23:59 current day)
39
+   datetime          startTime;     // Start time for calculation (23:00 previous day)
40
+   datetime          endTime;       // End time for calculation (23:00 current day)
47
    datetime          displayStart;  // When to start displaying this profile (= endTime)
41
    datetime          displayStart;  // When to start displaying this profile (= endTime)
48
    datetime          displayEnd;    // When to stop displaying this profile (= next day's endTime)
42
    datetime          displayEnd;    // When to stop displaying this profile (= next day's endTime)
49
    double            val;             // Value Area Low
43
    double            val;             // Value Area Low
@@ -59,27 +53,15 @@ VolumeProfileData g_Profiles[];
59
 
53
 
60
 // Prefix for FVG objects
54
 // Prefix for FVG objects
61
 string prefix;
55
 string prefix;
62
-datetime lastCandleTime = 0;
63
-datetime  startTradingTime = 0, endTradingTime = 0;
64
-string sep  =  ":";                // A separator as a character
65
-ushort u_sep;                      // The code of the separator character
66
-string result1[];
67
-
68
-
69
 //+------------------------------------------------------------------+
56
 //+------------------------------------------------------------------+
70
 //| Custom indicator initialization function                         |
57
 //| Custom indicator initialization function                         |
71
 //+------------------------------------------------------------------+
58
 //+------------------------------------------------------------------+
72
 int OnInit()
59
 int OnInit()
73
   {
60
   {
61
+
74
 // Set up FVG object prefix
62
 // Set up FVG object prefix
75
    prefix = "VProfFVG_";
63
    prefix = "VProfFVG_";
76
 
64
 
77
-   if(TimeCurrent()>expiry)
78
-     {
79
-      Comment("Inactive. Contact Provider to Activate");
80
-      ExpertRemove();
81
-      return(INIT_FAILED);
82
-     }
83
 // Initialize profile storage
65
 // Initialize profile storage
84
    ArrayResize(g_Profiles, MaxDaysBack);
66
    ArrayResize(g_Profiles, MaxDaysBack);
85
    for(int i = 0; i < MaxDaysBack; i++)
67
    for(int i = 0; i < MaxDaysBack; i++)
@@ -132,11 +114,12 @@ void OnTimer()
132
    MqlDateTime mdt;
114
    MqlDateTime mdt;
133
    TimeToStruct(currentTime, mdt);
115
    TimeToStruct(currentTime, mdt);
134
 
116
 
135
-// Check if it's near the 23:59 boundary (update a bit before and after)
136
-//if((mdt.hour == 23 && mdt.min >= 58) || (mdt.hour == 0 && mdt.min <= 5))
137
-//  {
138
-//   CalculateAllVolumeProfiles();
139
-//  }
117
+// Check if it's near the 23:00 boundary (update a bit before and after)
118
+// if((mdt.hour == 22 && mdt.min >= 59) || (mdt.hour == 23 && mdt.min <= 5))
119
+   if(newDayBar())
120
+     {
121
+      CalculateAllVolumeProfiles();
122
+     }
140
   }
123
   }
141
 
124
 
142
 //+------------------------------------------------------------------+
125
 //+------------------------------------------------------------------+
@@ -146,24 +129,7 @@ double RoundToTickSize(double value, double tickSize)
146
   {
129
   {
147
    return MathRound(value / tickSize) * tickSize;
130
    return MathRound(value / tickSize) * tickSize;
148
   }
131
   }
149
-//+------------------------------------------------------------------+
150
-//|                                                                  |
151
-//+------------------------------------------------------------------+
152
-bool newDayBar()
153
-  {
154
-   static datetime lastbar;
155
-   datetime curbar = iTime(Symbol(), PERIOD_D1, 0);
156
-   if(lastbar != curbar)
157
-     {
158
-      lastbar = curbar;
159
-      Print(" ---------------------- New Day Bar :: ---------------------- ",lastbar);
160
-      return (true);
161
-     }
162
-   else
163
-     {
164
-      return (false);
165
-     }
166
-  }
132
+
167
 //+------------------------------------------------------------------+
133
 //+------------------------------------------------------------------+
168
 //| Custom indicator iteration function                              |
134
 //| Custom indicator iteration function                              |
169
 //+------------------------------------------------------------------+
135
 //+------------------------------------------------------------------+
@@ -181,23 +147,16 @@ int OnCalculate(const int rates_total,
181
 // Check for insufficient data
147
 // Check for insufficient data
182
    if(rates_total < 3)
148
    if(rates_total < 3)
183
       return 0;
149
       return 0;
184
-
185
-   datetime currentTime = TimeCurrent();
186
-   MqlDateTime mdt;
187
-   TimeToStruct(currentTime, mdt);
188
-
189
-// Check if it's near the 23:59 boundary (update a bit before and after)
190
-   if((mdt.hour == (int)startHour && mdt.min >= (int)startMin) || (mdt.hour == (int)endHour && mdt.min <= (int)endMin))
150
+   if(newDayBar())
191
      {
151
      {
192
-      if(lastCandleTime != iTime(Symbol(),PERIOD_D1,0))
193
-        {
194
-         //if(newDayBar())
195
-           {
196
-            CalculateAllVolumeProfiles();
197
-            lastCandleTime = iTime(Symbol(),PERIOD_D1,0);
198
-           }
199
-        }
152
+      CalculateAllVolumeProfiles();
200
      }
153
      }
154
+// Calculate Volume Profiles if needed
155
+//if(prev_calculated == 0)
156
+//  {
157
+//   CalculateAllVolumeProfiles();
158
+//  }
159
+
201
 // Detect Fair Value Gaps if enabled
160
 // Detect Fair Value Gaps if enabled
202
    if(ShowFVG)
161
    if(ShowFVG)
203
      {
162
      {
@@ -368,7 +327,7 @@ void CalculateAllVolumeProfiles()
368
 // Update comment with the most recent profile (index 0)
327
 // Update comment with the most recent profile (index 0)
369
    if(ShowComment && calculatedDays > 0)
328
    if(ShowComment && calculatedDays > 0)
370
      {
329
      {
371
-      string info = "Volume Profile (TradingView "+startHour+":"+startMin+"-"+startHour+":"+startMin+" UTC+2)\n" +
330
+      string info = "Volume Profile (TradingView 23:00-23:00 UTC+2)\n" +
372
                     "Date: " + TimeToString(g_Profiles[0].date, TIME_DATE) + " (" + GetDayOfWeekName(g_Profiles[0].date) + ")\n" +
331
                     "Date: " + TimeToString(g_Profiles[0].date, TIME_DATE) + " (" + GetDayOfWeekName(g_Profiles[0].date) + ")\n" +
373
                     "Value Area: " + DoubleToString(ValueAreaPercent, 0) + "%\n" +
332
                     "Value Area: " + DoubleToString(ValueAreaPercent, 0) + "%\n" +
374
                     "VAL: " + DoubleToString(g_Profiles[0].val, _Digits) + "\n" +
333
                     "VAL: " + DoubleToString(g_Profiles[0].val, _Digits) + "\n" +
@@ -379,7 +338,24 @@ void CalculateAllVolumeProfiles()
379
       Comment(info);
338
       Comment(info);
380
      }
339
      }
381
   }
340
   }
382
-
341
+//+------------------------------------------------------------------+
342
+//|                                                                  |
343
+//+------------------------------------------------------------------+
344
+bool newDayBar()
345
+  {
346
+   static datetime lastbar;
347
+   datetime curbar = iTime(Symbol(), PERIOD_D1, 0);
348
+   if(lastbar != curbar)
349
+     {
350
+      lastbar = curbar;
351
+      Print(" ---------------------- New Day Bar :: ---------------------- ",lastbar);
352
+      return (true);
353
+     }
354
+   else
355
+     {
356
+      return (false);
357
+     }
358
+  }
383
 //+------------------------------------------------------------------+
359
 //+------------------------------------------------------------------+
384
 //| Calculate time boundaries for a profile                          |
360
 //| Calculate time boundaries for a profile                          |
385
 //+------------------------------------------------------------------+
361
 //+------------------------------------------------------------------+
@@ -420,8 +396,8 @@ void CalculateTimeBoundaries(int index)
420
    string dayBeforeTradingDayStr = StringFormat("%04d.%02d.%02d", beforeMdt.year, beforeMdt.mon, beforeMdt.day);
396
    string dayBeforeTradingDayStr = StringFormat("%04d.%02d.%02d", beforeMdt.year, beforeMdt.mon, beforeMdt.day);
421
 
397
 
422
 // Calculate start and end times
398
 // Calculate start and end times
423
-   g_Profiles[index].startTime = StringToTime(dayBeforeTradingDayStr + " 23:59:00");
424
-   g_Profiles[index].endTime = StringToTime(tradingDayStr + " 23:59:00");
399
+   g_Profiles[index].startTime = StringToTime(dayBeforeTradingDayStr + " 23:00:00");
400
+   g_Profiles[index].endTime = StringToTime(tradingDayStr + " 23:00:00");
425
    g_Profiles[index].displayStart = g_Profiles[index].endTime;
401
    g_Profiles[index].displayStart = g_Profiles[index].endTime;
426
   }
402
   }
427
 
403
 
@@ -436,7 +412,7 @@ void CalculateVolumeProfileForDay(int index)
436
 
412
 
437
    Print("Calculating volume profile for ", TimeToString(tradingDay, TIME_DATE),
413
    Print("Calculating volume profile for ", TimeToString(tradingDay, TIME_DATE),
438
          " (", GetDayOfWeekName(tradingDay), ")");
414
          " (", GetDayOfWeekName(tradingDay), ")");
439
-   Print("Time range: ", TimeToString(startTime), " to ", TimeToString(endTime));
415
+   Print("Time range: ", TimeToString(startTime), " to ", TimeToString(endTime), " Index: ", index);
440
 
416
 
441
 // Copy the OHLCV data for this day - using M1 timeframe for precision
417
 // Copy the OHLCV data for this day - using M1 timeframe for precision
442
    MqlRates rates[];
418
    MqlRates rates[];

BIN
valFvgMt5.ex5


+ 8 - 13
valFvgMt5.mq5

@@ -5,7 +5,7 @@
5
 //+------------------------------------------------------------------+
5
 //+------------------------------------------------------------------+
6
 #property copyright "Copyright 2025, MQL Development"
6
 #property copyright "Copyright 2025, MQL Development"
7
 #property link      "https://www.mqldevelopment.com/"
7
 #property link      "https://www.mqldevelopment.com/"
8
-#property version   "1.1"
8
+#property version   "1.2"
9
 #include <Trade\Trade.mqh>
9
 #include <Trade\Trade.mqh>
10
 CTrade  trade;
10
 CTrade  trade;
11
 #resource "\\Indicators\\SequentialVolumeProfileWithFVG.ex5"
11
 #resource "\\Indicators\\SequentialVolumeProfileWithFVG.ex5"
@@ -92,11 +92,6 @@ input        color                   BearishFVGColor            = clrDeepPink;
92
 input        double                  MinFVGSize                 = 0.0;              // Minimum FVG size in points (0 = any size)
92
 input        double                  MinFVGSize                 = 0.0;              // Minimum FVG size in points (0 = any size)
93
 input        int                     MaxBarsBack                = 300;              // How many bars to look back for FVG
93
 input        int                     MaxBarsBack                = 300;              // How many bars to look back for FVG
94
 
94
 
95
-input        string                  startHour                  = "23";             // Start Hour
96
-input        string                  startMin                   = "59";             // Start Minutes
97
-input        string                  endHour                    = "00";             // End Hour
98
-input        string                  endMin                     = "05";             // End Minutes
99
-
100
 
95
 
101
 
96
 
102
 // Global Variables
97
 // Global Variables
@@ -105,12 +100,16 @@ datetime  startTradingTime = 0, endTradingTime = 0;
105
 string sep  =  ":";                // A separator as a character
100
 string sep  =  ":";                // A separator as a character
106
 ushort u_sep;                      // The code of the separator character
101
 ushort u_sep;                      // The code of the separator character
107
 string result1[];
102
 string result1[];
103
+
108
 //+------------------------------------------------------------------+
104
 //+------------------------------------------------------------------+
109
 //|                                                                  |
105
 //|                                                                  |
110
 //+------------------------------------------------------------------+
106
 //+------------------------------------------------------------------+
111
 int OnInit()
107
 int OnInit()
112
   {
108
   {
113
 //---
109
 //---
110
+
111
+
112
+     
114
    trade.SetExpertMagicNumber(magic_no);
113
    trade.SetExpertMagicNumber(magic_no);
115
    trade.SetDeviationInPoints(10);
114
    trade.SetDeviationInPoints(10);
116
    trade.SetTypeFilling(ORDER_FILLING_IOC);
115
    trade.SetTypeFilling(ORDER_FILLING_IOC);
@@ -138,11 +137,7 @@ int OnInit()
138
                                 BullishFVGColor,
137
                                 BullishFVGColor,
139
                                 BearishFVGColor,
138
                                 BearishFVGColor,
140
                                 MinFVGSize,
139
                                 MinFVGSize,
141
-                                MaxBarsBack,
142
-                                startHour,
143
-                                startMin,
144
-                                endHour,
145
-                                endMin);
140
+                                MaxBarsBack);
146
 
141
 
147
 
142
 
148
 //---
143
 //---
@@ -528,7 +523,7 @@ string check_bearish_bullish()
528
 string fvg_gap()
523
 string fvg_gap()
529
   {
524
   {
530
 //Print("Imbalance: ");
525
 //Print("Imbalance: ");
531
-//  if(check_bearish_bullish() == previousBullish)
526
+ //  if(check_bearish_bullish() == previousBullish)
532
      {
527
      {
533
       if(iLow(Symbol(), PERIOD_CURRENT, 1) > iHigh(Symbol(), PERIOD_CURRENT, 3))
528
       if(iLow(Symbol(), PERIOD_CURRENT, 1) > iHigh(Symbol(), PERIOD_CURRENT, 3))
534
         {
529
         {
@@ -553,7 +548,7 @@ string fvg_gap()
553
            }
548
            }
554
         }
549
         }
555
      }
550
      }
556
-// if(check_bearish_bullish() == previousBearish)
551
+  // if(check_bearish_bullish() == previousBearish)
557
      {
552
      {
558
       if(iLow(Symbol(), PERIOD_CURRENT, 3) > iHigh(Symbol(), PERIOD_CURRENT, 1))
553
       if(iLow(Symbol(), PERIOD_CURRENT, 3) > iHigh(Symbol(), PERIOD_CURRENT, 1))
559
         {
554
         {