This plots the RTH (0930:1600) for HLCO for the previous day on today's chart
Ruby:
#Prior Day HLC RegularTradingHours
input rthbegin = 0930;
input rthend = 1600;
def pastOpen = If((SecondsTillTime(rthbegin) > 0), 0, 1);
def pastClose = If((SecondsTillTime(rthend) > 0), 0, 1);
def marketOpen = If(pastOpen and !pastClose, 1, 0);
def date = GetYYYYMMDD();
def c = close;
def h = high;
def l = low;
def o = open;
#Highest High during RTH from Previous Day Determined
def begin = CompoundValue(1, if getday()==getday()[1]
then if SecondsFromTime(rthbegin) == 0
then h
else if h > begin[1] and marketOpen
then h
else begin[1]
else 0, begin[1]);
def beginbn = if GetDay() == GetLastDay()
then 0
else if getday()==getday()[1]
then if h == begin and marketOpen
then BarNumber()
else beginbn[1]
else 0;
def beginprice = if getday()==getday()[1]
then if BarNumber() == HighestAll(beginbn)
then h
else beginprice[1]
else beginprice[1];
#Lowest Low During RTH from Previous Day Determined
def begin1 = CompoundValue(1, if getday()==getday()[1]
then if SecondsFromTime(rthbegin) == 0
then l
else if l < begin1[1] and marketOpen
then l
else begin1[1]
else 0, l);
def beginbn1 = if GetDay() == GetLastDay()
then 0
else if l == begin1
then BarNumber()
else beginbn1[1];
def beginprice1 = if date == date[1]
then if BarNumber() == HighestAll(beginbn1)
then l
else beginprice1[1]
else beginprice1[1];
#Close During RTH from Previous Day Determined
def begin2 = CompoundValue(1, if date == date[1]
then if SecondsFromTime(rthend) == 0
then c
else begin2[1]
else 0, c);
def beginbn2 = if GetDay() == GetLastDay()
then 0
else if c == begin2
then BarNumber()
else beginbn2[1];
def beginprice2 = if date == date[1]
then if BarNumber() == HighestAll(beginbn2)
then c
else beginprice2[1]
else beginprice2[1];
#Open During RTH from Previous Day Determined
def begin3 = CompoundValue(1, if date == date[1]
then if SecondsFromTime(rthbegin) == 0
then o
else begin3[1]
else 0, 0);
def beginbn3 = if GetDay() == GetLastDay()
then 0
else if date==date[1] and o == (begin3)
then BarNumber()
else beginbn3[1];
def beginprice3 = if date == date[1]
then if BarNumber() == (beginbn3)
then o
else beginprice3[1]
else beginprice3[1];
plot ph = if getday()!=getlastday() then double.nan else beginprice;
ph.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ph.setdefaultColor(color.green);
plot pl = if getday()!=getlastday() then double.nan else beginprice1;
pl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pl.setdefaultColor(color.red);
plot pc = if getday()!=getlastday() then double.nan else beginprice2;
pc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pc.setdefaultColor(color.yellow);
plot po = if getday()!=getlastday() then double.nan else beginprice3;
po.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
po.setdefaultColor(color.white);
input showbubbles_Prior_OHLC = yes;
input n = 5;
def n1 = n + 1;
def StartPlot = if showbubbles_Prior_OHLC == yes
then (IsNaN(c[n]) and !IsNaN(c[n1]))
else Double.NaN;
AddChartBubble(StartPlot, Round(ph[n1], 2), "PH-" + astext(Round(ph[n1], 2)), Color.GREEN, yes);
AddChartBubble(StartPlot, Round(pl[n1], 2), "PL-" + astext(Round(pl[n1], 2)), Color.RED, yes);
AddChartBubble(StartPlot, Round(pc[n1], 2), "PC-" + astext(Round(pc[n1], 2)), Color.YELLOW, yes);
AddChartBubble(StartPlot, Round(po[n1], 2), "PO-" + astext(Round(po[n1], 2)), Color.white, yes);
Last edited by a moderator: