Эх сурвалжийг харах

indicator updated

start/ end time is made input
WajeehSaqib-MQL 1 жил өмнө
parent
commit
39bd79d1a4

BIN
indicator/SequentialVolumeProfileWithFVG.ex5


+ 52 - 39
indicator/SequentialVolumeProfileWithFVG.mq5

@@ -31,13 +31,17 @@ input color    BullishFVGColor=clrLime;      // Bullish FVG color
 input color    BearishFVGColor=clrDeepPink;  // Bearish FVG color
 input double   MinFVGSize=0.0;         // Minimum FVG size in points (0 = any size)
 input int      MaxBarsBack=300;        // How many bars to look back for FVG
+input     string                startHour            = "23";                                     // Start Hour
+input     string                startMin             = "59";                                     // Start Minutes
+input     string                endHour              = "00";                                     // End Hour
+input     string                endMin               = "05";                                     // End Minutes
 
 // Structure to hold volume profile data for a day
 struct VolumeProfileData
   {
    datetime          date;          // Trading day date
-   datetime          startTime;     // Start time for calculation (23:00 previous day)
-   datetime          endTime;       // End time for calculation (23:00 current day)
+   datetime          startTime;     // Start time for calculation (23:59 previous day)
+   datetime          endTime;       // End time for calculation (23:59 current day)
    datetime          displayStart;  // When to start displaying this profile (= endTime)
    datetime          displayEnd;    // When to stop displaying this profile (= next day's endTime)
    double            val;             // Value Area Low
@@ -53,6 +57,12 @@ VolumeProfileData g_Profiles[];
 
 // Prefix for FVG objects
 string prefix;
+datetime lastCandleTime = 0;
+datetime  startTradingTime = 0, endTradingTime = 0;
+string sep  =  ":";                // A separator as a character
+ushort u_sep;                      // The code of the separator character
+string result1[];
+
 
 //+------------------------------------------------------------------+
 //| Custom indicator initialization function                         |
@@ -114,12 +124,11 @@ void OnTimer()
    MqlDateTime mdt;
    TimeToStruct(currentTime, mdt);
 
-// Check if it's near the 23:00 boundary (update a bit before and after)
-// if((mdt.hour == 22 && mdt.min >= 59) || (mdt.hour == 23 && mdt.min <= 5))
-   if(newDayBar())
-     {
-      CalculateAllVolumeProfiles();
-     }
+// Check if it's near the 23:59 boundary (update a bit before and after)
+//if((mdt.hour == 23 && mdt.min >= 58) || (mdt.hour == 0 && mdt.min <= 5))
+//  {
+//   CalculateAllVolumeProfiles();
+//  }
   }
 
 //+------------------------------------------------------------------+
@@ -129,7 +138,24 @@ double RoundToTickSize(double value, double tickSize)
   {
    return MathRound(value / tickSize) * tickSize;
   }
-
+//+------------------------------------------------------------------+
+//|                                                                  |
+//+------------------------------------------------------------------+
+bool newDayBar()
+  {
+   static datetime lastbar;
+   datetime curbar = iTime(Symbol(), PERIOD_D1, 0);
+   if(lastbar != curbar)
+     {
+      lastbar = curbar;
+      Print(" ---------------------- New Day Bar :: ---------------------- ",lastbar);
+      return (true);
+     }
+   else
+     {
+      return (false);
+     }
+  }
 //+------------------------------------------------------------------+
 //| Custom indicator iteration function                              |
 //+------------------------------------------------------------------+
@@ -147,16 +173,20 @@ int OnCalculate(const int rates_total,
 // Check for insufficient data
    if(rates_total < 3)
       return 0;
-   if(newDayBar())
+
+   datetime currentTime = TimeCurrent();
+   MqlDateTime mdt;
+   TimeToStruct(currentTime, mdt);
+
+// Check if it's near the 23:59 boundary (update a bit before and after)
+   if((mdt.hour == (int)startHour && mdt.min >= (int)startMin) || (mdt.hour == (int)endHour && mdt.min <= (int)endMin))
      {
-      CalculateAllVolumeProfiles();
+      if(lastCandleTime != iTime(Symbol(),PERIOD_CURRENT,0))
+        {
+         CalculateAllVolumeProfiles();
+         lastCandleTime = iTime(Symbol(),PERIOD_CURRENT,0);
+        }
      }
-// Calculate Volume Profiles if needed
-//if(prev_calculated == 0)
-//  {
-//   CalculateAllVolumeProfiles();
-//  }
-
 // Detect Fair Value Gaps if enabled
    if(ShowFVG)
      {
@@ -327,7 +357,7 @@ void CalculateAllVolumeProfiles()
 // Update comment with the most recent profile (index 0)
    if(ShowComment && calculatedDays > 0)
      {
-      string info = "Volume Profile (TradingView 23:00-23:00 UTC+2)\n" +
+      string info = "Volume Profile (TradingView "+startHour+":"+startMin+"-"+startHour+":"+startMin+" UTC+2)\n" +
                     "Date: " + TimeToString(g_Profiles[0].date, TIME_DATE) + " (" + GetDayOfWeekName(g_Profiles[0].date) + ")\n" +
                     "Value Area: " + DoubleToString(ValueAreaPercent, 0) + "%\n" +
                     "VAL: " + DoubleToString(g_Profiles[0].val, _Digits) + "\n" +
@@ -338,24 +368,7 @@ void CalculateAllVolumeProfiles()
       Comment(info);
      }
   }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-bool newDayBar()
-  {
-   static datetime lastbar;
-   datetime curbar = iTime(Symbol(), PERIOD_D1, 0);
-   if(lastbar != curbar)
-     {
-      lastbar = curbar;
-      Print(" ---------------------- New Day Bar :: ---------------------- ",lastbar);
-      return (true);
-     }
-   else
-     {
-      return (false);
-     }
-  }
+
 //+------------------------------------------------------------------+
 //| Calculate time boundaries for a profile                          |
 //+------------------------------------------------------------------+
@@ -396,8 +409,8 @@ void CalculateTimeBoundaries(int index)
    string dayBeforeTradingDayStr = StringFormat("%04d.%02d.%02d", beforeMdt.year, beforeMdt.mon, beforeMdt.day);
 
 // Calculate start and end times
-   g_Profiles[index].startTime = StringToTime(dayBeforeTradingDayStr + " 23:00:00");
-   g_Profiles[index].endTime = StringToTime(tradingDayStr + " 23:00:00");
+   g_Profiles[index].startTime = StringToTime(dayBeforeTradingDayStr + " 23:59:00");
+   g_Profiles[index].endTime = StringToTime(tradingDayStr + " 23:59:00");
    g_Profiles[index].displayStart = g_Profiles[index].endTime;
   }
 
@@ -412,7 +425,7 @@ void CalculateVolumeProfileForDay(int index)
 
    Print("Calculating volume profile for ", TimeToString(tradingDay, TIME_DATE),
          " (", GetDayOfWeekName(tradingDay), ")");
-   Print("Time range: ", TimeToString(startTime), " to ", TimeToString(endTime), " Index: ", index);
+   Print("Time range: ", TimeToString(startTime), " to ", TimeToString(endTime));
 
 // Copy the OHLCV data for this day - using M1 timeframe for precision
    MqlRates rates[];