|
@@ -31,19 +31,13 @@ input color BullishFVGColor=clrLime; // Bullish FVG color
|
|
|
input color BearishFVGColor=clrDeepPink; // Bearish FVG color
|
|
input color BearishFVGColor=clrDeepPink; // Bearish FVG color
|
|
|
input double MinFVGSize=0.0; // Minimum FVG size in points (0 = any size)
|
|
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 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
|
|
|
|
|
-
|
|
|
|
|
-datetime expiry=D'2025.05.30 12:30:27';
|
|
|
|
|
|
|
|
|
|
// Structure to hold volume profile data for a day
|
|
// Structure to hold volume profile data for a day
|
|
|
struct VolumeProfileData
|
|
struct VolumeProfileData
|
|
|
{
|
|
{
|
|
|
datetime date; // Trading day date
|
|
datetime date; // Trading day date
|
|
|
- datetime startTime; // Start time for calculation (23:59 previous day)
|
|
|
|
|
- datetime endTime; // End time for calculation (23:59 current day)
|
|
|
|
|
|
|
+ datetime startTime; // Start time for calculation (23:00 previous day)
|
|
|
|
|
+ datetime endTime; // End time for calculation (23:00 current day)
|
|
|
datetime displayStart; // When to start displaying this profile (= endTime)
|
|
datetime displayStart; // When to start displaying this profile (= endTime)
|
|
|
datetime displayEnd; // When to stop displaying this profile (= next day's endTime)
|
|
datetime displayEnd; // When to stop displaying this profile (= next day's endTime)
|
|
|
double val; // Value Area Low
|
|
double val; // Value Area Low
|
|
@@ -59,27 +53,15 @@ VolumeProfileData g_Profiles[];
|
|
|
|
|
|
|
|
// Prefix for FVG objects
|
|
// Prefix for FVG objects
|
|
|
string prefix;
|
|
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 |
|
|
//| Custom indicator initialization function |
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
|
int OnInit()
|
|
int OnInit()
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
// Set up FVG object prefix
|
|
// Set up FVG object prefix
|
|
|
prefix = "VProfFVG_";
|
|
prefix = "VProfFVG_";
|
|
|
|
|
|
|
|
- if(TimeCurrent()>expiry)
|
|
|
|
|
- {
|
|
|
|
|
- Comment("Inactive. Contact Provider to Activate");
|
|
|
|
|
- ExpertRemove();
|
|
|
|
|
- return(INIT_FAILED);
|
|
|
|
|
- }
|
|
|
|
|
// Initialize profile storage
|
|
// Initialize profile storage
|
|
|
ArrayResize(g_Profiles, MaxDaysBack);
|
|
ArrayResize(g_Profiles, MaxDaysBack);
|
|
|
for(int i = 0; i < MaxDaysBack; i++)
|
|
for(int i = 0; i < MaxDaysBack; i++)
|
|
@@ -132,11 +114,12 @@ void OnTimer()
|
|
|
MqlDateTime mdt;
|
|
MqlDateTime mdt;
|
|
|
TimeToStruct(currentTime, mdt);
|
|
TimeToStruct(currentTime, mdt);
|
|
|
|
|
|
|
|
-// 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();
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+// 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();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
@@ -146,24 +129,7 @@ double RoundToTickSize(double value, double tickSize)
|
|
|
{
|
|
{
|
|
|
return MathRound(value / tickSize) * 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 |
|
|
//| Custom indicator iteration function |
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
@@ -181,23 +147,16 @@ int OnCalculate(const int rates_total,
|
|
|
// Check for insufficient data
|
|
// Check for insufficient data
|
|
|
if(rates_total < 3)
|
|
if(rates_total < 3)
|
|
|
return 0;
|
|
return 0;
|
|
|
-
|
|
|
|
|
- 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))
|
|
|
|
|
|
|
+ if(newDayBar())
|
|
|
{
|
|
{
|
|
|
- if(lastCandleTime != iTime(Symbol(),PERIOD_D1,0))
|
|
|
|
|
- {
|
|
|
|
|
- //if(newDayBar())
|
|
|
|
|
- {
|
|
|
|
|
- CalculateAllVolumeProfiles();
|
|
|
|
|
- lastCandleTime = iTime(Symbol(),PERIOD_D1,0);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ CalculateAllVolumeProfiles();
|
|
|
}
|
|
}
|
|
|
|
|
+// Calculate Volume Profiles if needed
|
|
|
|
|
+//if(prev_calculated == 0)
|
|
|
|
|
+// {
|
|
|
|
|
+// CalculateAllVolumeProfiles();
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
// Detect Fair Value Gaps if enabled
|
|
// Detect Fair Value Gaps if enabled
|
|
|
if(ShowFVG)
|
|
if(ShowFVG)
|
|
|
{
|
|
{
|
|
@@ -368,7 +327,7 @@ void CalculateAllVolumeProfiles()
|
|
|
// Update comment with the most recent profile (index 0)
|
|
// Update comment with the most recent profile (index 0)
|
|
|
if(ShowComment && calculatedDays > 0)
|
|
if(ShowComment && calculatedDays > 0)
|
|
|
{
|
|
{
|
|
|
- string info = "Volume Profile (TradingView "+startHour+":"+startMin+"-"+startHour+":"+startMin+" UTC+2)\n" +
|
|
|
|
|
|
|
+ string info = "Volume Profile (TradingView 23:00-23:00 UTC+2)\n" +
|
|
|
"Date: " + TimeToString(g_Profiles[0].date, TIME_DATE) + " (" + GetDayOfWeekName(g_Profiles[0].date) + ")\n" +
|
|
"Date: " + TimeToString(g_Profiles[0].date, TIME_DATE) + " (" + GetDayOfWeekName(g_Profiles[0].date) + ")\n" +
|
|
|
"Value Area: " + DoubleToString(ValueAreaPercent, 0) + "%\n" +
|
|
"Value Area: " + DoubleToString(ValueAreaPercent, 0) + "%\n" +
|
|
|
"VAL: " + DoubleToString(g_Profiles[0].val, _Digits) + "\n" +
|
|
"VAL: " + DoubleToString(g_Profiles[0].val, _Digits) + "\n" +
|
|
@@ -379,7 +338,24 @@ void CalculateAllVolumeProfiles()
|
|
|
Comment(info);
|
|
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 |
|
|
//| Calculate time boundaries for a profile |
|
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
@@ -420,8 +396,8 @@ void CalculateTimeBoundaries(int index)
|
|
|
string dayBeforeTradingDayStr = StringFormat("%04d.%02d.%02d", beforeMdt.year, beforeMdt.mon, beforeMdt.day);
|
|
string dayBeforeTradingDayStr = StringFormat("%04d.%02d.%02d", beforeMdt.year, beforeMdt.mon, beforeMdt.day);
|
|
|
|
|
|
|
|
// Calculate start and end times
|
|
// Calculate start and end times
|
|
|
- g_Profiles[index].startTime = StringToTime(dayBeforeTradingDayStr + " 23:59:00");
|
|
|
|
|
- g_Profiles[index].endTime = StringToTime(tradingDayStr + " 23:59:00");
|
|
|
|
|
|
|
+ g_Profiles[index].startTime = StringToTime(dayBeforeTradingDayStr + " 23:00:00");
|
|
|
|
|
+ g_Profiles[index].endTime = StringToTime(tradingDayStr + " 23:00:00");
|
|
|
g_Profiles[index].displayStart = g_Profiles[index].endTime;
|
|
g_Profiles[index].displayStart = g_Profiles[index].endTime;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -436,7 +412,7 @@ void CalculateVolumeProfileForDay(int index)
|
|
|
|
|
|
|
|
Print("Calculating volume profile for ", TimeToString(tradingDay, TIME_DATE),
|
|
Print("Calculating volume profile for ", TimeToString(tradingDay, TIME_DATE),
|
|
|
" (", GetDayOfWeekName(tradingDay), ")");
|
|
" (", GetDayOfWeekName(tradingDay), ")");
|
|
|
- Print("Time range: ", TimeToString(startTime), " to ", TimeToString(endTime));
|
|
|
|
|
|
|
+ Print("Time range: ", TimeToString(startTime), " to ", TimeToString(endTime), " Index: ", index);
|
|
|
|
|
|
|
|
// Copy the OHLCV data for this day - using M1 timeframe for precision
|
|
// Copy the OHLCV data for this day - using M1 timeframe for precision
|
|
|
MqlRates rates[];
|
|
MqlRates rates[];
|