Previous POC, VAH, VAL, Profilehigh, and ProfileLow

AdamantBidoof

New member
Hi, I found this code
https://usethinkscript.com/threads/volume-profile-poc-plotted-forward-thinkorswim.8217/
Tweaked it a bit with my limited knowledge of copy pasta and trail and error in different time profiles. Is there a way I can add the Actual histogram of volume profile of the previous timed session?

Code:
#VolumeProfile_PreviousDay_displayed_NextDay
#20190426 Sleepyz
#20210712 Sleepyz - revised to add option for pricePerRowHeightMode rather than just automatic

input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input bubblemover = 4.0;
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
case CUSTOM:
    height = customRowHeight;
}
input timePerProfile = {CHART, MINUTE, THIRTY_MINUTES, HOUR, TWO_HOURS, FOUR_HOURS, default DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input profiles = 1000;
input showPreviousPointOfControl = yes;
input showPreviousValueArea = yes;
input valueAreaPercent = 70;
input opacity = 50;
input onExpansion = yes;

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 THIRTY_MINUTES:
    period = Floor(seconds / 1800 + day_number * 24 * 60);
case HOUR:
    period = Floor(seconds / 3600 + day_number * 24);
case TWO_HOURS:
    period = Floor(seconds / 7200 + day_number * 24);
case FOUR_HOURS:
    period = Floor(seconds / 14400 + 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];
profile vol = VolumeProfile("startNewProfile" = cond, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent, onExpansion = no);

#Prior Day High/Low ValueAreas
def HVA = if IsNaN(vol.GetHighestValueArea()) then HVA[1] else vol.GetHighestValueArea();
def pHVA = CompoundValue(1, if cond then HVA[1] else pHVA[1], Double.NaN);
def LVA = if IsNaN(vol.GetLowestValueArea()) then LVA[1] else vol.GetLowestValueArea();
def pLVA = CompoundValue(1, if cond then LVA[1] else pLVA[1], Double.NaN);
def plotsDomain = IsNaN(close) == onExpansion;

plot PrevHVA = pHVA;
plot PrevLVA = pLVA;
PrevHVA.SetDefaultColor(Color.YELLOW);
PrevLVA.SetDefaultColor(Color.YELLOW);
PrevHVA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevLVA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

AddCloud(PrevHVA , PrevLVA , Color.LIGHT_GRAY);

#Prior Day POC Calculated
def POC = if IsNaN(vol.GetPointOfControl()) and cond then POC[1] else vol.GetPointOfControl();
def pPOC = CompoundValue (1, if cond then POC[1] else pPOC[1], Double.NaN);

plot PrevPOC = pPOC;
PrevPOC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevPOC.SetDefaultColor(Color.MAGENTA);


profile volume = VolumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = CompoundValue(1, onExpansion, no);

#Prior Day highProfile/LowProfile
def hProfile = if IsNaN(vol.GetHighest()) and con then hProfile[1] else vol.GetHighest();
def php = CompoundValue(1, if cond then hProfile[1] else php[1], Double.NaN);
def lProfile = if IsNaN(vol.GetLowest()) and con then lProfile[1] else vol.GetLowest();
def plP = CompoundValue(1, if cond then lProfile[1] else plP[1], Double.NaN);

plot prevHProfile = php;
plot prevLProfile = plP;
prevHProfile.SetDefaultColor(Color.YELLOW);
prevLProfile.SetDefaultColor(Color.YELLOW);
prevHProfile.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevLProfile.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


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


vol.Show(GlobalColor("Profile"), if showPreviousPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT, if showPreviousValueArea then GlobalColor("Value Area") else Color.CURRENT, opacity);


prevPOC.SetDefaultColor(GlobalColor("Point Of Control"));
prevPOC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevHVA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevLVA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevHVA.SetDefaultColor(GlobalColor("Value Area"));
PrevLVA.SetDefaultColor(GlobalColor("Value Area"));
prevHProfile.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevLProfile.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevHProfile.SetDefaultColor(GetColor(3));
prevLProfile.SetDefaultColor(GetColor(3));
prevHProfile.Hide();
prevLProfile.Hide();

If someone can help to achieve this or tell me its not possible thats fine too haha.
Thanks for your help

@samer800 @chewie76
 
Last edited by a moderator:

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
531 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