Volume Profile Indicator & POCs For ThinkOrSwim

halcyonguy

Well-known member
VIP
@halcyonguy

Hey, I apologize for bumping an old thread and pinging you here, but I was wondering if you ever got around to figuring out OP/your own study? I too am doing something similar to OP's original query - basically wanting to plot levels of significance (high, low, POCs of day bars) dating back from two Sundays ago to current. For example, if today is Monday (8/23), then ideally, the study would be plotting levels up to the second previous Sunday (8/15) on today's chart. However, I'm not quite sure how to even approach this. I started by trying to define the Sunday as an offset to input in the look back of the variable, but quickly learned thats not how it worked. A friend of mine, though not familiar with thinkscript, told me that a fold function might work. I looked into this on ToS' TLC website and from what I can tell, if I define the days as numbers with Sunday being the start, it could loop until the 14th day? I'm not even sure if that makes sense.

If possible, any help and/or advice here is greatly appreciated. Again, sorry to ping and bump this old thread.

Couch.

@ktrades sorry i haven't posted up my code yet. i tend to take on new challenges sometimes before i finish up existing ones. i've come across a couple of posts, where people say it can't be done, so i figure out how to.
i just posted a mvp study. tomorrow i will look at my to do list of a half dozen or so studies i am in the middle of, and try to finish them up. i will get back to this.

@ComfyCouch see above. it's late, i will read your post in the morning
 

halcyonguy

Well-known member
VIP
@halcyonguy

Hey, I apologize for bumping an old thread and pinging you here, but I was wondering if you ever got around to figuring out OP/your own study? I too am doing something similar to OP's original query - basically wanting to plot levels of significance (high, low, POCs of day bars) dating back from two Sundays ago to current. For example, if today is Monday (8/23), then ideally, the study would be plotting levels up to the second previous Sunday (8/15) on today's chart. However, I'm not quite sure how to even approach this. I started by trying to define the Sunday as an offset to input in the look back of the variable, but quickly learned thats not how it worked. A friend of mine, though not familiar with thinkscript, told me that a fold function might work. I looked into this on ToS' TLC website and from what I can tell, if I define the days as numbers with Sunday being the start, it could loop until the 14th day? I'm not even sure if that makes sense.

If possible, any help and/or advice here is greatly appreciated. Again, sorry to ping and bump this old thread.

Couch.

is this what you are asking ?

do you want to look at an intra day chart,
and only on the current day,
see 28+ lines,
based from high and low levels from the days in the past 14+ days?
i'm ignoring poc for now....

...wanting to plot levels of significance (high, low, POCs of day bars)
...dating back from two Sundays ago to current.
...the study would be plotting levels up to the second previous Sunday (8/15) ,

this will need 28+ plot functions and supportive formulas.
 
Last edited:

halcyonguy

Well-known member
VIP
@halcyonguy

Hey, I apologize for bumping an old thread and pinging you here, but I was wondering if you ever got around to figuring out OP/your own study? I too am doing something similar to OP's original query - basically wanting to plot levels of significance (high, low, POCs of day bars) dating back from two Sundays ago to current. For example, if today is Monday (8/23), then ideally, the study would be plotting levels up to the second previous Sunday (8/15) on today's chart. However, I'm not quite sure how to even approach this. I started by trying to define the Sunday as an offset to input in the look back of the variable, but quickly learned thats not how it worked. A friend of mine, though not familiar with thinkscript, told me that a fold function might work. I looked into this on ToS' TLC website and from what I can tell, if I define the days as numbers with Sunday being the start, it could loop until the 14th day? I'm not even sure if that makes sense.

If possible, any help and/or advice here is greatly appreciated. Again, sorry to ping and bump this old thread.

Couch.
here is a study to plot high low levels from the past 5 days, onto just the current day

Code:
# prev5dayslevels_01

# get hi low levels from prev 5 days
# display lines on current day

def na = Double.NaN;
def istoday = if GetLastDay() == GetDay() then 1 else 0;

input timeFrame = AggregationPeriod.DAY;

def hi1 = high(period = timeFrame)[1];
def lo1 = low(period = timeFrame)[1];
def hi2 = high(period = timeFrame)[2];
def lo2 = low(period = timeFrame)[2];
def hi3 = high(period = timeFrame)[3];
def lo3 = low(period = timeFrame)[3];
def hi4 = high(period = timeFrame)[4];
def lo4 = low(period = timeFrame)[4];
def hi5 = high(period = timeFrame)[5];
def lo5 = low(period = timeFrame)[5];

plot hh1 = if istoday then hi1 else na;
plot ll1 = if istoday then lo1 else na;
plot hh2 = if istoday then hi2 else na;
plot ll2 = if istoday then lo2 else na;
plot hh3 = if istoday then hi3 else na;
plot ll3 = if istoday then lo3 else na;
plot hh4 = if istoday then hi4 else na;
plot ll4 = if istoday then lo4 else na;
plot hh5 = if istoday then hi5 else na;
plot ll5 = if istoday then lo5 else na;

hh1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

hh1.SetDefaultColor(Color.light_green);
ll1.SetDefaultColor(Color.light_red);
hh2.SetDefaultColor(Color.light_green);
ll2.SetDefaultColor(Color.light_red);
hh3.SetDefaultColor(Color.light_green);
ll3.SetDefaultColor(Color.light_red);
hh4.SetDefaultColor(Color.light_green);
ll4.SetDefaultColor(Color.light_red);
hh5.SetDefaultColor(Color.light_green);
ll5.SetDefaultColor(Color.light_red);
#
 

ComfyCouch

New member
is this what you are asking ?

do you want to look at an intra day chart,
and only on the current day,
see 28+ lines,
based from high and low levels from the days in the past 14+ days?
i'm ignoring poc for now....

...wanting to plot levels of significance (high, low, POCs of day bars)
...dating back from two Sundays ago to current.
...the study would be plotting levels up to the second previous Sunday (8/15) ,

this will need 28+ plot functions and supportive formulas.

Thanks for the reply halcyonguy. That is pretty much what I'm asking. Just to clarify, that holds true for when it is Sunday. However, once it becomes Monday, the plotted lines would reset to plot horizontal levels (for high/low/POC) up to the second previous Sunday, and as a new day begins, the previous day is added. So for example, if today is Monday, it would plot levels from the second previous Sunday (In total, would include 8 days (excluding saturday and including the two sundays & current Monday). Similarly, if it is now Tuesday, then it would plot levels up to 9 days and so on and so forth.

here is a study to plot high low levels from the past 5 days, onto just the current day

Code:
# prev5dayslevels_01

# get hi low levels from prev 5 days
# display lines on current day

def na = Double.NaN;
def istoday = if GetLastDay() == GetDay() then 1 else 0;

input timeFrame = AggregationPeriod.DAY;

def hi1 = high(period = timeFrame)[1];
def lo1 = low(period = timeFrame)[1];
def hi2 = high(period = timeFrame)[2];
def lo2 = low(period = timeFrame)[2];
def hi3 = high(period = timeFrame)[3];
def lo3 = low(period = timeFrame)[3];
def hi4 = high(period = timeFrame)[4];
def lo4 = low(period = timeFrame)[4];
def hi5 = high(period = timeFrame)[5];
def lo5 = low(period = timeFrame)[5];

plot hh1 = if istoday then hi1 else na;
plot ll1 = if istoday then lo1 else na;
plot hh2 = if istoday then hi2 else na;
plot ll2 = if istoday then lo2 else na;
plot hh3 = if istoday then hi3 else na;
plot ll3 = if istoday then lo3 else na;
plot hh4 = if istoday then hi4 else na;
plot ll4 = if istoday then lo4 else na;
plot hh5 = if istoday then hi5 else na;
plot ll5 = if istoday then lo5 else na;

hh1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

hh1.SetDefaultColor(Color.light_green);
ll1.SetDefaultColor(Color.light_red);
hh2.SetDefaultColor(Color.light_green);
ll2.SetDefaultColor(Color.light_red);
hh3.SetDefaultColor(Color.light_green);
ll3.SetDefaultColor(Color.light_red);
hh4.SetDefaultColor(Color.light_green);
ll4.SetDefaultColor(Color.light_red);
hh5.SetDefaultColor(Color.light_green);
ll5.SetDefaultColor(Color.light_red);
#

I really appreciate your time and help with my query, so I thank you very much. Truly.

I've gone and tried to code what I meant to do above by using your code as a template. However, I'm stuck in a position where if I want to only plot the current day, it lets me, but when I try to bundle it with plotting the previous days, not only does it not show the POCs of the previous days, but it plots the POC line for each previous day as 1.

For example, in the code below, I start with Monday and attempt to plot the previous days POC up to the second Sunday. If I keep
Code:
plot MondayPoc = if TodayIsMonday then TodayMondayPOC else na;
then it correctly plots all Monday POCs in the timeframe. However, if I keep
Code:
plot MondayPoc = if TodayIsMonday then TodayMondayPOC and TodayIsMonSun and TodayisMonFri and TodayisMonThurs and TodayisMonWed and TodayisMonTues and TodayisMonMon and TodayisMonSunSun else na;
,
it plots all Monday POCs as 1 and does not plot any of the previous days POC.

Here's the code; please bare with me, I'm very new to thinkscript and have been trying my best.

Code:
def yyyymmdd = GetYYYYMMDD(); 
def na = Double.Nan;

#Getting POC
def RTHBegin = 930;
def RTHEnd = 1600;
def RTH = SecondsFromTime(RthBegin) >= 0 and SecondsTillTime(RthEnd) >= 0; 
def cond2 = RTH != RTH[1];
profile tpo = TimeProfile("PricePerRow" = PricePerRow.Ticksize, "startNewProfile" = cond2, "onExpansion" = no);

#Defining Days of Week (credit to Mobius)
def DOW2 = getdayOfWeek(getYYYYMMDD());
def Mon = if DOW2 == 1 then 1 else 0;
def Tues = if DOW2 == 2 then 1 else 0;
def Wed = if DOW2 == 3 then 1 else 0;
def Thurs = if DOW2 == 4 then 1 else 0;
def Fri = if DOW2 == 5 then 1 else 0;
def Sat = if DOW2 == 6 then 1 else 0;
def Sun = if DOW2 == 7 then 1 else 0;

def TodayIsMonday = Mon;
def TodayMondayPoc = tpo.GetPointofControl(); #GetMondaysPOC.
def TodayIsMonSun = TodayMondayPoc[1]; #This should be prev Sunday's POC.
def TodayIsMonFri = TodayIsMonSun[1]; #This should be prev Friday's POC.
def TodayIsMonThurs = TodayIsMonFri[1]; #This should be prev Thursday's POC.
def TodayIsMonWed = TodayIsMonThurs[1]; #This should be prev Wednesday's POC.
def TodayisMonTues = TodayIsMonWed[1]; #This should be prev Tuesday's POC.
def TodayisMonMon = TodayIsMonTues[1]; #This should be prev Monday's POC.
def TodayisMonSunSun = TodayIsMonMon[1]; #And lastly, this should be the second prev Sunday's POC.
#plot MondayPoc = if TodayIsMonday then TodayMondayPOC else na; #This only plots Monday's POC.
plot MondayPoc = if TodayIsMonday then TodayMondayPOC and TodayIsMonSun and TodayisMonFri and TodayisMonThurs and TodayisMonWed and TodayisMonTues and TodayisMonMon and TodayisMonSunSun else na; #This should be plotting the POCs of Monday all the way to the second previous sunday.
 
mondayPoc.SetPaintingStrategy(PaintingStrategy.Horizontal);
mondayPoc.SetDefaultColor(Color.Orange);
 

halcyonguy

Well-known member
VIP
Thanks for the reply halcyonguy. That is pretty much what I'm asking. Just to clarify, that holds true for when it is Sunday. However, once it becomes Monday, the plotted lines would reset to plot horizontal levels (for high/low/POC) up to the second previous Sunday, and as a new day begins, the previous day is added. So for example, if today is Monday, it would plot levels from the second previous Sunday (In total, would include 8 days (excluding saturday and including the two sundays & current Monday). Similarly, if it is now Tuesday, then it would plot levels up to 9 days and so on and so forth.



I really appreciate your time and help with my query, so I thank you very much. Truly.

I've gone and tried to code what I meant to do above by using your code as a template. However, I'm stuck in a position where if I want to only plot the current day, it lets me, but when I try to bundle it with plotting the previous days, not only does it not show the POCs of the previous days, but it plots the POC line for each previous day as 1.

For example, in the code below, I start with Monday and attempt to plot the previous days POC up to the second Sunday. If I keep
Code:
plot MondayPoc = if TodayIsMonday then TodayMondayPOC else na;
then it correctly plots all Monday POCs in the timeframe. However, if I keep
Code:
plot MondayPoc = if TodayIsMonday then TodayMondayPOC and TodayIsMonSun and TodayisMonFri and TodayisMonThurs and TodayisMonWed and TodayisMonTues and TodayisMonMon and TodayisMonSunSun else na;
,
it plots all Monday POCs as 1 and does not plot any of the previous days POC.

Here's the code; please bare with me, I'm very new to thinkscript and have been trying my best.

Code:
def yyyymmdd = GetYYYYMMDD();
def na = Double.Nan;

#Getting POC
def RTHBegin = 930;
def RTHEnd = 1600;
def RTH = SecondsFromTime(RthBegin) >= 0 and SecondsTillTime(RthEnd) >= 0;
def cond2 = RTH != RTH[1];
profile tpo = TimeProfile("PricePerRow" = PricePerRow.Ticksize, "startNewProfile" = cond2, "onExpansion" = no);

#Defining Days of Week (credit to Mobius)
def DOW2 = getdayOfWeek(getYYYYMMDD());
def Mon = if DOW2 == 1 then 1 else 0;
def Tues = if DOW2 == 2 then 1 else 0;
def Wed = if DOW2 == 3 then 1 else 0;
def Thurs = if DOW2 == 4 then 1 else 0;
def Fri = if DOW2 == 5 then 1 else 0;
def Sat = if DOW2 == 6 then 1 else 0;
def Sun = if DOW2 == 7 then 1 else 0;

def TodayIsMonday = Mon;
def TodayMondayPoc = tpo.GetPointofControl(); #GetMondaysPOC.
def TodayIsMonSun = TodayMondayPoc[1]; #This should be prev Sunday's POC.
def TodayIsMonFri = TodayIsMonSun[1]; #This should be prev Friday's POC.
def TodayIsMonThurs = TodayIsMonFri[1]; #This should be prev Thursday's POC.
def TodayIsMonWed = TodayIsMonThurs[1]; #This should be prev Wednesday's POC.
def TodayisMonTues = TodayIsMonWed[1]; #This should be prev Tuesday's POC.
def TodayisMonMon = TodayIsMonTues[1]; #This should be prev Monday's POC.
def TodayisMonSunSun = TodayIsMonMon[1]; #And lastly, this should be the second prev Sunday's POC.
#plot MondayPoc = if TodayIsMonday then TodayMondayPOC else na; #This only plots Monday's POC.
plot MondayPoc = if TodayIsMonday then TodayMondayPOC and TodayIsMonSun and TodayisMonFri and TodayisMonThurs and TodayisMonWed and TodayisMonTues and TodayisMonMon and TodayisMonSunSun else na; #This should be plotting the POCs of Monday all the way to the second previous sunday.
 
mondayPoc.SetPaintingStrategy(PaintingStrategy.Horizontal);
mondayPoc.SetDefaultColor(Color.Orange);

please reread post #123 , where i said
this will need 28+ plot functions and supportive formulas. ( for 2 lines a day)

for every line you want to see on 1 day, you need a separate plot function.

i don't know know why you want to look for data for saturday and sunday,, .. but i will include them in the max day count.
if you want 3 lines plotted, from up to 14 previous days , that will be 42 plot functions and 42 sets of supporting formulas.
the 42 sets of formulas, can be somewhat simplified with script { }.
 
Last edited:

ComfyCouch

New member
please reread post #6 , where i said
this will need 28+ plot functions and supportive formulas. ( for 2 lines a day)

for every line you want to see on 1 day, you need a separate plot function.

i don't know know why you want to look for data for saturday and sunday,, .. but i will include them in the max day count.
if you want 3 lines plotted, from up to 14 previous days , that will be 42 plot functions and 42 sets of supporting formulas.
the 42 sets of formulas, can be somewhat simplified with script { }.

Thanks for the reply. I think I understand what you mean now. Instead of this line:

Code:
plot MondayPoc = if TodayIsMonday then TodayMondayPOC and TodayIsMonSun and TodayisMonFri and TodayisMonThurs and TodayisMonWed and TodayisMonTues and TodayisMonMon and TodayisMonSunSun else na;

it should instead be broken into separate plots, as you stated, like:

Code:
plot MondayPoc = if TodayIsMonday then TodayMondayPOC else na;
plot MondaySunPoc = if TodayisMonday then TodayisMonSun else na;
plot MondayFriPoc = if TodayisMonday then TodayIsMonFri else na;

and each other day that I'd like to reference would have its separate plot.

That makes a lot more sense. I just tested it out as well and it works out very nicely. I'd just need to extend the lines over to whatever current day it is.

i don't know know why want to look for data for saturday and sunday

Sorry, I should've clarified above. I mostly trade index futures and sometimes trade on Sunday globex hours, and similarly, use the POC/High/Low of those globex hours in intraday charts. As for Saturday, I agree, I would not want data from that day.
 

ComfyCouch

New member
Since posting this, I've gone ahead and tried to code a test run for the whole week. The idea is to first, define the current day as Monday. From there, each corresponding previous day is defined as the 1 lookback to the day ahead. Working, it should plot a POC line on each day for the past week from the current day. However, from the chart, it only plots a POC line on each Monday. I've attached an image below.



Here's the code below:
Code:
def yyyymmdd = GetYYYYMMDD();
def na = Double.Nan;

#Getting POC
def RTHBegin = 930;
def RTHEnd = 1600;
def RTH = SecondsFromTime(RthBegin) >= 0 and SecondsTillTime(RthEnd) >= 0;
def cond2 = RTH != RTH[1];
profile tpo = TimeProfile("PricePerRow" = PricePerRow.Ticksize, "startNewProfile" = cond2, "onExpansion" = no);

#Defining Days of Week (credit to Mobius)
def DOW2 = getdayOfWeek(getYYYYMMDD());
def Mon = if DOW2 == 1 then 1 else 0;
def Tues = if DOW2 == 2 then 1 else 0;
def Wed = if DOW2 == 3 then 1 else 0;
def Thurs = if DOW2 == 4 then 1 else 0;
def Fri = if DOW2 == 5 then 1 else 0;
def Sat = if DOW2 == 6 then 1 else 0;
def Sun = if DOW2 == 7 then 1 else 0;


def TodayIsMonday = Mon;
def StartingMonday = tpo.GetPointofControl();
def PreviousSunday = StartingMonday[1];
def PreviousFriday = PreviousSunday[1];
def PreviousThursday = PreviousFriday[1];
def PreviousWednesday = PreviousThursday[1];
def PreviousTuesday = PreviousWednesday[1];
def PreviousMonday = PreviousTuesday[1];
def SecondPreviousSunday = PreviousMonday[1];

#Plots for Current Monday.
plot StartingMondayPOC = if TodayIsMonday then StartingMonday else na;
plot PreviousSundayPOC = if TodayIsMonday then PreviousSunday else na;
plot PreviousFridayPOC = if TodayIsMonday then PreviousFriday else na;
plot PreviousThursdayPOC = if TodayIsMonday then PreviousThursday else na;
plot PreviousWednesdayPOC = if TodayIsMonday then PreviousWednesday else na;
plot PreviousTuesdayPOC = if TodayIsMonday then PreviousTuesday else na;
plot PreviousMondayPOC = if TodayIsMonday then PreviousMonday else na;
plot SecondPreviousSundayPOC = if TodayIsMonday then PreviousSunday else na;
StartingMondayPOC.SetPaintingStrategy(PaintingStrategy.Horizontal);
StartingMondayPOC.SetDefaultColor(Color.Orange);
PreviousSundayPOC.SetPaintingStrategy(PaintingStrategy.Horizontal);
PreviousSundayPOC.SetDefaultColor(Color.Orange);
PreviousFridayPOC.SetPaintingStrategy(PaintingStrategy.Horizontal);
PreviousFridayPOC.SetDefaultColor(Color.Orange);
PreviousThursdayPOC.SetPaintingStrategy(PaintingStrategy.Horizontal);
PreviousThursdayPOC.SetDefaultColor(Color.Orange);
PreviousWednesdayPOC.SetPaintingStrategy(PaintingStrategy.Horizontal);
PreviousWednesdayPOC.SetDefaultColor(Color.Orange);
PreviousTuesdayPOC.SetPaintingStrategy(PaintingStrategy.Horizontal);
PreviousTuesdayPOC.SetDefaultColor(Color.Orange);
PreviousMondayPOC.SetPaintingStrategy(PaintingStrategy.Horizontal);
PreviousMondayPOC.SetDefaultColor(Color.Orange);
SecondPreviousSundayPOC.SetPaintingStrategy(PaintingStrategy.Horizontal);
SecondPreviousSundayPOC.SetDefaultColor(Color.Orange);

Do I have to manually define each if statement in the plots as their days? For example, in PreviousFridayPOC, do I have to replace "TodayIsMonday" as "Fri" instead?

It looks as if I do the above, it does work but it also plots it for all Fridays in the timeframe in addition to the Mondays.

Going off your post as number 6, using that same logic, where you plot the past five days from today, would it be possible to define "today" as a specific day? I tried to do
Code:
def istoday = if GetLastDay() == GetDay() then 1 else 0; 
def TodayIsMonday = istoday == Mon;

but that did not work the way I intended to.

As always, thanks for your continued help.
 

halcyonguy

Well-known member
VIP
i hope this will help get you closer to what you want

referencing your code in post 11

your code only has a line on 1 day of the week
all lines are the same level
it wasn't storing the poc value for 7 days correctly.

this doesnt work with ext hours off.
def RTH = SecondsFromTime(RthBegin) >= 0 and SecondsTillTime(RthEnd) >= 0;
def cond2 = RTH != RTH[1];

--------------------

my changes
changed the mon, tues,wed,... formulas, so they hold a poc value, not true/false.

used this to determine when a new day occurs. it works when ext hours are off.
def gtdy = GetDay();
def diffday = if GtDy[1] <> GetDay() then 1 else 0;

assigned different colors for each day line


Ruby:
# prevweekdata_00b

# plot 5 (or 7 depending on decurity) poc lines , for the past 7 days

# post11
# https://usethinkscript.com/threads/only-show-friday-charts.5588/#post-74389
# https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Profiles/TimeProfile

def yyyymmdd = GetYYYYMMDD();
def na = Double.Nan;
#def istoday = if GetLastDay() == GetDay() then 1 else 0;


#Defining Days of Week (credit to Mobius)
def DOW2 = getdayOfWeek(getYYYYMMDD());

# test data, show day # of week , 1-7
input test_show_days = no;
addchartbubble(test_show_days, high*1.01, dow2, color.light_gray, yes);

# is the current bar on a different day, than prev bar ?  (first bar of day)
# this works with ext hours off
def gtdy = GetDay();
def diffday = if GtDy[1] <> GetDay() then 1 else 0;

input test_show_first_day_bar = no;
addchartbubble( test_show_first_day_bar and diffday, low*0.99, dow2, color.light_gray, no);

# test , plot spikes when diffday is true , first bar of the day. works with ext hours off
#plot g = if diffday then close else (close *0.9);
#g.setDefaultColor(Color.green);


#Getting POC
def RTHBegin = 930;
def RTHEnd = 1600;
# not used
#def RTH = SecondsFromTime(RthBegin) >= 0 and SecondsTillTime(RthEnd) >= 0;
# this doesnt work with ext hours off
#def cond2 = RTH != RTH[1];

#profile tpo = TimeProfile("PricePerRow" = PricePerRow.Ticksize, "startNewProfile" = cond2, "onExpansion" = no);
profile tpo = TimeProfile("PricePerRow" = PricePerRow.Ticksize, "startNewProfile" = diffday, "onExpansion" = no);
def tpopoc =  tpo.GetPointofControl();

# plot spikes when cond2 is true, first bar of the day. does not  work with ext hours off
#plot f = if cond2 then close else ( close *0.9);
#f.setDefaultColor(Color.cyan);


# assign a value for the day, and keep it till the same day next week
def Mon = if DOW2 == 1 then tpopoc else mon[1];
def Tues = if DOW2 == 2 then tpopoc else tues[1];
def Wed = if DOW2 == 3 then tpopoc else wed[1];
def Thur = if DOW2 == 4 then tpopoc else thur[1];
def Fri = if DOW2 == 5 then tpopoc else fri[1];
def Sat = if DOW2 == 6 then tpopoc else sat[1];
def Sun = if DOW2 == 7 then tpopoc else sun[1];

plot monx = mon;
plot tuesx = tues;
plot wedx = wed;
plot thurx = thur;
plot frix = fri;
plot satx = sat;
plot sunx = sun;

monx.SetPaintingStrategy(PaintingStrategy.Horizontal);
tuesx.SetPaintingStrategy(PaintingStrategy.Horizontal);
wedx.SetPaintingStrategy(PaintingStrategy.Horizontal);
thurx.SetPaintingStrategy(PaintingStrategy.Horizontal);
frix.SetPaintingStrategy(PaintingStrategy.Horizontal);
satx.SetPaintingStrategy(PaintingStrategy.Horizontal);
sunx.SetPaintingStrategy(PaintingStrategy.Horizontal);

#monx.setDefaultColor(Color.Orange);
#tuesx.setDefaultColor(Color.Orange);
#wedx.setDefaultColor(Color.Orange);
#thurx.setDefaultColor(Color.Orange);
#frix.setDefaultColor(Color.Orange);
#satx.setDefaultColor(Color.Orange);
#sunx.setDefaultColor(Color.Orange);

monx.setDefaultColor(getcolor(1));
tuesx.setDefaultColor(getcolor(2));
wedx.setDefaultColor(getcolor(3));
thurx.setDefaultColor(getcolor(4));
frix.setDefaultColor(getcolor(5));
satx.setDefaultColor(getcolor(6));
sunx.setDefaultColor(getcolor(7));
#



DsOBkI6.jpg
 

ComfyCouch

New member
i hope this will help get you closer to what you want

referencing your code in post 11

your code only has a line on 1 day of the week
all lines are the same level
it wasn't storing the poc value for 7 days correctly.

this doesnt work with ext hours off.
def RTH = SecondsFromTime(RthBegin) >= 0 and SecondsTillTime(RthEnd) >= 0;
def cond2 = RTH != RTH[1];

--------------------

my changes
changed the mon, tues,wed,... formulas, so they hold a poc value, not true/false.

used this to determine when a new day occurs. it works when ext hours are off.
def gtdy = GetDay();
def diffday = if GtDy[1] <> GetDay() then 1 else 0;

assigned different colors for each day line


Ruby:
# prevweekdata_00b

# plot 5 (or 7 depending on decurity) poc lines , for the past 7 days

# post11
# https://usethinkscript.com/threads/only-show-friday-charts.5588/#post-74389
# https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Profiles/TimeProfile

def yyyymmdd = GetYYYYMMDD();
def na = Double.Nan;
#def istoday = if GetLastDay() == GetDay() then 1 else 0;


#Defining Days of Week (credit to Mobius)
def DOW2 = getdayOfWeek(getYYYYMMDD());

# test data, show day # of week , 1-7
input test_show_days = no;
addchartbubble(test_show_days, high*1.01, dow2, color.light_gray, yes);

# is the current bar on a different day, than prev bar ?  (first bar of day)
# this works with ext hours off
def gtdy = GetDay();
def diffday = if GtDy[1] <> GetDay() then 1 else 0;

input test_show_first_day_bar = no;
addchartbubble( test_show_first_day_bar and diffday, low*0.99, dow2, color.light_gray, no);

# test , plot spikes when diffday is true , first bar of the day. works with ext hours off
#plot g = if diffday then close else (close *0.9);
#g.setDefaultColor(Color.green);


#Getting POC
def RTHBegin = 930;
def RTHEnd = 1600;
# not used
#def RTH = SecondsFromTime(RthBegin) >= 0 and SecondsTillTime(RthEnd) >= 0;
# this doesnt work with ext hours off
#def cond2 = RTH != RTH[1];

#profile tpo = TimeProfile("PricePerRow" = PricePerRow.Ticksize, "startNewProfile" = cond2, "onExpansion" = no);
profile tpo = TimeProfile("PricePerRow" = PricePerRow.Ticksize, "startNewProfile" = diffday, "onExpansion" = no);
def tpopoc =  tpo.GetPointofControl();

# plot spikes when cond2 is true, first bar of the day. does not  work with ext hours off
#plot f = if cond2 then close else ( close *0.9);
#f.setDefaultColor(Color.cyan);


# assign a value for the day, and keep it till the same day next week
def Mon = if DOW2 == 1 then tpopoc else mon[1];
def Tues = if DOW2 == 2 then tpopoc else tues[1];
def Wed = if DOW2 == 3 then tpopoc else wed[1];
def Thur = if DOW2 == 4 then tpopoc else thur[1];
def Fri = if DOW2 == 5 then tpopoc else fri[1];
def Sat = if DOW2 == 6 then tpopoc else sat[1];
def Sun = if DOW2 == 7 then tpopoc else sun[1];

plot monx = mon;
plot tuesx = tues;
plot wedx = wed;
plot thurx = thur;
plot frix = fri;
plot satx = sat;
plot sunx = sun;

monx.SetPaintingStrategy(PaintingStrategy.Horizontal);
tuesx.SetPaintingStrategy(PaintingStrategy.Horizontal);
wedx.SetPaintingStrategy(PaintingStrategy.Horizontal);
thurx.SetPaintingStrategy(PaintingStrategy.Horizontal);
frix.SetPaintingStrategy(PaintingStrategy.Horizontal);
satx.SetPaintingStrategy(PaintingStrategy.Horizontal);
sunx.SetPaintingStrategy(PaintingStrategy.Horizontal);

#monx.setDefaultColor(Color.Orange);
#tuesx.setDefaultColor(Color.Orange);
#wedx.setDefaultColor(Color.Orange);
#thurx.setDefaultColor(Color.Orange);
#frix.setDefaultColor(Color.Orange);
#satx.setDefaultColor(Color.Orange);
#sunx.setDefaultColor(Color.Orange);

monx.setDefaultColor(getcolor(1));
tuesx.setDefaultColor(getcolor(2));
wedx.setDefaultColor(getcolor(3));
thurx.setDefaultColor(getcolor(4));
frix.setDefaultColor(getcolor(5));
satx.setDefaultColor(getcolor(6));
sunx.setDefaultColor(getcolor(7));
#



DsOBkI6.jpg

halycon, thank you for your help and reply - my apologies for not replying sooner. This did in fact get me closer to what I want and helped me understand certain functions/formulas a lot better that I've tried to incorporate in the study. I'll post the updated study tomorrow, as I have to organize it a little bit better. There are still some things that I've got to fix that I do not quite understand how to do, but I'll be sure to include it tomorrow.

As always, thanks for your continued help.
 

ComfyCouch

New member
halycon, thank you for your help and reply - my apologies for not replying sooner. This did in fact get me closer to what I want and helped me understand certain functions/formulas a lot better that I've tried to incorporate in the study. I'll post the updated study tomorrow, as I have to organize it a little bit better. There are still some things that I've got to fix that I do not quite understand how to do, but I'll be sure to include it tomorrow.

As always, thanks for your continued help.

@halcyonguy (apologies for misspelling your name above), thank you for getting me closer to what I've been trying to get at. I was successfully able to plot the past five days from a specific/static day with no plots in other previous weeks. I've posted the code and a picture of the corresponding chart below.

One thing, however, I'd like to ask is in regards to repeat days. In the code below, I start from today, 8/31/21, a tuesday, as the 0 day, or starting point. From there, using your previous example, I was able to plot all previous days, monday, friday, thursday and wednesday for a total of five plots (including today). I wanted to try and include the previous week's tuesday as well, and therefore, attempted to plot it by adding

Code:
plot tuesday = if TodayIsXDay then tues[2] else na;
tuesday.SetPaintingStrategy(PaintingStrategy.Horizontal);
tuesday.SetDefaultColor(Color.Orange);

by adding a lookback period of [2]. However, as seen in the chart, the number/plot returned is the same as the currentday (today's POC) value, or specifically, the price: 4526.63. What am I doing wrong here? Would tues[2] not return the second previous Tuesday POC?

As always, thank you for your help and guidance.


Code:
#Plotting past five days of POCs based off specific day.

def yyyymmdd = GetYYYYMMDD();
def na = Double.NaN;


#Getting POC
def RTHBegin = 930;
def RTHEnd = 1600;
def RTH = SecondsFromTime(RTHBegin) >= 0 and SecondsTillTime(RTHEnd) >= 0;
def cond2 = RTH != RTH[1];
def GtDy = GetDay();
def diffday = if GtDy[1] <> GetDay() then 1 else 0;
profile tpo = TimeProfile("PricePerRow" = PricePerRow.TICKSIZE, "startNewProfile" = diffday, "onExpansion" = no);

def tpopoc = tpo.GetPointOfControl();

#Defining Days of Week and their POC's (credit to @halcyonguy and @Mobius)
def DOW2 = GetDayOfWeek(GetYYYYMMDD());
def Mon = if DOW2 == 1 then tpopoc else mon[1];
def Tues = if DOW2 == 2 then  tpopoc else tues[1];
def Wed = if DOW2 == 3 then  tpopoc else wed[1];
def Thurs = if DOW2 == 4 then tpopoc else thurs[1];
def Fri = if DOW2 == 5 then  tpopoc else fri[1];
def Sat = if DOW2 == 6 then  tpopoc else sat[1];
def Sun = if DOW2 == 7 then  tpopoc else sun[1];

#Defining Days
def TodayIsXDay = getday()==getlastday() and dow2 == 2; #Since today is 8/31/21 (Tuesday), TodayisXDay = 2

plot currentday = if TodayIsXDay then tues else na;
currentday.SetPaintingStrategy(PaintingStrategy.Horizontal);
currentday.SetDefaultColor(Color.Orange);

plot monday = if TodayIsXDay then mon else na;
monday.SetPaintingStrategy(PaintingStrategy.Horizontal);
monday.SetDefaultColor(Color.Orange);

plot friday = if TodayIsXDay then fri else na;
friday.SetPaintingStrategy(PaintingStrategy.Horizontal);
friday.SetDefaultColor(Color.Orange);

plot thursday = if TodayIsXDay then thurs else na;
thursday.SetPaintingStrategy(PaintingStrategy.Horizontal);
thursday.SetDefaultColor(Color.Orange);

plot wednesday = if TodayIsXDay  then wed else na;
wednesday.SetPaintingStrategy(PaintingStrategy.Horizontal);
wednesday.SetDefaultColor(Color.Orange);

plot tuesday = if TodayIsXDay then tues[2] else na;
tuesday.SetPaintingStrategy(PaintingStrategy.Horizontal);
tuesday.SetDefaultColor(Color.Orange);

Chart (shows today's POC (tuesday) plotted twice):
 

ziongotoptions

New member
VIP
Code:
def poc = reference VolumeProfile("price per row height mode" = "TICKSIZE", "time per profile" = "DAY", "on expansion" = no);
def vahigh = reference VolumeProfile("price per row height mode" = "TICKSIZE", "time per profile" = "DAY", "on expansion" = no).VAHigh;
def valow = reference VolumeProfile("price per row height mode" = "TICKSIZE", "time per profile" = "DAY", "on expansion" = no).VALow;

Hello, I found this code on here, I was wondering how do I modify it to show the previous day POC, VAH, and VAL. Like I would want for the code to plot on today's chart, the POC, VAH, and Low based on yesterday's volume/price movement
 

SleepyZ

Well-known member
Code:
def poc = reference VolumeProfile("price per row height mode" = "TICKSIZE", "time per profile" = "DAY", "on expansion" = no);
def vahigh = reference VolumeProfile("price per row height mode" = "TICKSIZE", "time per profile" = "DAY", "on expansion" = no).VAHigh;
def valow = reference VolumeProfile("price per row height mode" = "TICKSIZE", "time per profile" = "DAY", "on expansion" = no).VALow;

Hello, I found this code on here, I was wondering how do I modify it to show the previous day POC, VAH, and VAL. Like I would want for the code to plot on today's chart, the POC, VAH, and Low based on yesterday's volume/price movement

The following allows you to use that code, choose daysback to plot prior occurrences to right edge, and chart bubbles option. 'Thisday' snippet was used to handle non-trading days, such as the past weekend.

The chart below also includes the display of the volumeprofile study to test the script below.

Capture.jpg
Ruby:
input daysback = 1;

def ymd      = GetYYYYMMDD();
def candles  = !IsNaN(close);
def capture  = candles and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay  = (HighestAll(dayCount) - dayCount) ;

def poc      = if thisDay == daysback then reference VolumeProfile("price per row height mode" = "TICKSIZE", "time per profile" = "DAY", "on expansion" = no) else poc[1];
def vahigh   = if thisDay == daysback then reference VolumeProfile("price per row height mode" = "TICKSIZE", "time per profile" = "DAY", "on expansion" = no).VAHigh else vahigh[1];
def valow    = if thisDay == daysback then reference VolumeProfile("price per row height mode" = "TICKSIZE", "time per profile" = "DAY", "on expansion" = no).VALow else valow[1];

plot poc1    = if thisDay > daysback then Double.NaN else poc;
plot vahigh1 = if thisDay > daysback then Double.NaN else vahigh;
plot valow1  = if thisDay > daysback then Double.NaN else valow;

poc1.setdefaultColor(color.cyan);
vahigh1.setdefaultColor(color.yellow);
valow1.setdefaultColor(color.yellow);

input bubblemover = 3;
def b  = bubblemover;
def b1 = b + 1;
input showbubbles = yes;
addchartBubble(showbubbles and isnan(close[b]) and !isnan(close[b1]), poc1[b], "POC - " + daysback, color.cyan);
addchartBubble(showbubbles and isnan(close[b]) and !isnan(close[b1]), vahigh1[b], "VAH - " + daysback, color.yellow);
addchartBubble(showbubbles and isnan(close[b]) and !isnan(close[b1]), valow1[b], "VAL - " + daysback, color.yellow);
 

ziongotoptions

New member
VIP
The following allows you to use that code, choose daysback to plot prior occurrences to right edge, and chart bubbles option. 'Thisday' snippet was used to handle non-trading days, such as the past weekend.

The chart below also includes the display of the volumeprofile study to test the script below.
wow thank you so much, this is perfect! I have a question, if I leave this on the chart, what time does the line readjust? would I see the prior value high during the premarket of the next session?
 

maka123

New member
VIP
Hi all, anyone able to write a script to search for stock that crosses the poc. ideally we can set whether for intraday , day or week.

i try to use the script from @markos . It is near to what i want however most of result miss the poc area.



# Mr. Script
def yyyymmdd = GetYYYYMMDD();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def period = Floor(day_number / 7);
def cond = 0 < period - period[1];
profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no);
vol.Show("va color" = Color.YELLOW);
def b = vol.GetLowestValueArea();
plot c = close <= b and close >= (b*.9);
 

SleepyZ

Well-known member
Hi all, anyone able to write a script to search for stock that crosses the poc. ideally we can set whether for intraday , day or week.

i try to use the script from @markos . It is near to what i want however most of result miss the poc area.



# Mr. Script
def yyyymmdd = GetYYYYMMDD();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def period = Floor(day_number / 7);
def cond = 0 < period - period[1];
profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no);
vol.Show("va color" = Color.YELLOW);
def b = vol.GetLowestValueArea();
plot c = close <= b and close >= (b*.9);

Put this in the scanner. You can also put it in a study and change def b to plot b

Ruby:
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 = no;
input showValueArea = no;
input valueAreaPercent = 70;
input opacity = 0;

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);
#vol.Show("va color" = Color.YELLOW);
def b = vol.GetPointOfControl();
plot c = if close crosses b then 1 else 0;
 

maka123

New member
VIP
Thanks for your help! It work for the scanner @

SleepyZ


Meanwhile , if i would like to plot the volume profile within a date range. For example between a day range in daily chart.Unlike ninja trader, tos cant select a date range by mouse cursor.
 
Last edited:

SleepyZ

Well-known member
Thanks for your help! It work for the scanner @

SleepyZ


Meanwhile , if i would like to plot the volume profile within a date range. For example between a day range in daily chart.Unlike ninja trader, tos cant select a date range by mouse cursor.

We have limited control over manipulating the TOS volumeprofile. Here is a date range modification of the volumeprofile that you may test for usefulness.

Capture.jpg
Ruby:
#VolumeProfile_DateRange

input begindate  = 20210802;
input enddate    = 20210820;
input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input onExpansion = no;
input profiles = 100;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 70;
input opacity = 50;

def count =  GetYYYYMMDD()>= (begindate)  and getyyyYMMDD()<=enddate;
def cond = count != count[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();

input bubbles = yes;
input n  = 2;
def   n1 = n + 1;
AddChartBubble(bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), VAHigh[n1], "V-VAH", color = Color.YELLOW, yes);
AddChartBubble(bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), VALow[n1], "V-VAL", Color.YELLOW, no);
AddChartBubble(bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), POC[n1], "V-POC", Color.RED, no);
 

Lulu22

New member
Hi Everyone,

Is it possible to script extended horizontal lines only on virgin point of control (VPOC) that price has not touched previously. I am currently drawing the lines manually but I would like to save some time with this process.

Thank you,
 

Similar threads

Top