Quarterly Value Area (TPO)

ziongotoptions

Active member
Code:
def poc = reference tpoProfile("price per row height mode" = "TICKSIZE", "time per profile" = "MONTH", "on expansion" = no, multiplier = 3).poc;
def vahigh = reference tpoProfile("price per row height mode" = "TICKSIZE", "time per profile" = "MONTH", "on expansion" = no, multiplier = 3).VAHigh;
def valow = reference tpoProfile("price per row height mode" = "TICKSIZE", "time per profile" = "MONTH", "on expansion" = no, multiplier = 3).VALow;

plot tpoc = poc[1];
plot tavahigh = vahigh[1];
plot tvalow = valow[1];

Hello I'm trying to script a code to calculate the quarterly VAH but I'm running into an issue, the script is calculating the Value Area for every three months not quarterly, any ideas on how to get the Quarterly VAH?
 
Solution
Thank you I’m sorry if I’m being a hassle I just want to plot the previous quarter value area on todays quarter , just as support resistance area I only really need to the lines, my system tells me if it’s above value area high , that’s initiative buying therefore trending behavior. So I really just want to plot the lines, hiding the profile works. I tried offsetting the profile by 1 but it plotted the previous quarter value area on the previous quarter, not on todays chart which is what I’m looking for

Here are the prior quarter and current quarter plotted on the current quarter's period.

Capture.jpg
Ruby:
input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile...
Unfortunately QUARTER is not an allowed aggregation period in TOS for TPO Profiles.

time per profileDefines aggregation period to calculate the bars for the histogram. Setting this parameter to "CHART" involves the entire price plot into calculation. Values "BAR", "MINUTE", "HOUR", "DAY", "WEEK", "MONTH", and "OPT EXP" allow you to set aggregation manually, specifying number of these periods within the "multiplier" input.

So as a workaround you could set "time per profile" = "CHART", then set your chart timeframe to Custom and set the beginning day to the first day of the quarter you are analyzing & end date to end of quarter/current day.

Also worth noting
multiplierDefines the number of periods to calculate the TPO profile. Note that this setting is ignored if "time per profile" input is set to "CHART".
 
Last edited:

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

Code:
def poc = reference tpoProfile("price per row height mode" = "TICKSIZE", "time per profile" = "MONTH", "on expansion" = no, multiplier = 3).poc;
def vahigh = reference tpoProfile("price per row height mode" = "TICKSIZE", "time per profile" = "MONTH", "on expansion" = no, multiplier = 3).VAHigh;
def valow = reference tpoProfile("price per row height mode" = "TICKSIZE", "time per profile" = "MONTH", "on expansion" = no, multiplier = 3).VALow;

plot tpoc = poc[1];
plot tavahigh = vahigh[1];
plot tvalow = valow[1];

Hello I'm trying to script a code to calculate the quarterly VAH but I'm running into an issue, the script is calculating the Value Area for every three months not quarterly, any ideas on how to get the Quarterly VAH?

See if this helps

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, "QUARTER", "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);
def qtr = (GetMonth() - 1) % 3;
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 QUARTER:
    period = qtr == 0 and qtr[1] != 0;
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 tpo = TimeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
    def con = CompoundValue(1, onExpansion, no);
    def pc = if IsNaN(tpo.GetPointOfControl()) and con then pc[1] else tpo.GetPointOfControl();
    def hVA = if IsNaN(tpo.GetHighestValueArea()) and con then hVA[1] else tpo.GetHighestValueArea();
    def lVA = if IsNaN(tpo.GetLowestValueArea()) and con then lVA[1] else tpo.GetLowestValueArea();

    def hProfile = if IsNaN(tpo.GetHighest()) and con then hProfile[1] else tpo.GetHighest();
    def lProfile = if IsNaN(tpo.GetLowest()) and con then lProfile[1] else tpo.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));

    tpo.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 profiles = 2;
Thank you I’m sorry if I’m being a hassle I just want to plot the previous quarter value area on todays quarter , just as support resistance area I only really need to the lines, my system tells me if it’s above value area high , that’s initiative buying therefore trending behavior. So I really just want to plot the lines, hiding the profile works. I tried offsetting the profile by 1 but it plotted the previous quarter value area on the previous quarter, not on todays chart which is what I’m looking for
 
Code:
# qtr = 0 if start of new quarter.
def qtr = (GetMonth() - 1) % 3;

def newQtr = qtr == 0 and qtr[1] != 0;

def QCount = compoundValue(1, if newQtr then if QCount[1] == 4 then 1 else QCount[1] + 1 else QCount[1], 1);

#
def startPro = if onExpansion != onExpansion.All then newQtr else 0;

Hello, could someone explain this code to me? I want to modify it to def monthly instead of quarterly but Im having a hard time breaking the script down because of the compound value
 
Code:
# qtr = 0 if start of new quarter.
def qtr = (GetMonth() - 1) % 3;

def newQtr = qtr == 0 and qtr[1] != 0;

def QCount = compoundValue(1, if newQtr then if QCount[1] == 4 then 1 else QCount[1] + 1 else QCount[1], 1);

#
def startPro = if onExpansion != onExpansion.All then newQtr else 0;

Hello, could someone explain this code to me? I want to modify it to def monthly instead of quarterly but Im having a hard time breaking the script down because of the compound value


this

def QCount = compoundValue(1, if newQtr then if QCount[1] == 4 then 1 else QCount[1] + 1 else QCount[1], 1);

is equiv to this

def QCount;
if barnumber > 1 then {

QCount = if newQtr then if QCount[1] == 4 then 1 else QCount[1] + 1 else QCount[1]

} else {

QCount = 1;

}

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

compoundValue(
1st parameter, a barnumber

2nd param ,
if current barnumber is > 1st param. , then process the 2nd param.

3 param ,
if current barnumber is <= 1st param. , then process the 3rd param.
)
 
Code:
# qtr = 0 if start of new quarter.
def qtr = (GetMonth() - 1) % 3;

def newQtr = qtr == 0 and qtr[1] != 0;

def QCount = compoundValue(1, if newQtr then if QCount[1] == 4 then 1 else QCount[1] + 1 else QCount[1], 1);

#
def startPro = if onExpansion != onExpansion.All then newQtr else 0;

Hello, could someone explain this code to me? I want to modify it to def monthly instead of quarterly but Im having a hard time breaking the script down because of the compound value
try adding something like this, to the end of your study, to display some values, to help debugging.

addchartbubble(1, low*0.99,
qtr + "\n" +
newQtr + "\n" +
QCount + "\n" +
startPro
, color cyan, no);
 
this

def QCount = compoundValue(1, if newQtr then if QCount[1] == 4 then 1 else QCount[1] + 1 else QCount[1], 1);

is equiv to this

def QCount;
if barnumber > 1 then {

QCount = if newQtr then if QCount[1] == 4 then 1 else QCount[1] + 1 else QCount[1]

} else {

QCount = 1;

}

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

compoundValue(
1st parameter, a barnumber

2nd param ,
if current barnumber is > 1st param. , then process the 2nd param.

3 param ,
if current barnumber is <= 1st param. , then process the 3rd param.
)
thank you but could you explain it in terms of its unction for defining quarterly, like why are they using that compound value, what is the logic behind it
 
thank you but could you explain it in terms of its unction for defining quarterly, like why are they using that compound value, what is the logic behind it
they used a compoundvalue() function because the formula within it looks back one bar. if the a formula tries to look back 1 bar, on the 1st bar on the chart , it may cause an error. so they're telling it if it's bar #1 , skip the formula, and after that process the formula.
 
Thank you I’m sorry if I’m being a hassle I just want to plot the previous quarter value area on todays quarter , just as support resistance area I only really need to the lines, my system tells me if it’s above value area high , that’s initiative buying therefore trending behavior. So I really just want to plot the lines, hiding the profile works. I tried offsetting the profile by 1 but it plotted the previous quarter value area on the previous quarter, not on todays chart which is what I’m looking for

Here are the prior quarter and current quarter plotted on the current quarter's period.

Capture.jpg
Ruby:
input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {CHART, MINUTE, HOUR, DAY, WEEK, MONTH, default QUARTER, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 2;
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);
def qtr = (GetMonth() - 1 ) % 3;
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 QUARTER:
    period = qtr == 0 and qtr[1] != 0;
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 tpo = TimeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = CompoundValue(1, onExpansion, no);
def pc  = if IsNaN(tpo.GetPointOfControl()) and con then pc[1] else tpo.GetPointOfControl();
def hVA = if IsNaN(tpo.GetHighestValueArea()) and con then hVA[1] else tpo.GetHighestValueArea();
def lVA = if IsNaN(tpo.GetLowestValueArea()) and con then lVA[1] else tpo.GetLowestValueArea();

def hProfile    = if IsNaN(tpo.GetHighest()) and con then hProfile[1] else tpo.GetHighest();
def lProfile    = if IsNaN(tpo.GetLowest()) and con then lProfile[1] else tpo.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;

plot POC = if plotsDomain then pc else Double.NaN;
plot VAH = if plotsDomain then hVA else Double.NaN;
plot VAL = if plotsDomain then lVA else Double.NaN;

def poc1   = if POC != POC[1] then pc[1] else poc1[1];
plot xpoc1 = poc1;
def vah1   = if VAH != VAH[1] then VAH[1] else vah1[1];
plot xvah1 = vah1;
def val1   = if VAL != VAL[1] then VAL[1] else val1[1];
plot xval1 = val1;

POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
xpoc1.SetPaintingStrategy(PaintingStrategy.DASHES);
xvah1.SetPaintingStrategy(PaintingStrategy.DASHES);
xval1.SetPaintingStrategy(PaintingStrategy.DASHES);
POC.SetDefaultColor(Color.RED);
VAH.SetDefaultColor(Color.YELLOW);
VAL.SetDefaultColor(Color.YELLOW);
xpoc1.SetDefaultColor(Color.RED);
xvah1.SetDefaultColor(Color.YELLOW);
xval1.SetDefaultColor(Color.YELLOW);
 
Solution
Hello and thank you, could you add a labels so the lines for the quarterly profiles can be identified?
Optional labels and/or moveable bubbles have been added to the code below.
Ruby:
input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {CHART, MINUTE, HOUR, DAY, WEEK, MONTH, default QUARTER, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 2;
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);
def qtr = (GetMonth() - 1 ) % 3;
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 QUARTER:
    period = qtr == 0 and qtr[1] != 0;
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 tpo = TimeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = CompoundValue(1, onExpansion, no);
def pc  = if IsNaN(tpo.GetPointOfControl()) and con then pc[1] else tpo.GetPointOfControl();
def hVA = if IsNaN(tpo.GetHighestValueArea()) and con then hVA[1] else tpo.GetHighestValueArea();
def lVA = if IsNaN(tpo.GetLowestValueArea()) and con then lVA[1] else tpo.GetLowestValueArea();

def hProfile    = if IsNaN(tpo.GetHighest()) and con then hProfile[1] else tpo.GetHighest();
def lProfile    = if IsNaN(tpo.GetLowest()) and con then lProfile[1] else tpo.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;

plot POC = if plotsDomain then pc else Double.NaN;
plot VAH = if plotsDomain then hVA else Double.NaN;
plot VAL = if plotsDomain then lVA else Double.NaN;

def poc1   = if POC != POC[1] then pc[1] else poc1[1];
plot xpoc1 = poc1;
def vah1   = if VAH != VAH[1] then VAH[1] else vah1[1];
plot xvah1 = vah1;
def val1   = if VAL != VAL[1] then VAL[1] else val1[1];
plot xval1 = val1;

POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
xpoc1.SetPaintingStrategy(PaintingStrategy.DASHES);
xvah1.SetPaintingStrategy(PaintingStrategy.DASHES);
xval1.SetPaintingStrategy(PaintingStrategy.DASHES);
POC.SetDefaultColor(Color.RED);
VAH.SetDefaultColor(Color.YELLOW);
VAL.SetDefaultColor(Color.YELLOW);
xpoc1.SetDefaultColor(Color.RED);
xvah1.SetDefaultColor(Color.YELLOW);
xval1.SetDefaultColor(Color.YELLOW);

input showbubbles = yes;
input bubblemover = 2;
def b  = bubblemover;
def b1 = b + 1;
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), POC[b1], "QP", Color.RED);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), VAL[b1], "QL", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), VAH[b1], "QH", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), xpoc1[b1], "Q1P", Color.RED);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), xval1[b1], "Q1L", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), xvah1[b1], "Q1H", Color.YELLOW);

input showlabels = yes;
AddLabel(showlabels and POC, "QP " + AsText(POC), Color.RED);
AddLabel(showlabels and VAL, "QL " + AsText(VAL), Color.YELLOW);
AddLabel(showlabels and VAH, "QH " + AsText(VAH), Color.YELLOW);
AddLabel(showlabels and xpoc1, "Q1P " + AsText(xpoc1), Color.RED);
AddLabel(showlabels and xval1, "Q1L " + AsText(xval1), Color.YELLOW);
AddLabel(showlabels and xvah1, "Q1H " + AsText(xvah1), Color.YELLOW);
 
Optional labels and/or moveable bubbles have been added to the code below.
Thanks, When you switch to monthly the labels stay on "Q" Quarterly could you please get them to adjust with the change in the time frame, and if possible could the input be added for turning on and off the previous TPO ? thanks again!
 
Thanks, When you switch to monthly the labels stay on "Q" Quarterly could you please get them to adjust with the change in the time frame, and if possible could the input be added for turning on and off the previous TPO ? thanks again!

This is a new script to limit the plots to the current timeframe selected period to the current and prior timeframes,
Limited to Week, Month and Quarter Timeframes, and best Used on Daily and above charts or Intraday charts with at least 180 days displayed
Optional bubbles and/or labels were added. I reworked the code as it is tricky to just limit the plots as requested using the prior script.

Capture.jpg
Ruby:
#TPO Profile-Just Lines with Quarter Timeframe Added-Limited to Week, Month and Quarter Timeframes
#Only Displays on the Current Timeframe Selected, the Current and Prior Timeframes
#Best Used on Daily and above charts or Intraday charts with at least 180 days displayed


script tpo {
    input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
    input customRowHeight = 1.0;
    input timePerProfile = {CHART, MINUTE, HOUR, DAY, WEEK, MONTH, default QUARTER, "OPT EXP", BAR};
    input multiplier = 1;
    input onExpansion = no;
    input profiles = 2;
    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);
    def qtr = (GetMonth() - 1 ) % 3;
    def type = timePerProfile;

    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 QUARTER:
        period = qtr == 0 and qtr[1] != 0;
    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 tpo = TimeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
    def con = CompoundValue(1, onExpansion, no);
    def pc  = if IsNaN(tpo.GetPointOfControl()) and con then pc[1] else tpo.GetPointOfControl();
    def hVA = if IsNaN(tpo.GetHighestValueArea()) and con then hVA[1] else tpo.GetHighestValueArea();
    def lVA = if IsNaN(tpo.GetLowestValueArea()) and con then lVA[1] else tpo.GetLowestValueArea();

    def hProfile    = if IsNaN(tpo.GetHighest()) and con then hProfile[1] else tpo.GetHighest();
    def lProfile    = if IsNaN(tpo.GetLowest()) and con then lProfile[1] else tpo.GetLowest();
    def plotsDomain = IsNaN(close) == onExpansion;

    plot POC = if plotsDomain then pc else Double.NaN;
    plot VAH = if plotsDomain then hVA else Double.NaN;
    plot VAL = if plotsDomain then lVA else Double.NaN;
}



input timePerProfile = {WEEK, MONTH, default QUARTER};
def poc = tpo("time per profile" = timePerProfile);
def vah = tpo("time per profile" = timePerProfile).VAH;
def val = tpo("time per profile" = timePerProfile).VAL;

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

plot poc0 = if thisDay == 0 then poc else Double.NaN;
plot val0 = if thisDay == 0 then val else Double.NaN;
plot vah0 = if thisDay == 0 then vah else Double.NaN;

def pc1   = CompoundValue(1, if thisDay == 1 then poc else pc1[1] , poc);
plot poc1 = if thisDay == 0 then pc1 else Double.NaN;
def vh1   = CompoundValue(1, if thisDay == 1 then vah else vh1[1] , vah);
plot vah1 = if thisDay == 0 then vh1 else Double.NaN;
def vl1   = CompoundValue(1, if thisDay == 1 then val else vl1[1] , val);
plot val1 = if thisDay == 0 then vl1 else Double.NaN;

poc0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vah0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
val0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
poc1.SetPaintingStrategy(PaintingStrategy.DASHES);
vah1.SetPaintingStrategy(PaintingStrategy.DASHES);
val1.SetPaintingStrategy(PaintingStrategy.DASHES);
poc0.SetDefaultColor(Color.RED);
vah0.SetDefaultColor(Color.YELLOW);
val0.SetDefaultColor(Color.YELLOW);
poc1.SetDefaultColor(Color.RED);
vah1.SetDefaultColor(Color.YELLOW);
val1.SetDefaultColor(Color.YELLOW);


input showbubbles = yes;
input bubblemover = 2;
def b  = bubblemover;
def b1 = b + 1;
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), poc[b1],
(if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else "Q") + "POC", Color.RED);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), val[b1], (if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else "Q") + "VAL", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), vah[b1], (if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else "Q") + "VAH", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), poc1[b1], (if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else "Q") + "POC1", Color.RED);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), val1[b1], (if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else "Q") + "VAL1", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), vah1[b1], (if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else "Q") + "VAH1", Color.YELLOW);

input showlabels = yes;
AddLabel(showlabels, timePerProfile + " :  Current", Color.WHITE);
AddLabel(showlabels and poc, "POC " + AsText(poc), Color.RED);
AddLabel(showlabels and val, "VAL " + AsText(val), Color.YELLOW);
AddLabel(showlabels and vah, "VAH " + AsText(vah), Color.YELLOW);
AddLabel(showlabels, "  Prior : ", Color.WHITE);
AddLabel(showlabels and poc1, "POC1 " + AsText(poc1), Color.RED);
AddLabel(showlabels and val1, "VAL1 " + AsText(val1), Color.YELLOW);
AddLabel(showlabels and vah1, "VAH1 " + AsText(vah1), Color.YELLOW);
 
This is a new script to limit the plots to the current timeframe selected period to the current and prior timeframes,
Limited to Week, Month and Quarter Timeframes, and best Used on Daily and above charts or Intraday charts with at least 180 days displayed
Optional bubbles and/or labels were added. I reworked the code as it is tricky to just limit the plots as requested using the prior script.
@SleepyZ Hello and thanks, the drop-down only supports Weekly Monthly and Quarterly how can we use it for the daily and advise?
 
@SleepyZ Hello and thanks, the drop-down only supports Weekly Monthly and Quarterly how can we use it for the daily and advise?

You can use this one for most timeframes with enough periods showing to plot the lines, but no hiding of prior period's profile. The current and prior period's TPO will plot on the current period though.

{EDIT - Added better code for bubbles to match the Limited Version Below}

Capture.jpg

Ruby:
input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {CHART, MINUTE, HOUR, DAY, WEEK, MONTH, default QUARTER, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 2;
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);
def qtr = (GetMonth() - 1 ) % 3;
def type=timeperprofile;

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 QUARTER:
    period = qtr == 0 and qtr[1] != 0;
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 tpo = TimeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = CompoundValue(1, onExpansion, no);
def pc  = if IsNaN(tpo.GetPointOfControl()) and con then pc[1] else tpo.GetPointOfControl();
def hVA = if IsNaN(tpo.GetHighestValueArea()) and con then hVA[1] else tpo.GetHighestValueArea();
def lVA = if IsNaN(tpo.GetLowestValueArea()) and con then lVA[1] else tpo.GetLowestValueArea();

def hProfile    = if IsNaN(tpo.GetHighest()) and con then hProfile[1] else tpo.GetHighest();
def lProfile    = if IsNaN(tpo.GetLowest()) and con then lProfile[1] else tpo.GetLowest();
def plotsDomain = IsNaN(close) == onExpansion;
def ymd      = close(period=aggregationPeriod.QUARTER);
def candles  = !IsNaN(ymd);
def capture  = candles[1] and ymd != ymd[1] ;
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay  = (HighestAll(dayCount) - dayCount ) ;


plot POC = if plotsDomain then pc else Double.NaN;
plot VAH = if plotsDomain then hVA else Double.NaN;
plot VAL = if plotsDomain then lVA else Double.NaN;


def poc1   = if PoC != PoC[1] then poc[1] else poc1[1];
def poc1x  = if thisday==0 and thisday-1==1 then poc1[1] else poc1x[1];
plot xpoc1 = poc1[1];
def vah1   = if VAH != VAH[1] then VAH[1] else vah1[1];
plot xvah1 = vah1;
def val1   = if VAL != VAL[1] then VAL[1] else val1[1];
plot xval1 = val1;
xpoc1.sethiding(!thisday==1);
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
xpoc1.SetPaintingStrategy(PaintingStrategy.DASHES);
xvah1.SetPaintingStrategy(PaintingStrategy.DASHES);
xval1.SetPaintingStrategy(PaintingStrategy.DASHES);
POC.SetDefaultColor(Color.RED);
VAH.SetDefaultColor(Color.YELLOW);
VAL.SetDefaultColor(Color.YELLOW);
xpoc1.SetDefaultColor(Color.RED);
xvah1.SetDefaultColor(Color.YELLOW);
xval1.SetDefaultColor(Color.YELLOW);

input showbubbles = yes;
input bubblemover = 2;
def b  = bubblemover;
def b1 = b + 1;
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), POC[b1],
(if timePerProfile == timePerProfile.DAY then "D" else if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else if timePerProfile == timePerProfile.MONTH then "Q" else "") +"POC", Color.RED);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), VAL[b1], (if timePerProfile == timePerProfile.DAY then "D" else if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else if timePerProfile == timePerProfile.MONTH then "Q" else "") +"VAL", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), VAH[b1], (if timePerProfile == timePerProfile.DAY then "D" else if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else if timePerProfile == timePerProfile.MONTH then "Q" else "") +"VAH", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), xpoc1[b1], (if timePerProfile == timePerProfile.DAY then "D" else if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else if timePerProfile == timePerProfile.MONTH then "Q" else "") +"POC1", Color.RED);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), xval1[b1], (if timePerProfile == timePerProfile.DAY then "D" else if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else if timePerProfile == timePerProfile.MONTH then "Q" else "") +"VAL1", Color.YELLOW);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), xvah1[b1], (if timePerProfile == timePerProfile.DAY then "D" else if timePerProfile == timePerProfile.WEEK then "W" else if timePerProfile == timePerProfile.MONTH then "M" else if timePerProfile == timePerProfile.MONTH then "Q" else "") +"VAH1", Color.YELLOW);

input showlabels = yes;
addlabel(showlabels, timeperprofile + " :  Current", color.white);
AddLabel(showlabels and POC, "POC " + AsText(POC), Color.RED);
AddLabel(showlabels and VAL, "VAL " + AsText(VAL), Color.YELLOW);
AddLabel(showlabels and VAH, "VAH " + AsText(VAH), Color.YELLOW);
addlabel(showlabels, "  Prior : ", color.white);
AddLabel(showlabels and xpoc1, "POC " + AsText(xpoc1), Color.RED);
AddLabel(showlabels and xval1, "VAL " + AsText(xval1), Color.YELLOW);
AddLabel(showlabels and xvah1, "VAH "+ AsText(xvah1), Color.YELLOW);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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