#TPO_Extended_POCs_HVAs_LVAs_for_x_Daysback_and_Limited_Plots_when_crossed
#More can be added using the logic below
#Sleepyz - usethinkscript request @yardlay
#Added HVA * LVA Lines and Plot limit when crossed for all 3;
#Added Price to Most Recent Naked Labels
script v {
input daysback = 1;
def volp = reference TPOProfile("time per profile" = "DAY", "on expansion" = no, "price per row height mode" = "TICKSIZE");
def ymd = GetYYYYMMDD();
def y = if ymd != ymd[1] then y[1] + 1 else y[1];
def pc = if IsNaN(close)
then pc[1] else
if y == HighestAll(y) - daysback
then volp else
pc[1];
plot x = if y > HighestAll(y) - daysback and Between(pc, low, high)
then BarNumber() else Double.NaN;
plot poc = if IsNaN(LowestAll(x))
then pc
else if BarNumber() > LowestAll(x)
then Double.NaN
else pc;
}
script vh {
input daysback = 1;
def volh = reference TPOProfile("time per profile" = "DAY", "on expansion" = no, "price per row height mode" = "TICKSIZE").VAHigh;
def ymd = GetYYYYMMDD();
def y = if ymd != ymd[1] then y[1] + 1 else y[1];
def ph = if IsNaN(close)
then ph[1] else
if y == HighestAll(y) - daysback
then volh else
ph[1];
plot x = if y > HighestAll(y) - daysback and Between(ph, low, high)
then BarNumber() else Double.NaN;
plot hva = if IsNaN(LowestAll(x))
then ph
else if BarNumber() > LowestAll(x)
then Double.NaN
else ph;
}
script vl {
input daysback = 1;
def voll = reference TPOProfile("time per profile" = "DAY", "on expansion" = no, "price per row height mode" = "TICKSIZE").VALow;
def ymd = GetYYYYMMDD();
def y = if ymd != ymd[1] then y[1] + 1 else y[1];
def pl = if IsNaN(close)
then pl[1] else
if y == HighestAll(y) - daysback
then voll else
pl[1];
plot x = if y > HighestAll(y) - daysback and Between(pl, low, high)
then BarNumber() else Double.NaN;
plot val = if IsNaN(LowestAll(x))
then pl
else if BarNumber() > LowestAll(x)
then Double.NaN
else pl;
}
DefineGlobalColor("H", Color.YELLOW);
DefineGlobalColor("L", Color.YELLOW);
DefineGlobalColor("P", Color.DARK_RED);
DefineGlobalColor("NB", Color.MAGENTA);
plot v1 = v(1).poc;
v1.AssignValueColor(if IsNaN(LowestAll(v(1).x)) then GlobalColor("NB") else GlobalColor("P"));
v1.SetPaintingStrategy(PaintingStrategy.DASHES);
v1.SetLineWeight(2);
plot v2 = v(2).poc;
v2.AssignValueColor(if IsNaN(LowestAll(v(2).x)) then GlobalColor("NB") else GlobalColor("P"));
v2.SetPaintingStrategy(PaintingStrategy.DASHES);
v2.SetLineWeight(2);
plot v3 = v(3).poc;
v3.AssignValueColor(if IsNaN(LowestAll(v(3).x)) then GlobalColor("NB") else GlobalColor("P"));
v3.SetPaintingStrategy(PaintingStrategy.DASHES);
v3.SetLineWeight(2);
plot v4 = v(4).poc;
v4.AssignValueColor(if IsNaN(LowestAll(v(4).x)) then GlobalColor("NB") else GlobalColor("P"));
v4.SetPaintingStrategy(PaintingStrategy.DASHES);
v4.SetLineWeight(2);
plot v5 = v(5).poc;
v5.AssignValueColor(if IsNaN(LowestAll(v(5).x)) then GlobalColor("NB") else GlobalColor("P"));
v5.SetPaintingStrategy(PaintingStrategy.DASHES);
v5.SetLineWeight(2);
plot v6 = v(6).poc;
v6.AssignValueColor(if IsNaN(LowestAll(v(6).x)) then GlobalColor("NB") else GlobalColor("P"));
v6.SetPaintingStrategy(PaintingStrategy.DASHES);
v6.SetLineWeight(2);
plot v7 = v(7).poc;
v7.AssignValueColor(if IsNaN(LowestAll(v(7).x)) then GlobalColor("NB") else GlobalColor("P"));
v7.SetPaintingStrategy(PaintingStrategy.DASHES);
v7.SetLineWeight(2);
plot v8 = v(8).poc;
v8.AssignValueColor(if IsNaN(LowestAll(v(8).x)) then GlobalColor("NB") else GlobalColor("P"));
v8.SetPaintingStrategy(PaintingStrategy.DASHES);
v8.SetLineWeight(2);
plot v9 = v(9).poc;
v9.AssignValueColor(if IsNaN(LowestAll(v(9).x)) then GlobalColor("NB") else GlobalColor("P"));
v9.SetPaintingStrategy(PaintingStrategy.DASHES);
v9.SetLineWeight(2);
plot v10 = v(10).poc;
v10.AssignValueColor(if IsNaN(LowestAll(v(10).x)) then GlobalColor("NB") else GlobalColor("P"));
v10.SetPaintingStrategy(PaintingStrategy.DASHES);
v10.SetLineWeight(2);
;
AddLabel(1, "Most Recent Naked --> POC: " +
if IsNaN(LowestAll(v(1).x)) then "V1: " + v1 else
if IsNaN(LowestAll(v(2).x)) then "V2: " + v2 else
if IsNaN(LowestAll(v(3).x)) then "V3: " + v3 else
if IsNaN(LowestAll(v(4).x)) then "V4: " + v4 else
if IsNaN(LowestAll(v(5).x)) then "V5: " + v5 else
if IsNaN(LowestAll(v(6).x)) then "V6: " + v6 else
if IsNaN(LowestAll(v(7).x)) then "V7: " + v7 else
if IsNaN(LowestAll(v(8).x)) then "V8: " + v8 else
if IsNaN(LowestAll(v(9).x)) then "V9: " + v9 else
if IsNaN(LowestAll(v(10).x)) then "V10: " + v10 else
"NO V", Color.YELLOW) ;
plot vh1 = vh(1).hva;
vh1.AssignValueColor(if IsNaN(LowestAll(vh(1).x)) then GlobalColor("NB") else GlobalColor("H"));
vh1.SetPaintingStrategy(PaintingStrategy.DASHES);
vh1.SetLineWeight(2);
plot vh2 = vh(2).hva;
vh2.AssignValueColor(if IsNaN(LowestAll(vh(2).x)) then GlobalColor("NB") else GlobalColor("H"));
vh2.SetPaintingStrategy(PaintingStrategy.DASHES);
vh2.SetLineWeight(2);
plot vh3 = vh(3).hva;
v3.AssignValueColor(if IsNaN(LowestAll(vh(3).x)) then GlobalColor("NB") else GlobalColor("H"));
v3.SetPaintingStrategy(PaintingStrategy.DASHES);
v3.SetLineWeight(2);
plot vh4 = vh(4).hva;
vh4.AssignValueColor(if IsNaN(LowestAll(vh(4).x)) then GlobalColor("NB") else GlobalColor("H"));
vh4.SetPaintingStrategy(PaintingStrategy.DASHES);
vh4.SetLineWeight(2);
plot vh5 = vh(5).hva;
vh5.AssignValueColor(if IsNaN(LowestAll(vh(5).x)) then GlobalColor("NB") else GlobalColor("H"));
vh5.SetPaintingStrategy(PaintingStrategy.DASHES);
vh5.SetLineWeight(2);
plot vh6 = vh(6).hva;
vh6.AssignValueColor(if IsNaN(LowestAll(vh(6).x)) then GlobalColor("NB") else GlobalColor("H"));
vh6.SetPaintingStrategy(PaintingStrategy.DASHES);
vh6.SetLineWeight(2);
plot vh7 = vh(7).hva;
vh7.AssignValueColor(if IsNaN(LowestAll(vh(7).x)) then GlobalColor("NB") else GlobalColor("H"));
vh7.SetPaintingStrategy(PaintingStrategy.DASHES);
vh7.SetLineWeight(2);
plot vh8 = vh(8).hva;
vh8.AssignValueColor(if IsNaN(LowestAll(vh(8).x)) then GlobalColor("NB") else GlobalColor("H"));
vh8.SetPaintingStrategy(PaintingStrategy.DASHES);
vh8.SetLineWeight(2);
plot vh9 = vh(9).hva;
vh9.AssignValueColor(if IsNaN(LowestAll(vh(9).x)) then GlobalColor("NB") else GlobalColor("H"));
vh9.SetPaintingStrategy(PaintingStrategy.DASHES);
vh9.SetLineWeight(2);
plot vh10 = vh(10).hva;
vh10.AssignValueColor(if IsNaN(LowestAll(vh(10).x)) then GlobalColor("NB") else GlobalColor("H"));
vh10.SetPaintingStrategy(PaintingStrategy.DASHES);
vh10.SetLineWeight(2);
;
AddLabel(1, " VAH: " +
if IsNaN(LowestAll(vh(1).x)) then "VH1: " + vh1 else
if IsNaN(LowestAll(vh(2).x)) then "VH2: " + vh2 else
if IsNaN(LowestAll(vh(3).x)) then "VH3: " + vh3 else
if IsNaN(LowestAll(vh(4).x)) then "VH4: " + vh4 else
if IsNaN(LowestAll(vh(5).x)) then "VH5: " + vh5 else
if IsNaN(LowestAll(vh(6).x)) then "VH6: " + vh6 else
if IsNaN(LowestAll(vh(7).x)) then "VH7: " + vh7 else
if IsNaN(LowestAll(vh(8).x)) then "VH8: " + vh8 else
if IsNaN(LowestAll(vh(9).x)) then "VH9: " + vh9 else
if IsNaN(LowestAll(vh(10).x)) then "VH10: " + vh10 else
"NO VH", Color.WHITE) ;
plot vl1 = vl(1).val;
vl1.AssignValueColor(if IsNaN(LowestAll(vl(1).x)) then GlobalColor("NB") else GlobalColor("L"));
vl1.SetPaintingStrategy(PaintingStrategy.DASHES);
vl1.SetLineWeight(2);
plot vl2 = vl(2).val;
vl2.AssignValueColor(if IsNaN(LowestAll(vl(2).x)) then GlobalColor("NB") else GlobalColor("L"));
vl2.SetPaintingStrategy(PaintingStrategy.DASHES);
vl2.SetLineWeight(2);
plot vl3 = vl(3).val;
vl3.AssignValueColor(if IsNaN(LowestAll(vl(3).x)) then GlobalColor("NB") else GlobalColor("L"));
vl3.SetPaintingStrategy(PaintingStrategy.DASHES);
vl3.SetLineWeight(2);
plot vl4 = vl(4);
vl4.AssignValueColor(if IsNaN(LowestAll(vl(4).x)) then GlobalColor("NB") else GlobalColor("L"));
vl4.SetPaintingStrategy(PaintingStrategy.DASHES);
vl4.SetLineWeight(2);
plot vl5 = vl(5).val;
vl5.AssignValueColor(if IsNaN(LowestAll(vl(5).x)) then GlobalColor("NB") else GlobalColor("L"));
vl5.SetPaintingStrategy(PaintingStrategy.DASHES);
vl5.SetLineWeight(2);
plot vl6 = vl(6).val;
vl6.AssignValueColor(if IsNaN(LowestAll(vl(6).x)) then GlobalColor("NB") else GlobalColor("L"));
vl6.SetPaintingStrategy(PaintingStrategy.DASHES);
vl6.SetLineWeight(2);
plot vl7 = vl(7).val;
vl7.AssignValueColor(if IsNaN(LowestAll(vl(7).x)) then GlobalColor("NB") else GlobalColor("L"));
vl7.SetPaintingStrategy(PaintingStrategy.DASHES);
vl7.SetLineWeight(2);
plot vl8 = vl(8).val;
vl8.AssignValueColor(if IsNaN(LowestAll(vl(8).x)) then GlobalColor("NB") else GlobalColor("L"));
vl8.SetPaintingStrategy(PaintingStrategy.DASHES);
vl8.SetLineWeight(2);
plot vl9 = vl(9).val;
vl9.AssignValueColor(if IsNaN(LowestAll(vl(9).x)) then GlobalColor("NB") else GlobalColor("L"));
vl9.SetPaintingStrategy(PaintingStrategy.DASHES);
vl9.SetLineWeight(2);
plot vl10 = vl(10).val;
vl10.AssignValueColor(if IsNaN(LowestAll(vl(10).x)) then GlobalColor("NB") else GlobalColor("L"));
vl10.SetPaintingStrategy(PaintingStrategy.DASHES);
vl10.SetLineWeight(2);
;
AddLabel(1, " VAL: " +
if IsNaN(LowestAll(vl(1).x)) then "VL1: " + vl1 else
if IsNaN(LowestAll(vl(2).x)) then "VL2: " + vl2 else
if IsNaN(LowestAll(vl(3).x)) then "VL3: " + vl3 else
if IsNaN(LowestAll(vl(4).x)) then "VL4: " + vl4 else
if IsNaN(LowestAll(vl(5).x)) then "VL5: " + vl5 else
if IsNaN(LowestAll(vl(6).x)) then "VL6: " + vl6 else
if IsNaN(LowestAll(vl(7).x)) then "VL7: " + vl7 else
if IsNaN(LowestAll(vl(8).x)) then "VL8: " + vl8 else
if IsNaN(LowestAll(vl(9).x)) then "VL9: " + vl9 else
if IsNaN(LowestAll(vl(10).x)) then "VL10: " + vl10 else
"NO VL", Color.YELLOW) ;
#TPOprofile script with Defaults to match extended POC plots x daysback
#
# TD Ameritrade IP Company, Inc. (c) 2010-2022
#
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 = yes;
input showValueArea = yes;
input valueAreaPercent = 70;
input opacity = 50;
def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
switch (timePerProfile) {
case CHART:
period = 0;
case MINUTE:
period = Floor(seconds / 60 + day_number * 24 * 60);
case HOUR:
period = Floor(seconds / 3600 + day_number * 24);
case DAY:
period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
period = Floor(day_number / 7);
case MONTH:
period = Floor(month - First(month));
case "OPT EXP":
period = exp_opt - First(exp_opt);
case BAR:
period = BarNumber() - 1;
}
def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % multiplier else count[1], 0);
def 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();