I am trying to modify the Volume Profile indicator so that it starts at market open on a chart that shows premarket activity (the chart setting is TODAY: 10m). I've added in a session start time input but I keep getting the development error that states "Unexpected error has happened. An unexpected error has occurred. If the problem persists, please contact tech support. You are advised to restart your application now." Here is the code I am using:
input customRowHeight = 1.0;
input timePerProfile = {default CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 60;
input opacity = 20;
input sessionStartTime = 0930; # Custom session start time in HHMM format
# Calculate session start in seconds
def sessionStartHour = Floor(sessionStartTime / 100);
def sessionStartMinute = sessionStartTime % 100;
def sessionStartSeconds = (sessionStartHour * 3600) + (sessionStartMinute * 60);
# Adjusted time logic
def secondsSinceSessionStart = SecondsFromTime(sessionStartSeconds);
def isSessionActive = secondsSinceSessionStart >= 0;
# Calculate period based on the selected profile type
def yyyymmdd = GetYyyyMmDd();
def tradingDays = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd);
def period;
switch (timePerProfile) {
case CHART:
period = 0;
case MINUTE:
period = Floor(secondsSinceSessionStart / 60);
case HOUR:
period = Floor(secondsSinceSessionStart / 3600);
case DAY:
period = if isSessionActive then tradingDays - 1 else Double.NaN;
case WEEK:
period = Floor(DaysFromDate(First(yyyymmdd)) / 7);
case MONTH:
period = GetYear() * 12 + GetMonth() - First(GetYear() * 12 + GetMonth());
case "OPT EXP":
period = GetYear() * 12 + GetMonth() + (GetDayOfMonth(yyyymmdd) > 20);
case BAR:
period = BarNumber() - 1;
}
# Define conditions for starting a new profile
def count = CompoundValue(1, if period != period[1] then (count[1] + 1) % multiplier else count[1], 0);
def cond = count == 0;
# Determine price per row height
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
height = PricePerRow.AUTOMATIC;
case TICKSIZE:
height = PricePerRow.TICKSIZE;
case CUSTOM:
height = customRowHeight;
}
# Volume profile
profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def pc = vol.GetPointOfControl();
def hVA = vol.GetHighestValueArea();
def lVA = vol.GetLowestValueArea();
# Plots
plot POC = if !IsNaN(pc) then pc else Double.NaN;
plot VAHigh = if !IsNaN(hVA) then hVA else Double.NaN;
plot VALow = if !IsNaN(lVA) then lVA else Double.NaN;
DefineGlobalColor("Profile", GetColor(1));
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));
POC.SetDefaultColor(GlobalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(GlobalColor("Value Area"));
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetDefaultColor(GlobalColor("Value Area"));
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
input customRowHeight = 1.0;
input timePerProfile = {default CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 60;
input opacity = 20;
input sessionStartTime = 0930; # Custom session start time in HHMM format
# Calculate session start in seconds
def sessionStartHour = Floor(sessionStartTime / 100);
def sessionStartMinute = sessionStartTime % 100;
def sessionStartSeconds = (sessionStartHour * 3600) + (sessionStartMinute * 60);
# Adjusted time logic
def secondsSinceSessionStart = SecondsFromTime(sessionStartSeconds);
def isSessionActive = secondsSinceSessionStart >= 0;
# Calculate period based on the selected profile type
def yyyymmdd = GetYyyyMmDd();
def tradingDays = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd);
def period;
switch (timePerProfile) {
case CHART:
period = 0;
case MINUTE:
period = Floor(secondsSinceSessionStart / 60);
case HOUR:
period = Floor(secondsSinceSessionStart / 3600);
case DAY:
period = if isSessionActive then tradingDays - 1 else Double.NaN;
case WEEK:
period = Floor(DaysFromDate(First(yyyymmdd)) / 7);
case MONTH:
period = GetYear() * 12 + GetMonth() - First(GetYear() * 12 + GetMonth());
case "OPT EXP":
period = GetYear() * 12 + GetMonth() + (GetDayOfMonth(yyyymmdd) > 20);
case BAR:
period = BarNumber() - 1;
}
# Define conditions for starting a new profile
def count = CompoundValue(1, if period != period[1] then (count[1] + 1) % multiplier else count[1], 0);
def cond = count == 0;
# Determine price per row height
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
height = PricePerRow.AUTOMATIC;
case TICKSIZE:
height = PricePerRow.TICKSIZE;
case CUSTOM:
height = customRowHeight;
}
# Volume profile
profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def pc = vol.GetPointOfControl();
def hVA = vol.GetHighestValueArea();
def lVA = vol.GetLowestValueArea();
# Plots
plot POC = if !IsNaN(pc) then pc else Double.NaN;
plot VAHigh = if !IsNaN(hVA) then hVA else Double.NaN;
plot VALow = if !IsNaN(lVA) then lVA else Double.NaN;
DefineGlobalColor("Profile", GetColor(1));
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));
POC.SetDefaultColor(GlobalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(GlobalColor("Value Area"));
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetDefaultColor(GlobalColor("Value Area"));
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);