```
#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;
script v {
input daysback = 1;
def volp = reference VolumeProfile("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];
def rth = secondsfromTime(0930)>=0 and secondsFromTime(1600)<0;
def hi = if !rth then double.nan else high;
def lo = if !rth then double.nan else low;
def x = if y > HighestAll(y) - daysback and Between(pc, lo, hi)
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 VolumeProfile("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];
def rth = secondsfromTime(0930)>=0 and secondsFromTime(1600)<0;
def hi = if !rth then double.nan else high;
def lo = if !rth then double.nan else low;
def x = if y > HighestAll(y) - daysback and Between(ph, lo, hi)
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 VolumeProfile("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];
def rth = secondsfromTime(0930)>=0 and secondsFromTime(1600)<0;
def hi = if !rth then double.nan else high;
def lo = if !rth then double.nan else low;
def x = if y > HighestAll(y) - daysback and Between(pl, lo, hi)
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);
plot v1 = v(1).poc;
v1.SetDefaultColor(Color.RED);
v1.SetPaintingStrategy(PaintingStrategy.DASHES);
v1.SetLineWeight(2);
plot v2 = v(2).poc;
v2.SetDefaultColor(Color.RED);
v2.SetPaintingStrategy(PaintingStrategy.DASHES);
v2.SetLineWeight(2);
plot v3 = v(3).poc;
v3.SetDefaultColor(Color.RED);
v3.SetPaintingStrategy(PaintingStrategy.DASHES);
v3.SetLineWeight(2);
plot v4 = v(4).poc;
v4.SetDefaultColor(Color.RED);
v4.SetPaintingStrategy(PaintingStrategy.DASHES);
v4.SetLineWeight(2);
plot v5 = v(5).poc;
v5.SetDefaultColor(Color.RED);
v5.SetPaintingStrategy(PaintingStrategy.DASHES);
v5.SetLineWeight(2);
plot v6 = v(6).poc;
v6.SetDefaultColor(Color.RED);
v6.SetPaintingStrategy(PaintingStrategy.DASHES);
v6.SetLineWeight(2);
plot v7 = v(7).poc;
v7.SetDefaultColor(Color.RED);
v7.SetPaintingStrategy(PaintingStrategy.DASHES);
v7.SetLineWeight(2);
plot v8 = v(8).poc;
v8.SetDefaultColor(Color.RED);
v8.SetPaintingStrategy(PaintingStrategy.DASHES);
v8.SetLineWeight(2);
plot v9 = v(9).poc;
v9.SetDefaultColor(Color.RED);
v9.SetPaintingStrategy(PaintingStrategy.DASHES);
v9.SetLineWeight(2);
plot v10 = v(10).poc;
v10.SetDefaultColor(Color.RED);
v10.SetPaintingStrategy(PaintingStrategy.DASHES);
v10.SetLineWeight(2);
;
plot vh1 = vh(1);
vh1.SetDefaultColor(globalColor("H"));
vh1.SetPaintingStrategy(PaintingStrategy.DASHES);
vh1.SetLineWeight(2);
plot vh2 = vh(2);
vh2.SetDefaultColor(globalColor("H"));
vh2.SetPaintingStrategy(PaintingStrategy.DASHES);
vh2.SetLineWeight(2);
plot vh3 = vh(3);
v3.SetDefaultColor(globalColor("H"));
v3.SetPaintingStrategy(PaintingStrategy.DASHES);
v3.SetLineWeight(2);
plot vh4 = vh(4);
vh4.SetDefaultColor(globalColor("H"));
vh4.SetPaintingStrategy(PaintingStrategy.DASHES);
vh4.SetLineWeight(2);
plot vh5 = vh(5);
vh5.SetDefaultColor(globalColor("H"));
vh5.SetPaintingStrategy(PaintingStrategy.DASHES);
vh5.SetLineWeight(2);
plot vh6 = vh(6);
vh6.SetDefaultColor(globalColor("H"));
vh6.SetPaintingStrategy(PaintingStrategy.DASHES);
vh6.SetLineWeight(2);
plot vh7 = vh(7);
vh7.SetDefaultColor(globalColor("H"));
vh7.SetPaintingStrategy(PaintingStrategy.DASHES);
vh7.SetLineWeight(2);
plot vh8 = vh(8);
vh8.SetDefaultColor(globalColor("H"));
vh8.SetPaintingStrategy(PaintingStrategy.DASHES);
vh8.SetLineWeight(2);
plot vh9 = vh(9);
vh9.SetDefaultColor(globalColor("H"));
vh9.SetPaintingStrategy(PaintingStrategy.DASHES);
vh9.SetLineWeight(2);
plot vh10 = vh(10);
vh10.SetDefaultColor(globalColor("H"));
vh10.SetPaintingStrategy(PaintingStrategy.DASHES);
vh10.SetLineWeight(2);
;
plot vl1 = vl(1);
vl1.SetDefaultColor(globalColor("L"));
vl1.SetPaintingStrategy(PaintingStrategy.DASHES);
vl1.SetLineWeight(2);
plot vl2 = vl(2);
vl2.SetDefaultColor(globalColor("L"));
vl2.SetPaintingStrategy(PaintingStrategy.DASHES);
vl2.SetLineWeight(2);
plot vl3 = vl(3);
vl3.SetDefaultColor(globalColor("L"));
vl3.SetPaintingStrategy(PaintingStrategy.DASHES);
vl3.SetLineWeight(2);
plot vl4 = vl(4);
vl4.SetDefaultColor(globalColor("L"));
vl4.SetPaintingStrategy(PaintingStrategy.DASHES);
vl4.SetLineWeight(2);
plot vl5 = vl(5);
vl5.SetDefaultColor(globalColor("L"));
vl5.SetPaintingStrategy(PaintingStrategy.DASHES);
vl5.SetLineWeight(2);
plot vl6 = vl(6);
vl6.SetDefaultColor(globalColor("L"));
vl6.SetPaintingStrategy(PaintingStrategy.DASHES);
vl6.SetLineWeight(2);
plot vl7 = vl(7);
vl7.SetDefaultColor(globalColor("L"));
vl7.SetPaintingStrategy(PaintingStrategy.DASHES);
vl7.SetLineWeight(2);
plot vl8 = vl(8);
vl8.SetDefaultColor(globalColor("L"));
vl8.SetPaintingStrategy(PaintingStrategy.DASHES);
vl8.SetLineWeight(2);
plot vl9 = vl(9);
vl9.SetDefaultColor(globalColor("L"));
vl9.SetPaintingStrategy(PaintingStrategy.DASHES);
vl9.SetLineWeight(2);
plot vl10 = vl(10);
vl10.SetDefaultColor(globalColor("L"));
vl10.SetPaintingStrategy(PaintingStrategy.DASHES);
vl10.SetLineWeight(2);
;
#Volumeprofile 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 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();
#
```