Extend Point of Control Line (Volume Profile) For ThinkOrSwim

yardley

New member
Hi,

I need some help redoing the VolumeProfile Indictor that comes with ThinkorSwim. Here's my ask:

I want to present the VolumeProfile indicator on a chart such that the POC of control line extends all the way to the right axis. Here's a pic to demonstrate.
Image

The first image shows a chart that displays the daily Volume Profile with the blue line being the POC. In the second image, I manually drew a line that extends the POC line to the right with the price displayed at the end. Can someone help me replicate this with the existing VolumeProfile indicator that comes with ThinkOrSwim? I'm not very savvy with ThinkOrSwim script. Greatly appreciate any help.
 
Solution
Hi,

I need some help redoing the VolumeProfile Indictor that comes with ThinkorSwim. Here's my ask:

I want to present the VolumeProfile indicator on a chart such that the POC of control line extends all the way to the right axis. Here's a pic to demonstrate.
Image

The first image shows a chart that displays the daily Volume Profile with the blue line being the POC. In the second image, I manually drew a line that extends the POC line to the right with the price displayed at the end. Can someone help me replicate this with the existing VolumeProfile indicator that comes with ThinkOrSwim? I'm not very savvy with ThinkOrSwim script. Greatly appreciate any help.

Just saw your request.

This script combines x number of...
Just saw your request.

This script combines x number of extended plots of the POC of the Volumeprofile indicator, also included in the script. You can add more extended plots by using the logic used to create the 10 included in the script. You could also change the def volp to be one of the other profile plots available in the box to the right when you click on the reference volumeprofile portion of the def volp.
@SleepyZ If I wanted to show all the POC from the last 365 days would I just adjust the days back in the script or would I need to set the chart to that many days back? The reason I say this is because I've already tried both ways and its not plotting POC that I'm seeing from June that I manually drew out. I would like this to show all POC's only from the entire year unless broken.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@SleepyZ If I wanted to show all the POC from the last 365 days would I just adjust the days back in the script or would I need to set the chart to that many days back? The reason I say this is because I've already tried both ways and its not plotting POC that I'm seeing from June that I manually drew out. I would like this to show all POC's only from the entire year unless broken.

The script contains 10 poc plots. You will need to make the remaining 355 plots using the basis to create the 10. It will likely be very resource intensive if you decide to do this.
 
Added HVA, LVA plots to POC plots, all extended to the right unless crossed

is it possible to have this modified, so that the plots only disappear when crossed or tested during regular trading hours? Because pre-market and after-hours generally have much lower volume and liquidity…
 
is it possible to have this modified, so that the plots only disappear when crossed or tested during regular trading hours? Because pre-market and after-hours generally have much lower volume and liquidity…

Yes, in the script function, defined high/low to be hi/lo, which is restricted to rthrs.

The image shows the old code on the left and the new on the right.

Screenshot 2024-02-12 112708.png

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

script v {
    input daysback = 1;
    def volp = reference VolumeProfile("time per profile" = "DAY", "on expansion" = no, "price per row height mode" = "TICKSIZE");
    def ymd  = GetYYYYMMDD();
    def y    = if ymd != ymd[1] then y[1] + 1 else y[1];
    def pc   = if IsNaN(close)
                  then pc[1] else
               if y == HighestAll(y) - daysback
                  then volp  else
               pc[1];
    def rth  = secondsfromTime(0930)>=0 and secondsFromTime(1600)<0;
    def hi   = if !rth then double.nan else high;
    def lo   = if !rth then double.nan else low;
    def x    = if y > HighestAll(y) - daysback and Between(pc, lo, hi)
           then BarNumber() else Double.NaN;

    plot poc = if IsNaN(LowestAll(x))
           then pc
           else if BarNumber() > LowestAll(x)
           then Double.NaN
           else pc;
}
script vh {
    input daysback = 1;
    def volh = reference VolumeProfile("time per profile" = "DAY", "on expansion" = no, "price per row height mode" = "TICKSIZE").VAHigh;
    def ymd  = GetYYYYMMDD();
    def y    = if ymd != ymd[1] then y[1] + 1 else y[1];
    def ph   = if IsNaN(close)
                  then ph[1] else
               if y == HighestAll(y) - daysback
                  then volh  else
               ph[1];
    def rth  = secondsfromTime(0930)>=0 and secondsFromTime(1600)<0;
    def hi   = if !rth then double.nan else high;
    def lo   = if !rth then double.nan else low;
    def x    = if y > HighestAll(y) - daysback and Between(ph, lo, hi)
           then BarNumber() else Double.NaN;

    plot hva = if IsNaN(LowestAll(x))
           then ph
           else if BarNumber() > LowestAll(x)
           then Double.NaN
           else ph;
}
script vl {
    input daysback = 1;
    def voll = reference VolumeProfile("time per profile" = "DAY", "on expansion" = no, "price per row height mode" = "TICKSIZE").VALow;
    def ymd  = GetYYYYMMDD();
    def y    = if ymd != ymd[1] then y[1] + 1 else y[1];
    def pl   = if IsNaN(close)
                  then pl[1] else
               if y == HighestAll(y) - daysback
                  then voll  else
               pl[1];
    def rth  = secondsfromTime(0930)>=0 and secondsFromTime(1600)<0;
    def hi   = if !rth then double.nan else high;
    def lo   = if !rth then double.nan else low;
    def x    = if y > HighestAll(y) - daysback and Between(pl, lo, hi)
           then BarNumber() else Double.NaN;

    plot val = if IsNaN(LowestAll(x))
           then pl
           else if BarNumber() > LowestAll(x)
           then Double.NaN
           else pl;
}

defineglobalColor("H", color.yellow);
defineglobalColor("L", color.yellow);

plot v1 =  v(1).poc;
v1.SetDefaultColor(Color.RED);
v1.SetPaintingStrategy(PaintingStrategy.DASHES);
v1.SetLineWeight(2);

plot v2 =  v(2).poc;
v2.SetDefaultColor(Color.RED);
v2.SetPaintingStrategy(PaintingStrategy.DASHES);
v2.SetLineWeight(2);

plot v3 =  v(3).poc;
v3.SetDefaultColor(Color.RED);
v3.SetPaintingStrategy(PaintingStrategy.DASHES);
v3.SetLineWeight(2);

plot v4 =  v(4).poc;
v4.SetDefaultColor(Color.RED);
v4.SetPaintingStrategy(PaintingStrategy.DASHES);
v4.SetLineWeight(2);

plot v5 =  v(5).poc;
v5.SetDefaultColor(Color.RED);
v5.SetPaintingStrategy(PaintingStrategy.DASHES);
v5.SetLineWeight(2);

plot v6 =  v(6).poc;
v6.SetDefaultColor(Color.RED);
v6.SetPaintingStrategy(PaintingStrategy.DASHES);
v6.SetLineWeight(2);

plot v7 =  v(7).poc;
v7.SetDefaultColor(Color.RED);
v7.SetPaintingStrategy(PaintingStrategy.DASHES);
v7.SetLineWeight(2);

plot v8 =  v(8).poc;
v8.SetDefaultColor(Color.RED);
v8.SetPaintingStrategy(PaintingStrategy.DASHES);
v8.SetLineWeight(2);

plot v9 =  v(9).poc;
v9.SetDefaultColor(Color.RED);
v9.SetPaintingStrategy(PaintingStrategy.DASHES);
v9.SetLineWeight(2);

plot v10 =  v(10).poc;
v10.SetDefaultColor(Color.RED);
v10.SetPaintingStrategy(PaintingStrategy.DASHES);
v10.SetLineWeight(2);
;


plot vh1 =  vh(1);
vh1.SetDefaultColor(globalColor("H"));
vh1.SetPaintingStrategy(PaintingStrategy.DASHES);
vh1.SetLineWeight(2);

plot vh2 =  vh(2);
vh2.SetDefaultColor(globalColor("H"));
vh2.SetPaintingStrategy(PaintingStrategy.DASHES);
vh2.SetLineWeight(2);

plot vh3 =  vh(3);
v3.SetDefaultColor(globalColor("H"));
v3.SetPaintingStrategy(PaintingStrategy.DASHES);
v3.SetLineWeight(2);

plot vh4 =  vh(4);
vh4.SetDefaultColor(globalColor("H"));
vh4.SetPaintingStrategy(PaintingStrategy.DASHES);
vh4.SetLineWeight(2);

plot vh5 =  vh(5);
vh5.SetDefaultColor(globalColor("H"));
vh5.SetPaintingStrategy(PaintingStrategy.DASHES);
vh5.SetLineWeight(2);

plot vh6 =  vh(6);
vh6.SetDefaultColor(globalColor("H"));
vh6.SetPaintingStrategy(PaintingStrategy.DASHES);
vh6.SetLineWeight(2);

plot vh7 =  vh(7);
vh7.SetDefaultColor(globalColor("H"));
vh7.SetPaintingStrategy(PaintingStrategy.DASHES);
vh7.SetLineWeight(2);

plot vh8 =  vh(8);
vh8.SetDefaultColor(globalColor("H"));
vh8.SetPaintingStrategy(PaintingStrategy.DASHES);
vh8.SetLineWeight(2);

plot vh9 =  vh(9);
vh9.SetDefaultColor(globalColor("H"));
vh9.SetPaintingStrategy(PaintingStrategy.DASHES);
vh9.SetLineWeight(2);

plot vh10 =  vh(10);
vh10.SetDefaultColor(globalColor("H"));
vh10.SetPaintingStrategy(PaintingStrategy.DASHES);
vh10.SetLineWeight(2);
;

plot vl1 =  vl(1);
vl1.SetDefaultColor(globalColor("L"));
vl1.SetPaintingStrategy(PaintingStrategy.DASHES);
vl1.SetLineWeight(2);

plot vl2 =  vl(2);
vl2.SetDefaultColor(globalColor("L"));
vl2.SetPaintingStrategy(PaintingStrategy.DASHES);
vl2.SetLineWeight(2);

plot vl3 =  vl(3);
vl3.SetDefaultColor(globalColor("L"));
vl3.SetPaintingStrategy(PaintingStrategy.DASHES);
vl3.SetLineWeight(2);

plot vl4 =  vl(4);
vl4.SetDefaultColor(globalColor("L"));
vl4.SetPaintingStrategy(PaintingStrategy.DASHES);
vl4.SetLineWeight(2);

plot vl5 =  vl(5);
vl5.SetDefaultColor(globalColor("L"));
vl5.SetPaintingStrategy(PaintingStrategy.DASHES);
vl5.SetLineWeight(2);

plot vl6 =  vl(6);
vl6.SetDefaultColor(globalColor("L"));
vl6.SetPaintingStrategy(PaintingStrategy.DASHES);
vl6.SetLineWeight(2);

plot vl7 =  vl(7);
vl7.SetDefaultColor(globalColor("L"));
vl7.SetPaintingStrategy(PaintingStrategy.DASHES);
vl7.SetLineWeight(2);

plot vl8 =  vl(8);
vl8.SetDefaultColor(globalColor("L"));
vl8.SetPaintingStrategy(PaintingStrategy.DASHES);
vl8.SetLineWeight(2);

plot vl9 =  vl(9);
vl9.SetDefaultColor(globalColor("L"));
vl9.SetPaintingStrategy(PaintingStrategy.DASHES);
vl9.SetLineWeight(2);

plot vl10 =  vl(10);
vl10.SetDefaultColor(globalColor("L"));
vl10.SetPaintingStrategy(PaintingStrategy.DASHES);
vl10.SetLineWeight(2);
;

#Volumeprofile script with Defaults to match extended POC plots x daysback
#
# TD Ameritrade IP Company, Inc. (c) 2010-2022
#

input pricePerRowHeightMode = {AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {CHART, MINUTE, HOUR, default DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 70;
input opacity = 50;

def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
switch (timePerProfile) {
case CHART:
    period = 0;
case MINUTE:
    period = Floor(seconds / 60 + day_number * 24 * 60);
case HOUR:
    period = Floor(seconds / 3600 + day_number * 24);
case DAY:
    period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
    period = Floor(day_number / 7);
case MONTH:
    period = Floor(month - First(month));
case "OPT EXP":
    period = exp_opt - First(exp_opt);
case BAR:
    period = BarNumber() - 1;
}

def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % multiplier else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
case CUSTOM:
    height = customRowHeight;
}

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = CompoundValue(1, onExpansion, no);
def pc = if IsNaN(vol.GetPointOfControl()) and con then pc[1] else vol.GetPointOfControl();
def hVA = if IsNaN(vol.GetHighestValueArea()) and con then hVA[1] else vol.GetHighestValueArea();
def lVA = if IsNaN(vol.GetLowestValueArea()) and con then lVA[1] else vol.GetLowestValueArea();

def hProfile = if IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;

plot POC = if plotsDomain then pc else Double.NaN;
plot ProfileHigh = if plotsDomain then hProfile else Double.NaN;
plot ProfileLow = if plotsDomain then lProfile else Double.NaN;
plot VAHigh = if plotsDomain then hVA else Double.NaN;
plot VALow = if plotsDomain then lVA else Double.NaN;

DefineGlobalColor("Profile", GetColor(1));
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));

vol.Show(GlobalColor("Profile"), if showPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT, if showValueArea then GlobalColor("Value Area") else Color.CURRENT, opacity);
POC.SetDefaultColor(GlobalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(GlobalColor("Value Area"));
VALow.SetDefaultColor(GlobalColor("Value Area"));
ProfileHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh.SetDefaultColor(GetColor(3));
ProfileLow.SetDefaultColor(GetColor(3));
ProfileHigh.Hide();
ProfileLow.Hide();

#
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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