Intraday Volume Profile with Dynamic Start

billgt

New member
VIP
I am wondering if anyone has seen a volume profile study for TOS that plots intraday volume profiles but with a start based on something like a breakout of the previous range or X % price move. The built in volume profile can be used to do this on a fixed time basis but I think that is too rigid. I want something that will look to see if the price has moved out of the range of the current intraday volume profile and then start a new volume profile using the next X bars as the data. There is an indicator out there not available for TOS called TAS Boxes that looks like it will do something like this. I would be happy to pay for it but it isn't available on TOS. I have already searched UseThinkScript and didn't see anything. I am going to attempt to code this by modifying the built in volume profile but don't want to waste my time if anyone knows of something already done or that is close.

Thanks!

Bill
 

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

Thanks. I started looking at the code and very quickly ran into a roadblock. Here is the section of the code I am struggling with if anyone can assist.

Code:
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();


The start of a new profile is based on the "cond" variable. The "cond" variable in the original code is based on a new period being found such as a new minute, hour, day, etc. But my condition needs to be based on the price being higher than the current volume profile hVA which of course doesn't exist yet because we don't create the profile until after the "cond" variable is created. In some other language I would do something like the following.

def cond;
def hVA = 0;
if hVA = 0 then
cond = true;
else
if close > hVA then
cond = true;
else
cond = false;

profile vol = volumeProfile("startNewProfile" = cond, ...... etc.
hVA = if IsNaN(vol.getHighestValueArea()) and con then hVA[1] else vol.getHighestValueArea();

But in TOS there is no concept that I know of to initialize a variable in one place and then assign it again in another lower in the code. It always throws a compiler error saying that "var X has already been assigend". You can do this in Tradingview but I just don't know a way around it in TOS. Any suggestions to get around this?

Thanks!

Bill
 
Thanks. I started looking at the code and very quickly ran into a roadblock. Here is the section of the code I am struggling with if anyone can assist.

Code:
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();


The start of a new profile is based on the "cond" variable. The "cond" variable in the original code is based on a new period being found such as a new minute, hour, day, etc. But my condition needs to be based on the price being higher than the current volume profile hVA which of course doesn't exist yet because we don't create the profile until after the "cond" variable is created. In some other language I would do something like the following.

def cond;
def hVA = 0;
if hVA = 0 then
cond = true;
else
if close > hVA then
cond = true;
else
cond = false;

profile vol = volumeProfile("startNewProfile" = cond, ...... etc.
hVA = if IsNaN(vol.getHighestValueArea()) and con then hVA[1] else vol.getHighestValueArea();

But in TOS there is no concept that I know of to initialize a variable in one place and then assign it again in another lower in the code. It always throws a compiler error saying that "var X has already been assigend". You can do this in Tradingview but I just don't know a way around it in TOS. Any suggestions to get around this?

Thanks!

Bill

I just saw your request and this might give you some ideas. It assigns the variable hva and uses it in the cond portion of volumeprofile, but it is defined in a lower portion of the code( See the areas enclosed by #----). As TOS has not provided much access to the code behind the volumeprofile indicator, manipulating the cond portion of the code is about the most creative thing we can do and hope it produces what we want.

This can be quirky and you need to wait a few seconds for it to load and display as properly as possible given the above limitation.

Capture.jpg
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2010-2021
#

input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {default CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = yes;
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 hva;
def cond = close crosses above hva[1]; # 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();

#---------------------------------------------------------------------
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"));
VAHigh.SetLineWeight(2);
VALow.SetLineWeight(2);
ProfileHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh.SetDefaultColor(GetColor(3));
ProfileLow.SetDefaultColor(GetColor(3));
ProfileHigh.Hide();
ProfileLow.Hide();
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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