Weekly volume profile (POC) plotted forward on 30 minute chart

daytrader023042

New member
Hi all,

Been struggling to wrap my head around why I can't get this script to work. It's a modified version of some code I found a while back on this forum by @SleepyZ (thank you!). I'm not a programmer, just some basic knowledge from this site and a little help from ChatGPT. Basically, I would like a script that works on a 30 minute chart and uses weekly volume profile to do the following... It should take each POC for the last three completed weeks, and then plot them beginning from their respective subsequent week (e.g. the POC for the week of Jan 5th should begin plotting on Jan 12th). The lines should continue to plot to the right indefinitely. At any one point, the study should only show the latest three POC plots. The lines should be magenta to begin, but once breached at any time after the week the line formed, it should become gray (indicating that price has visited the specific POC after the week it formed).

I've been able to get the script working on a daily chart using monthly volume profile, but after adjusting everything for the 30 minute chart, no luck. Nothing appears on the chart. I've checked chart settings, ensured the plot is enabled, etc...

Here is the working code for the daily chart, and a screenshot of what the end result looks like (working as expected). At the bottom of the post, I have included the code I have tried on a 30M chart using Weekly Volume Profile, with no luck. Any suggestions as to what I may be doing wrong here? Thanks in advance for any help.

Code:
#Extended_POCs_HVAs_LVAs_for_x_Daysback_
#More can be added using the logic below
#Sleepyz - usethinkscript request @yardlay
#Added HVA * LVA Lines and Plot limit when crossed for all 3;

input limit_display = 3;
script v {
input daysback = 1;

    def month   = GetMonth();
    def year    = GetYear();
    def monthID = year * 12 + month;

    def currentMonth = HighestAll(monthID);
    def targetMonth  = currentMonth - daysback;

    def thisBarMonthID = monthID;

    def volp = reference VolumeProfile("time per profile" = "Month", "on expansion" = no, "price per row height mode" = "TICKSIZE");

def pocValue = if IsNaN(close) then pocValue[1]
                   else if thisBarMonthID == targetMonth then volp
                   else pocValue[1];

    def showPlot = thisBarMonthID > targetMonth;


    # Track breach
    def afterFormation = thisBarMonthID > targetMonth;

    # Regular intrabar touch
    def touchedBar = low <= pocValue and high >= pocValue;

    # Gap-cross detection (open on wrong side compared to prior close)
    def touchedGap = (close[1] < pocValue and open > pocValue) or
                     (close[1] > pocValue and open < pocValue);

    def touched = afterFormation and (touchedBar or touchedGap);

    def touchedEver = CompoundValue(1, if touched then 1 else touchedEver[1], 0);

    # Only show POC until first touch
    def active = showPlot and (touchedEver == 0);

    plot pocLive = if active then pocValue else Double.NaN;  # line while active
    plot pocGray = if showPlot and touchedEver then pocValue else Double.NaN;  # gray once breached

}

# Example: v1 (copy logic for v2...v10)
def poc1Live = v(1).pocLive;
def poc1Gray = v(1).pocGray;

plot v1 = if limit_display < 1 then Double.NaN else poc1Live;
v1.SetPaintingStrategy(PaintingStrategy.DASHES);
v1.SetLineWeight(2);
v1.SetDefaultColor(CreateColor(255, 0, 255));

plot v1gray = if limit_display < 1 then Double.NaN else poc1Gray;
v1gray.SetPaintingStrategy(PaintingStrategy.DASHES);
v1gray.SetLineWeight(2);
v1gray.SetDefaultColor(Color.GRAY);

# Example: v2
def poc2Live = v(2).pocLive;
def poc2Gray = v(2).pocGray;

plot v2 = if limit_display < 2 then Double.NaN else poc2Live;
v2.SetPaintingStrategy(PaintingStrategy.DASHES);
v2.SetLineWeight(2);
v2.SetDefaultColor(CreateColor(255, 0, 255));

plot v2gray = if limit_display < 2 then Double.NaN else poc2Gray;
v2gray.SetPaintingStrategy(PaintingStrategy.DASHES);
v2gray.SetLineWeight(2);
v2gray.SetDefaultColor(Color.GRAY);

# Example: v3
def poc3Live = v(3).pocLive;
def poc3Gray = v(3).pocGray;

plot v3 = if limit_display < 3 then Double.NaN else poc3Live;
v3.SetPaintingStrategy(PaintingStrategy.DASHES);
v3.SetLineWeight(2);
v3.SetDefaultColor(CreateColor(255, 0, 255));

plot v3gray = if limit_display < 3 then Double.NaN else poc3Gray;
v3gray.SetPaintingStrategy(PaintingStrategy.DASHES);
v3gray.SetLineWeight(2);
v3gray.SetDefaultColor(Color.GRAY);

usethinkscript.png



30M Chart Weekly Volume Profile code that is not working:
Code:
### NOTE: At start of new week, one 30M bar/candle needs to complete before the prior weeks POC line plots on current week
# Weekly POCs plotted forward on a 30-min chart
# Adapted from original by Sleepyz - Modified for Weekly
# Extended: POCs turn gray once touched after the week they formed

input limit_display = 3;

script v {
    input daysback = 1;

    def week    = GetWeek();
    def year    = GetYear();
    def weekID  = year * 100 + week;

    def currentWeek = HighestAll(weekID);
    def targetWeek  = currentWeek - daysback;

    def thisBarWeekID = weekID;

    def volp = reference VolumeProfile("time per profile" = "Week", "on expansion" = no, "price per row height mode" = "TICKSIZE");

    def pocValue = if IsNaN(close) then pocValue[1]
                   else if thisBarWeekID == targetWeek then volp
                   else pocValue[1];

    def showPlot =  thisBarWeekID > targetWeek;

    # Track breach
    def afterFormation = thisBarWeekID > targetWeek;

    # Regular intrabar touch
    def touchedBar = low <= pocValue and high >= pocValue;

    # Gap-cross detection (open on wrong side compared to prior close)
    def touchedGap = (close[1] < pocValue and open > pocValue) or
                     (close[1] > pocValue and open < pocValue);

    def touched = afterFormation and (touchedBar or touchedGap);

    def touchedEver = CompoundValue(1, if touched then 1 else touchedEver[1], 0);

    # Only show POC until first touch
    def active = showPlot and (touchedEver == 0);

    plot pocLive = if active then pocValue else Double.NaN;  # line while active
    plot pocGray = if showPlot and touchedEver then pocValue else Double.NaN;  # gray once breached
}


# Example: v1 (copy logic for v2...v10)
def poc1Live = v(1).pocLive;
def poc1Gray = v(1).pocGray;

plot v1 = if limit_display < 1 then Double.NaN else poc1Live;
v1.SetPaintingStrategy(PaintingStrategy.DASHES);
v1.SetLineWeight(2);
v1.SetDefaultColor(CreateColor(255, 0, 255));

plot v1gray = if limit_display < 1 then Double.NaN else poc1Gray;
v1gray.SetPaintingStrategy(PaintingStrategy.DASHES);
v1gray.SetLineWeight(2);
v1gray.SetDefaultColor(Color.GRAY);


# Example: v2
def poc2Live = v(2).pocLive;
def poc2Gray = v(2).pocGray;

plot v2 = if limit_display < 2 then Double.NaN else poc2Live;
v2.SetPaintingStrategy(PaintingStrategy.DASHES);
v2.SetLineWeight(2);
v2.SetDefaultColor(CreateColor(255, 0, 255));

plot v2gray = if limit_display < 2 then Double.NaN else poc2Gray;
v2gray.SetPaintingStrategy(PaintingStrategy.DASHES);
v2gray.SetLineWeight(2);
v2gray.SetDefaultColor(Color.GRAY);


# Example: v3
def poc3Live = v(3).pocLive;
def poc3Gray = v(3).pocGray;

plot v3 = if limit_display < 3 then Double.NaN else poc3Live;
v3.SetPaintingStrategy(PaintingStrategy.DASHES);
v3.SetLineWeight(2);
v3.SetDefaultColor(CreateColor(255, 0, 255));

plot v3gray = if limit_display < 3 then Double.NaN else poc3Gray;
v3gray.SetPaintingStrategy(PaintingStrategy.DASHES);
v3gray.SetLineWeight(2);
v3gray.SetDefaultColor(Color.GRAY);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
960 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