#Example_PreviousDaysHL-each_extended_through_expansion
#20170911 - BLT
#Example Highs/Lows from previous days, extended from each day through the right expansion
script philow {
input n = 1;
def ymd = GetYYYYMMDD();
def ok = !IsNaN(close);
def capture = ok and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture
then dayCount[1] + 1
else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) ;
def hh = CompoundValue(1, if thisDay[1] == n + 1 and thisDay == n
then high
else if thisDay == n and high > hh[1] and thisDay == n
then high
else hh[1] , high);
def hhnan = if IsNaN(close) then hhnan[1] else hh;
plot hhplot = if thisDay == n
then Double.NaN
else if thisDay <= n
then hhnan
else Double.NaN;
def ll = CompoundValue(1, if thisDay[1] == n + 1 and thisDay == n
then low
else if thisDay == n and low < ll[1] and thisDay == n
then low
else ll[1] , low);
def llnan = if IsNaN(ll) then llnan[1] else ll;
plot llplot = if thisDay == n and SecondsFromTime(0930) < 0
then Double.NaN
else if thisDay <= n
then (llnan)
else Double.NaN;
plot day = thisday;
}
#Plots of Highs/Lows/Opens/Closes based upon script...add more days using similar plot statements, increasing the value by 1
input show_lines = no;
input day = 1;
plot H1 = HighestAll(philow(day));
plot L1 = LowestAll(philow(day).llplot);
H1.SetHiding(!show_lines);
L1.SetHiding(!show_lines);
input show_bubbles = yes;
AddChartBubble(show_bubbles and philow().day == day and high == H1, high, "HH: " + H1, Color.GREEN);
AddChartBubble(show_bubbles and philow().day == day and low == L1, low, "LL: " + L1, Color.LIGHT_RED, no);