|
|
@@ -31,19 +31,13 @@ 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
|
|
38
|
|
-
|
|
39
|
|
-datetime expiry=D'2025.05.30 12:30:27';
|
|
40
|
34
|
|
|
41
|
35
|
// Structure to hold volume profile data for a day
|
|
42
|
36
|
struct VolumeProfileData
|
|
43
|
37
|
{
|
|
44
|
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
|
41
|
datetime displayStart; // When to start displaying this profile (= endTime)
|
|
48
|
42
|
datetime displayEnd; // When to stop displaying this profile (= next day's endTime)
|
|
49
|
43
|
double val; // Value Area Low
|
|
|
@@ -59,27 +53,15 @@ VolumeProfileData g_Profiles[];
|
|
59
|
53
|
|
|
60
|
54
|
// Prefix for FVG objects
|
|
61
|
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
|
57
|
//| Custom indicator initialization function |
|
|
71
|
58
|
//+------------------------------------------------------------------+
|
|
72
|
59
|
int OnInit()
|
|
73
|
60
|
{
|
|
|
61
|
+
|
|
74
|
62
|
// Set up FVG object prefix
|
|
75
|
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
|
65
|
// Initialize profile storage
|
|
84
|
66
|
ArrayResize(g_Profiles, MaxDaysBack);
|
|
85
|
67
|
for(int i = 0; i < MaxDaysBack; i++)
|
|
|
@@ -132,11 +114,12 @@ void OnTimer()
|
|
132
|
114
|
MqlDateTime mdt;
|
|
133
|
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
|
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
|
134
|
//| Custom indicator iteration function |
|
|
169
|
135
|
//+------------------------------------------------------------------+
|
|
|
@@ -181,23 +147,16 @@ int OnCalculate(const int rates_total,
|
|
181
|
147
|
// Check for insufficient data
|
|
182
|
148
|
if(rates_total < 3)
|
|
183
|
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
|
160
|
// Detect Fair Value Gaps if enabled
|
|
202
|
161
|
if(ShowFVG)
|
|
203
|
162
|
{
|
|
|
@@ -368,7 +327,7 @@ void CalculateAllVolumeProfiles()
|
|
368
|
327
|
// Update comment with the most recent profile (index 0)
|
|
369
|
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
|
331
|
"Date: " + TimeToString(g_Profiles[0].date, TIME_DATE) + " (" + GetDayOfWeekName(g_Profiles[0].date) + ")\n" +
|
|
373
|
332
|
"Value Area: " + DoubleToString(ValueAreaPercent, 0) + "%\n" +
|
|
374
|
333
|
"VAL: " + DoubleToString(g_Profiles[0].val, _Digits) + "\n" +
|
|
|
@@ -379,7 +338,24 @@ void CalculateAllVolumeProfiles()
|
|
379
|
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
|
360
|
//| Calculate time boundaries for a profile |
|
|
385
|
361
|
//+------------------------------------------------------------------+
|
|
|
@@ -420,8 +396,8 @@ void CalculateTimeBoundaries(int index)
|
|
420
|
396
|
string dayBeforeTradingDayStr = StringFormat("%04d.%02d.%02d", beforeMdt.year, beforeMdt.mon, beforeMdt.day);
|
|
421
|
397
|
|
|
422
|
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
|
401
|
g_Profiles[index].displayStart = g_Profiles[index].endTime;
|
|
426
|
402
|
}
|
|
427
|
403
|
|
|
|
@@ -436,7 +412,7 @@ void CalculateVolumeProfileForDay(int index)
|
|
436
|
412
|
|
|
437
|
413
|
Print("Calculating volume profile for ", TimeToString(tradingDay, TIME_DATE),
|
|
438
|
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
|
417
|
// Copy the OHLCV data for this day - using M1 timeframe for precision
|
|
442
|
418
|
MqlRates rates[];
|