Anchored Volume Profile between two times and corresponding dates

shakib3585

Active member
Hello,

I was watching the volume profile in NinjaTrader, where Trader Dale was demonstrating a volume profile based on a fixed start and end point. I was hoping if it was possible to make a similar script for thinkorswim, the volume profile can be anchored and ended between two specific dates and times. For example, the script would be able to start an anchor at a specific time and date and also will be able to have ended at another time and date. Please help if it is possible.

Thank you very much
 
Solution
Hello,

I was watching the volume profile in NinjaTrader, where Trader Dale was demonstrating a volume profile based on a fixed start and end point. I was hoping if it was possible to make a similar script for thinkorswim, the volume profile can be anchored and ended between two specific dates and times. For example, the script would be able to start an anchor at a specific time and date and also will be able to have ended at another time and date. Please help if it is possible.

Thank you very much

Much better updated version in post #6 https://usethinkscript.com/threads/...mes-and-corresponding-dates.21151/post-156022

Enter dates and times to anchor volumeprofile. These must be...
Hello,

I was watching the volume profile in NinjaTrader, where Trader Dale was demonstrating a volume profile based on a fixed start and end point. I was hoping if it was possible to make a similar script for thinkorswim, the volume profile can be anchored and ended between two specific dates and times. For example, the script would be able to start an anchor at a specific time and date and also will be able to have ended at another time and date. Please help if it is possible.

Thank you very much

Much better updated version in post #6 https://usethinkscript.com/threads/...mes-and-corresponding-dates.21151/post-156022

Enter dates and times to anchor volumeprofile. These must be visible on the chart.
Code:
#VolumeProfile_Choice_of_Displaying_Input_Dates_Times
#Dates and Times must show on chart
#

input startdate   = 20250715;
input enddate     = 20250717;

input starttime   = 1000;
input endtime     = 0900;

input show_profilehigh_low = yes;

#Show vol profile will display the profile area when set to yes. However, since we have no control over the function vol.show, the profile for the area beyond the selected dates/times will also display. Therefore the default is set to no.
input show_vol_profile     = no;

input show_label           = yes;
AddLabel(show_label, "VolProfile: " + AsPrice(startdate) + " at " + AsPrice(starttime) + " to " + AsPrice(enddate) + " at " + AsPrice(endtime), Color.YELLOW);

input pricePerRowHeightMode = {AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input onExpansion = no;
input profiles = 2;
input showPointOfControl = yes;
input showValueArea = no;
input valueAreaPercent = 70;
input opacity = 50;

def na = Double.NaN;
def tz = CompoundValue(1, if GetYYYYMMDD() == startdate and GetYYYYMMDD() <= enddate and SecondsFromTime(starttime) == 0 then 1 else if tz[1] == 1 and GetYYYYMMDD() < enddate then 1 else if tz[1] == 1 and GetYYYYMMDD() == enddate and SecondsFromTime(endtime) <= 0 then 1 else 0, 0);

def zone = 1;
def cond = tz != tz[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 pc  = if IsNaN(vol.GetPointOfControl()) then pc[1] else vol.GetPointOfControl();
def hVA = if IsNaN(vol.GetHighestValueArea()) then hVA[1] else vol.GetHighestValueArea();
def lVA = if IsNaN(vol.GetLowestValueArea()) then lVA[1] else vol.GetLowestValueArea();

def hProfile = if IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest()) then lProfile[1] else vol.GetLowest();

def POC_         = if tz == zone then pc else na;
def ProfileHigh_ = if tz == zone then hProfile else na;
def ProfileLow_  = if tz == zone then lProfile else na;
def VAHigh_      = if tz == zone then hVA else na;
def VALow_       = if tz == zone then lVA else na;

plot POC = POC_;
plot VAHigh = VAHigh_;
plot VALow = VALow_;
plot ProfileHigh = if !show_profilehigh_low then na else ProfileHigh_;
plot ProfileLow = if !show_profilehigh_low then na else ProfileLow_;

DefineGlobalColor("Profile", Color.GRAY);
DefineGlobalColor("Point Of Control", Color.RED);
DefineGlobalColor("Value Area", Color.GRAY);

vol.Show(if show_vol_profile then GlobalColor("Profile") else Color.CURRENT);#, 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));

input bubbles = yes;
input n  = 6;
AddChartBubble(bubbles and tz[n] == 1 and tz[n - 1] == 0, VAHigh[n], "VAH", Color.YELLOW, yes);
AddChartBubble(bubbles and tz[n] == 1 and tz[n - 1] == 0, VALow[n], "VAL", Color.YELLOW, no);
AddChartBubble(bubbles and tz[n] == 1 and tz[n - 1] == 0, POC[n], "POC", Color.RED, no);

#
To display the profile lines only as in the image below, input show_vol_profile set to = no;
Screenshot 2025-07-20 101904.jpg
To display the Gray shaded profile with lines as in the image below, input show_vol_profile set to = yes;
 
Last edited:
Solution

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

Enter dates and times to anchor volumeprofile. These must be visible on the chart.

To display the profile lines only as in the image below, input show_vol_profile set to = no;

To display the Gray shaded profile with lines as in the image below, input show_vol_profile set to = yes;
Nice idea, but I am testing this and it doesn't seem to work too well for the following reasons:
1) the POC, VAL and VAH do not show on intraday charts defeating the purpose of the time bounds
2) when you switch to intraday it does not respect the time bound (dates)and it plots the histogram for the chart instead
 
Nice idea, but I am testing this and it doesn't seem to work too well for the following reasons:
1) the POC, VAL and VAH do not show on intraday charts defeating the purpose of the time bounds
2) when you switch to intraday it does not respect the time bound (dates)and it plots the histogram for the chart instead
The above code works as requested. See the images within an intraday chart with the lines.
It will only work if as stated above if:
"Enter dates and times to anchor volumeprofile. These must be visible on the chart."
 
Very interesting, and tried to show 1) the POC during the regular session: successful; 2) the POC in the extended session: although the input of the end time set to 20250814 09:30, POC is

@SleepyZ

truncated at 20250813 1700. Is my setup wrong? If setup is right, how to display the POC over the whole extend session?
1755354152416.png


The above has the settings below:
1755354268940.png
 
Last edited by a moderator:
Very interesting, and tried to show 1) the POC during the regular session: successful; 2) the POC in the extended session: although the input of the end time set to 20250814 09:30, POC is

@SleepyZ

truncated at 20250813 1700. Is my setup wrong? If setup is right, how to display the POC over the whole extend session?
View attachment 25481

The above has the settings below:
View attachment 25482

I have modified this to work more consistently. It should now work as you requested.

Code:
#VolumeProfile_Choice_of_Displaying_Input_Dates_Times_v1
#Dates and Times must show on chart
#

input startdate   = 20250826;
input enddate     = 20250827;

input starttime   = 1600;
input endtime     = 0930;

input show_profilehigh_low = yes;

#Show vol profile will display the profile area when set to yes. However, since we have no control over the function vol.show, the profile for the area beyond the selected dates/times will also display. Therefore the default is set to no.
input show_vol_profile     = no;

input show_label           = yes;
AddLabel(show_label, "VolProfile: " + AsPrice(startdate) + " at " + AsPrice(starttime) + " to " + AsPrice(enddate) + " at " + AsPrice(endtime), Color.YELLOW);

input pricePerRowHeightMode = {AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input onExpansion = no;
input profiles = 2;
input showPointOfControl = yes;
input showValueArea = no;
input valueAreaPercent = 70;
input opacity = 50;

def na = Double.NaN;
def bn = BarNumber();
def begin = if GetYYYYMMDD() == startdate and SecondsFromTime(starttime)[1] < 0 and SecondsFromTime(starttime) >= 0 then bn else na;
def end   = if GetYYYYMMDD() == enddate and SecondsFromTime(endtime)[1] < 0 and SecondsFromTime(endtime) >= 0 then bn else na;
def tz = Between(bn, HighestAll(begin), HighestAll(end));

def zone = 1;
def cond = tz != tz[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 pc  = if IsNaN(vol.GetPointOfControl()) then pc[1] else vol.GetPointOfControl();
def hVA = if IsNaN(vol.GetHighestValueArea()) then hVA[1] else vol.GetHighestValueArea();
def lVA = if IsNaN(vol.GetLowestValueArea()) then lVA[1] else vol.GetLowestValueArea();

def hProfile = if IsNaN(vol.GetHighest()) then hProfile[1] else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest()) then lProfile[1] else vol.GetLowest();

def POC_         = if tz == zone then pc else na;
def ProfileHigh_ = if tz == zone then hProfile else na;
def ProfileLow_  = if tz == zone then lProfile else na;
def VAHigh_      = if tz == zone then hVA else na;
def VALow_       = if tz == zone then lVA else na;

plot POC = POC_;
plot VAHigh = VAHigh_;
plot VALow = VALow_;
plot ProfileHigh = if !show_profilehigh_low then na else ProfileHigh_;
plot ProfileLow = if !show_profilehigh_low then na else ProfileLow_;

DefineGlobalColor("Profile", Color.GRAY);
DefineGlobalColor("Point Of Control", Color.RED);
DefineGlobalColor("Value Area", Color.GRAY);

vol.Show(if show_vol_profile then GlobalColor("Profile") else Color.CURRENT);#, 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));

input bubbles = yes;
input n  = 6;
AddChartBubble(bubbles and tz[n] == 1 and tz[n - 1] == 0, VAHigh[n], "VAH", Color.YELLOW, yes);
AddChartBubble(bubbles and tz[n] == 1 and tz[n - 1] == 0, VALow[n], "VAL", Color.YELLOW, no);
AddChartBubble(bubbles and tz[n] == 1 and tz[n - 1] == 0, POC[n], "POC", Color.RED, no);

#
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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