Previous Day Values
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jjustingreyy

//@version=5
indicator("Previous Day Values", overlay = true)

//Previous Day Values 
// to highlight the session 
var line[] prevDayLines = array.new_line()

prevDayOpen = na(nz(request.security(syminfo.tickerid, "D", time[1])))
isNewDay = not(na(prevDayOpen)) and prevDayOpen != request.security(syminfo.tickerid, "D", time)

if isNewDay and array.size(prevDayLines) > 0
    for i = 0 to array.size(prevDayLines) - 1
        line.delete(array.get(prevDayLines, i))
    array.clear(prevDayLines)

[dh,dl,dc, dv] = request.security(syminfo.ticker, "D", [high[1],low[1], close[1], ta.vwap[1]], lookahead=barmerge.lookahead_on)

// Function to create line and label
f_line_and_label(_p, _color, _text) =>
    if (not na(_p))
        l = line.new(x1=na, y1=_p, x2=bar_index + 50, y2=_p, width = 1, color=_color, extend = extend.right)
        array.push(prevDayLines, l)
        var label lb = na
        if (na(lb))
            lb := label.new(na, na, "", color = color.rgb(255, 255, 255), style = label.style_none, textcolor=color.rgb(255, 255, 255))
        label.set_xy(lb, bar_index + 60, _p + syminfo.mintick*0.5)
        label.set_text(lb, _text + ": " + str.tostring(_p))
        label.set_color(lb, _color)

// Toggle for previous day levels
show_prev_day_high = input(true, title="Show Previous Day High")
show_prev_day_low = input(true, title="Show Previous Day Low")
show_prev_day_vwap = input(true, title="Show Previous Day Vwap")
show_prev_day_close = input(true, title="Show Previous Day Close")

// Display Previous Day Values if toggle is on
if show_prev_day_high
    f_line_and_label(dh, color.rgb(254, 101, 101), "Prev Day High")
if show_prev_day_low
    f_line_and_label(dl, color.rgb(84, 232, 128), "Prev Day Low")
if show_prev_day_close
    f_line_and_label(dc, color.rgb(97, 197, 255), "Prev Day Close")
if show_prev_day_vwap
    f_line_and_label(dv, color.rgb(239, 204, 79), "Prev Day VWAP Close")