Prior days Value Area High and Low

daytrader023042

New member
Hello all,

Not sure if what I'm looking to accomplish is possible, but thought asking you smart folks was worth a try. I am trying to build a watchlist column (5M aggregation) that will return a signal depending on how the value area high/low has changed on a daily volume profile. The code I have found below seems to correctly return todays value area high and low, as well as the prior days value area high and low. However, I would also like to pull the value area high and low for prior days as well, such as 2 days ago, 3 days ego, etc.. I don't need help setting up the signal or anything, as I've learned enough ThinkScript from this great community to take care of that part.

Currently, the following variables appear to return the correct values:
  • VAHigh -> Returns current day VAH
  • VALow -> Returns current day VAL
  • vahprev -> Returns prior day VAH
  • valprev -> Returns prior day VAL
Wondering if anyone can help out here. I'm not sure how complex this request is, but completely understand if it is outside of the scope of this forum. Thanks in advance!

Code:
# Archive Name: Volume Profile with Expanded Intraday Period Selections plus the Prior Day's Value Areas
# Archive Section: Volume
# Suggested Tos Name: VolumeProfileIntradayPeriods_Unknown
# Archive Date: 5.05.2018
# Archive Notes: found in stanL's treebase but that crashed.  Mobius found this one.

#VolumeProfile with Expanded Intraday Period Selections plus the Prior Day's Value Areas
input pricePerRowHeightMode = {AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {CHART, MINUTE, MIN2, MIN3, MIN4, MIN5, MIN10, MIN15, MIN20, MIN30, 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 = 68;
input opacity = 20; # 5.05.2018 JQ original was 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 MIN2:
    period = Floor(seconds / 120 + day_number * 24);
case MIN3:
    period = Floor(seconds / 180 + day_number * 24);
case MIN4:
    period = Floor(seconds / 240 + day_number * 24);
case MIN5:
    period = Floor(seconds / 300 + day_number * 24);
case MIN10:
    period = Floor(seconds / 600 + day_number * 24);
case MIN15:
    period = Floor(seconds / 900 + day_number * 24);
case MIN20:
    period = Floor(seconds / 1200 + day_number * 24);
case MIN30:
    period = Floor(seconds / 1800 + day_number * 24);
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 volcount = if period != period[1] then  volume  else  volcount[1]+volume;
#addlabel(yes,volcount,color.white);
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;

def POC = if plotsDomain then pc else Double.NaN;
def ProfileHigh = if plotsDomain then hProfile else Double.NaN;
def ProfileLow = if plotsDomain then lProfile else Double.NaN;
def VAHigh = if plotsDomain then hVA else Double.NaN; #Returns todays VA High
def VALow = if plotsDomain then lVA else Double.NaN; #Returns todays VA Low

#Prior Day Profile - counting formula by functionform
rec count1 = CompoundValue(1, if !(GetDay() != GetDay()[1]) then count1[1] + 1 else 1, 1);
def priorperiod = if IsNaN(count1[1]) then 1 else Max(count1, count1[1]);
profile vol1 = VolumeProfile("startNewProfile" = GetDay() != GetDay()[1], "onExpansion" = no);

def vahprior = vol1.GetHighestValueArea();
def pocprior = vol1.GetPointOfControl();
def valprior = vol1.GetLowestValueArea();

def vahprev = GetValue(vahprior, priorperiod); #Returns yesterdays VA High
def pocprev = GetValue(pocprior, priorperiod);
def valprev = GetValue(valprior, priorperiod); #Returns yesterdays VA Low
 
Hello all,

Not sure if what I'm looking to accomplish is possible, but thought asking you smart folks was worth a try. I am trying to build a watchlist column (5M aggregation) that will return a signal depending on how the value area high/low has changed on a daily volume profile. The code I have found below seems to correctly return todays value area high and low, as well as the prior days value area high and low. However, I would also like to pull the value area high and low for prior days as well, such as 2 days ago, 3 days ego, etc.. I don't need help setting up the signal or anything, as I've learned enough ThinkScript from this great community to take care of that part.

Currently, the following variables appear to return the correct values:
  • VAHigh -> Returns current day VAH
  • VALow -> Returns current day VAL
  • vahprev -> Returns prior day VAH
  • valprev -> Returns prior day VAL
Wondering if anyone can help out here. I'm not sure how complex this request is, but completely understand if it is outside of the scope of this forum. Thanks in advance!

Code:
# Archive Name: Volume Profile with Expanded Intraday Period Selections plus the Prior Day's Value Areas
# Archive Section: Volume
# Suggested Tos Name: VolumeProfileIntradayPeriods_Unknown
# Archive Date: 5.05.2018
# Archive Notes: found in stanL's treebase but that crashed.  Mobius found this one.

#VolumeProfile with Expanded Intraday Period Selections plus the Prior Day's Value Areas
input pricePerRowHeightMode = {AUTOMATIC, default TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {CHART, MINUTE, MIN2, MIN3, MIN4, MIN5, MIN10, MIN15, MIN20, MIN30, 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 = 68;
input opacity = 20; # 5.05.2018 JQ original was 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 MIN2:
    period = Floor(seconds / 120 + day_number * 24);
case MIN3:
    period = Floor(seconds / 180 + day_number * 24);
case MIN4:
    period = Floor(seconds / 240 + day_number * 24);
case MIN5:
    period = Floor(seconds / 300 + day_number * 24);
case MIN10:
    period = Floor(seconds / 600 + day_number * 24);
case MIN15:
    period = Floor(seconds / 900 + day_number * 24);
case MIN20:
    period = Floor(seconds / 1200 + day_number * 24);
case MIN30:
    period = Floor(seconds / 1800 + day_number * 24);
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 volcount = if period != period[1] then  volume  else  volcount[1]+volume;
#addlabel(yes,volcount,color.white);
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;

def POC = if plotsDomain then pc else Double.NaN;
def ProfileHigh = if plotsDomain then hProfile else Double.NaN;
def ProfileLow = if plotsDomain then lProfile else Double.NaN;
def VAHigh = if plotsDomain then hVA else Double.NaN; #Returns todays VA High
def VALow = if plotsDomain then lVA else Double.NaN; #Returns todays VA Low

#Prior Day Profile - counting formula by functionform
rec count1 = CompoundValue(1, if !(GetDay() != GetDay()[1]) then count1[1] + 1 else 1, 1);
def priorperiod = if IsNaN(count1[1]) then 1 else Max(count1, count1[1]);
profile vol1 = VolumeProfile("startNewProfile" = GetDay() != GetDay()[1], "onExpansion" = no);

def vahprior = vol1.GetHighestValueArea();
def pocprior = vol1.GetPointOfControl();
def valprior = vol1.GetLowestValueArea();

def vahprev = GetValue(vahprior, priorperiod); #Returns yesterdays VA High
def pocprev = GetValue(pocprior, priorperiod);
def valprev = GetValue(valprior, priorperiod); #Returns yesterdays VA Low

This might help get what you want. https://usethinkscript.com/threads/volume-profile-indicator-pocs-for-thinkorswim.8153/post-140443
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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