Volume Profile with Session Start Time input

msmmlee

New member
Plus
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);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
243 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top