Bladeren bron

indicator updated

start/ end time is made input
WajeehSaqib-MQL 9 maanden geleden
bovenliggende
commit
39bd79d1a4
2 gewijzigde bestanden met toevoegingen van 52 en 39 verwijderingen
  1. BIN
      indicator/SequentialVolumeProfileWithFVG.ex5
  2. 52 39
      indicator/SequentialVolumeProfileWithFVG.mq5

BIN
indicator/SequentialVolumeProfileWithFVG.ex5


+ 52 - 39
indicator/SequentialVolumeProfileWithFVG.mq5

@@ -31,13 +31,17 @@ input color    BullishFVGColor=clrLime;      // Bullish FVG color
31 31
 input color    BearishFVGColor=clrDeepPink;  // Bearish FVG color
32 32
 input double   MinFVGSize=0.0;         // Minimum FVG size in points (0 = any size)
33 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
34 38
 
35 39
 // Structure to hold volume profile data for a day
36 40
 struct VolumeProfileData
37 41
   {
38 42
    datetime          date;          // Trading day date
39
-   datetime          startTime;     // Start time for calculation (23:00 previous day)
40
-   datetime          endTime;       // End time for calculation (23:00 current day)
43
+   datetime          startTime;     // Start time for calculation (23:59 previous day)
44
+   datetime          endTime;       // End time for calculation (23:59 current day)
41 45
    datetime          displayStart;  // When to start displaying this profile (= endTime)
42 46
    datetime          displayEnd;    // When to stop displaying this profile (= next day's endTime)
43 47
    double            val;             // Value Area Low
@@ -53,6 +57,12 @@ VolumeProfileData g_Profiles[];
53 57
 
54 58
 // Prefix for FVG objects
55 59
 string prefix;
60
+datetime lastCandleTime = 0;
61
+datetime  startTradingTime = 0, endTradingTime = 0;
62
+string sep  =  ":";                // A separator as a character
63
+ushort u_sep;                      // The code of the separator character
64
+string result1[];
65
+
56 66
 
57 67
 //+------------------------------------------------------------------+
58 68
 //| Custom indicator initialization function                         |
@@ -114,12 +124,11 @@ void OnTimer()
114 124
    MqlDateTime mdt;
115 125
    TimeToStruct(currentTime, mdt);
116 126
 
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
-     }
127
+// Check if it's near the 23:59 boundary (update a bit before and after)
128
+//if((mdt.hour == 23 && mdt.min >= 58) || (mdt.hour == 0 && mdt.min <= 5))
129
+//  {
130
+//   CalculateAllVolumeProfiles();
131
+//  }
123 132
   }
124 133
 
125 134
 //+------------------------------------------------------------------+
@@ -129,7 +138,24 @@ double RoundToTickSize(double value, double tickSize)
129 138
   {
130 139
    return MathRound(value / tickSize) * tickSize;
131 140
   }
132
-
141
+//+------------------------------------------------------------------+
142
+//|                                                                  |
143
+//+------------------------------------------------------------------+
144
+bool newDayBar()
145
+  {
146
+   static datetime lastbar;
147
+   datetime curbar = iTime(Symbol(), PERIOD_D1, 0);
148
+   if(lastbar != curbar)
149
+     {
150
+      lastbar = curbar;
151
+      Print(" ---------------------- New Day Bar :: ---------------------- ",lastbar);
152
+      return (true);
153
+     }
154
+   else
155
+     {
156
+      return (false);
157
+     }
158
+  }
133 159
 //+------------------------------------------------------------------+
134 160
 //| Custom indicator iteration function                              |
135 161
 //+------------------------------------------------------------------+
@@ -147,16 +173,20 @@ int OnCalculate(const int rates_total,
147 173
 // Check for insufficient data
148 174
    if(rates_total < 3)
149 175
       return 0;
150
-   if(newDayBar())
176
+
177
+   datetime currentTime = TimeCurrent();
178
+   MqlDateTime mdt;
179
+   TimeToStruct(currentTime, mdt);
180
+
181
+// Check if it's near the 23:59 boundary (update a bit before and after)
182
+   if((mdt.hour == (int)startHour && mdt.min >= (int)startMin) || (mdt.hour == (int)endHour && mdt.min <= (int)endMin))
151 183
      {
152
-      CalculateAllVolumeProfiles();
184
+      if(lastCandleTime != iTime(Symbol(),PERIOD_CURRENT,0))
185
+        {
186
+         CalculateAllVolumeProfiles();
187
+         lastCandleTime = iTime(Symbol(),PERIOD_CURRENT,0);
188
+        }
153 189
      }
154
-// Calculate Volume Profiles if needed
155
-//if(prev_calculated == 0)
156
-//  {
157
-//   CalculateAllVolumeProfiles();
158
-//  }
159
-
160 190
 // Detect Fair Value Gaps if enabled
161 191
    if(ShowFVG)
162 192
      {
@@ -327,7 +357,7 @@ void CalculateAllVolumeProfiles()
327 357
 // Update comment with the most recent profile (index 0)
328 358
    if(ShowComment && calculatedDays > 0)
329 359
      {
330
-      string info = "Volume Profile (TradingView 23:00-23:00 UTC+2)\n" +
360
+      string info = "Volume Profile (TradingView "+startHour+":"+startMin+"-"+startHour+":"+startMin+" UTC+2)\n" +
331 361
                     "Date: " + TimeToString(g_Profiles[0].date, TIME_DATE) + " (" + GetDayOfWeekName(g_Profiles[0].date) + ")\n" +
332 362
                     "Value Area: " + DoubleToString(ValueAreaPercent, 0) + "%\n" +
333 363
                     "VAL: " + DoubleToString(g_Profiles[0].val, _Digits) + "\n" +
@@ -338,24 +368,7 @@ void CalculateAllVolumeProfiles()
338 368
       Comment(info);
339 369
      }
340 370
   }
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
-  }
371
+
359 372
 //+------------------------------------------------------------------+
360 373
 //| Calculate time boundaries for a profile                          |
361 374
 //+------------------------------------------------------------------+
@@ -396,8 +409,8 @@ void CalculateTimeBoundaries(int index)
396 409
    string dayBeforeTradingDayStr = StringFormat("%04d.%02d.%02d", beforeMdt.year, beforeMdt.mon, beforeMdt.day);
397 410
 
398 411
 // Calculate start and end times
399
-   g_Profiles[index].startTime = StringToTime(dayBeforeTradingDayStr + " 23:00:00");
400
-   g_Profiles[index].endTime = StringToTime(tradingDayStr + " 23:00:00");
412
+   g_Profiles[index].startTime = StringToTime(dayBeforeTradingDayStr + " 23:59:00");
413
+   g_Profiles[index].endTime = StringToTime(tradingDayStr + " 23:59:00");
401 414
    g_Profiles[index].displayStart = g_Profiles[index].endTime;
402 415
   }
403 416
 
@@ -412,7 +425,7 @@ void CalculateVolumeProfileForDay(int index)
412 425
 
413 426
    Print("Calculating volume profile for ", TimeToString(tradingDay, TIME_DATE),
414 427
          " (", GetDayOfWeekName(tradingDay), ")");
415
-   Print("Time range: ", TimeToString(startTime), " to ", TimeToString(endTime), " Index: ", index);
428
+   Print("Time range: ", TimeToString(startTime), " to ", TimeToString(endTime));
416 429
 
417 430
 // Copy the OHLCV data for this day - using M1 timeframe for precision
418 431
    MqlRates rates[];