```
#Previous_Day_HighLowClose_RTHrs_ExtHrs_Sessions_for_Futures_v1
#[email protected]
#Modified by Sleepyz
#Extended Lines across chart
#Added Today's RTH open
#Added Mode choice between RTHrs v EXTrs Sessions
input agg = {default DAY, WEEK, MONTH};
input mode = {default RTHrs, EXTHrs};
input extend_lines_across_chart = yes;
input rthbegin = 0930;
input rthend = 1600;
input extend = 1800;
input showBubbles = no;
input showValuesInBubbles = yes;
input showLabels = yes;
input showValuesInLabels = yes;
plot todayrthOpen;
plot prevClose;
plot prevLow;
plot prevHigh;
def NA = Double.NaN;
def bn = BarNumber();
def exp = IsNaN(close);
def rth = SecondsFromTime(rthbegin) > - 0 and SecondsFromTime(rthend) <= 0;
def start = GetDayOfWeek(GetYYYYMMDD());
def period =
if agg == agg.MONTH then GetMonth()
else if agg == agg.WEEK then GetWeek()
else GetYYYYMMDD();
def count = if !IsNaN(close) and period != period[1] then count[1] + 1 else count[1];
def cond = HighestAll(count) - count;
################# RTH Open
def rthopen = if (GetDay() == GetLastDay() or exp) and SecondsFromTime(rthbegin) == 0
then open
else rthopen[1];
todayrthOpen = if extend_lines_across_chart == yes
then HighestAll(rthopen)
else if exp
then rthopen
else NA;
################# close
def extclose = close(period = agg)[1];
def rthclose = CompoundValue(1, if cond == 1 and SecondsFromTime(rthend) == 0 then close[1] else rthclose[1], close);
def hpdclose = if mode == mode.RTHrs and GetDay() == GetLastDay()
then rthclose[1]
else if mode == mode.EXTHrs and GetDay() == GetLastDay()
then close("period" = agg)[1]
else hpdclose[1];
prevClose = if extend_lines_across_chart == yes
then HighestAll(hpdclose)
else if exp
then hpdclose
else NA;
################# Low
def extlow = low(period = agg)[1];
def rthlowday = CompoundValue(1,
if cond[1] == 2 then Double.NaN
else if cond == 1 and SecondsFromTime(rthbegin) == 0
then low
else if cond >= 1 and rth == 1 and low < rthlowday[1]
then low else rthlowday[1], low);
def rthlowweek = if cond == 1 then if start[1] != 1 and start == 1 then NA
else if start == 1 and SecondsFromTime(0930) == 0 then low
else if start >= 1 and rth and low < rthlowweek[1] then low
else rthlowweek[1]
else NA;
def rthlowmon = if cond == 1 then if cond[1] == 2 and cond == 1 then NA
else if start == 1 and SecondsFromTime(0930) == 0 then low
else if start >= 1 and rth and low < rthlowmon[1] then low
else rthlowmon[1]
else NA;
def hpdlow = if mode == mode.RTHrs and agg == agg.DAY
then HighestAll(if IsNaN(close[-1]) then rthlowday else NA)
else if mode == mode.RTHrs and agg == agg.WEEK
then LowestAll(if cond == 1 then rthlowweek else NA)
else if mode == mode.RTHrs and agg == agg.MONTH
then LowestAll(if cond == 1 then rthlowmon else NA)
else if mode == mode.EXTHrs
then HighestAll(if IsNaN(close[-1]) then extlow else NA)
else hpdlow[1];
prevLow = if extend_lines_across_chart == yes
then HighestAll(hpdlow)
else if exp
then HighestAll(hpdlow)
else NA;
################# High
def exthigh = high(period = agg)[1];
def rthhighday = CompoundValue(1,
if cond == 1 and SecondsFromTime(rthbegin) == 0
then high
else if cond == 1 and rth
then Max(high, rthhighday[1])
else rthhighday[1], high);
def rthhighweek = if cond == 1 then
if start[1] != 1 and start == 1
then Double.NaN
else if start == 1 and SecondsFromTime(0930) == 0
then high
else if start >= 1 and rth and high > rthhighweek[1]
then high
else rthhighweek[1]
else NA;
def rthhighmon = if cond == 1 then
if cond[1] == 2 and cond == 1
then Double.NaN
else if start == 1 and SecondsFromTime(0930) == 0
then high
else if start >= 1 and rth and high > rthhighmon[1]
then high
else rthhighmon[1]
else NA;
def hpdhigh = if mode == mode.RTHrs and agg == agg.DAY
then HighestAll(if IsNaN(close[-1]) then rthhighday else NA)
else if mode == mode.RTHrs and agg == agg.WEEK
then HighestAll(if cond == 1 then rthhighweek else NA)
else if mode == mode.RTHrs and agg == agg.MONTH
then HighestAll(if cond == 1 then rthhighmon else NA)
else if mode == mode.EXTHrs
then HighestAll(if IsNaN(close[-1]) then exthigh else Double.NaN)
else hpdhigh[1];
prevHigh = if extend_lines_across_chart == yes
then HighestAll(hpdhigh)
else if exp
then HighestAll(hpdhigh)
else NA;
#Labels
AddLabel(showLabels, mode, Color.WHITE);
AddLabel(showLabels, "PREV " + agg, Color.MAGENTA);
AddLabel(showLabels,
if showValuesInLabels then "RO $" + todayrthOpen
else "TO", todayrthOpen.TakeValueColor());
AddLabel(showLabels,
(if showValuesInLabels
then "PH $" + prevHigh
else "PH"), Color.GREEN);
AddLabel(showLabels,
(if showValuesInLabels
then "PL $" + prevLow
else "PL"), Color.RED);
AddLabel(showLabels,
(if showValuesInLabels then "PC $" + prevClose
else "PC"), Color.YELLOW);
#Bubbles
input bubblemover = 1;
def b = bubblemover;
def b1 = b + 1;
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , todayrthOpen[b],
if showValuesInBubbles then "TO $" + todayrthOpen[b] else "TO", Color.WHITE, yes);
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevClose[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
then "EC $" + prevClose[b]
else "RC $" + prevClose[b]
else if mode == mode.RTHrs
then "RC"
else "EC"), Color.YELLOW, yes);
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevLow[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
then "EL $" + prevLow[b]
else "RL $" + prevLow[b]
else if mode == mode.RTHrs
then "RL"
else "EL"), Color.RED, yes);
AddChartBubble(showBubbles and IsNaN(close[b]) and !IsNaN(close[b1]) , prevHigh[b],
(if showValuesInBubbles
then if mode == mode.EXTHrs
then "EH $" + prevHigh[b]
else "RH $" + prevHigh[b]
else if mode == mode.RTHrs
then "RH"
else "EH"), Color.GREEN, yes);
todayrthOpen.SetDefaultColor(Color.WHITE);
prevLow.SetDefaultColor(Color.RED);
prevHigh.SetDefaultColor(Color.GREEN);
prevClose.SetDefaultColor(Color.YELLOW);
prevLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#
```