Current price & Daily open
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Munkhtur

//@version=5
indicator('Current price & Daily open', shorttitle='Price & DO', overlay=true)

daily_time  = request.security(syminfo.tickerid, 'D', time,  lookahead=barmerge.lookahead_on)
daily_open  = request.security(syminfo.tickerid, 'D', open,  lookahead=barmerge.lookahead_on)
daily_close = request.security(syminfo.tickerid, 'D', close, lookahead=barmerge.lookahead_on)

var lastprice    = input(defval=true, title='Last Price')
var dailyopen    = input(defval=true, title='Daily Open')
var extend_right = 20
var show_price   = lastprice
var show_open    = dailyopen and timeframe.isintraday and timeframe.multiplier <= 60

candlecolor    = close >= open
line_color     = candlecolor ? color.blue : color.red
DOcolor        = close >= daily_open
daily_color    = DOcolor ? color.blue : color.red
rightbar(bars) =>
    time_close + (time - time[1]) * bars

if barstate.islast
    if show_open and DOcolor and not barstate.isconfirmed and barstate.isrealtime
        var open_line  = line.new(x1=daily_time, x2=rightbar(extend_right), y1=daily_open, y2=daily_open, color = daily_color, width=1, xloc = xloc.bar_time)
        var open_label = label.new(x=rightbar(extend_right), y=daily_open, text='Open ' + str.tostring(daily_open), style = label.style_none, textcolor = daily_color, size = size.small, xloc = xloc.bar_time)
        line.set_x1(open_line, daily_time)
        line.set_x2(open_line, rightbar(extend_right))
        line.set_y1(open_line, daily_open)
        line.set_y2(open_line, daily_open)
        label.set_x(open_label, rightbar(extend_right))
        label.set_y(open_label, daily_open)
        
    if show_open and not DOcolor and not barstate.isconfirmed and barstate.isrealtime
        var open_line  = line.new(x1=daily_time, x2=rightbar(extend_right), y1=daily_open, y2=daily_open, color = daily_color, width=1, xloc = xloc.bar_time)
        var open_label = label.new(x=rightbar(extend_right), y=daily_open, text='Open ' + str.tostring(daily_open), style = label.style_none, textcolor = daily_color, size = size.small, xloc = xloc.bar_time)
        line.set_x1(open_line, daily_time)
        line.set_x2(open_line, rightbar(extend_right))
        line.set_y1(open_line, daily_open)
        line.set_y2(open_line, daily_open)
        label.set_x(open_label, rightbar(extend_right))
        label.set_y(open_label, daily_open)

    if show_price and candlecolor and not barstate.isconfirmed and barstate.isrealtime
        var open_line  = line.new(x1=rightbar(extend_right - 20), x2=rightbar(extend_right - 15), y1=close, y2=close, color = line_color, width=1, xloc = xloc.bar_time)
        var open_label = label.new(x=rightbar(extend_right - 15), y=close, text=str.tostring(close), style = label.style_none, textcolor = line_color, size = size.small, xloc = xloc.bar_time)
        line.set_x1(open_line, rightbar(extend_right - 20))
        line.set_x2(open_line, rightbar(extend_right - 15))
        line.set_y1(open_line, close)
        line.set_y2(open_line, close)
        label.set_x(open_label, rightbar(extend_right - 15))
        label.set_y(open_label, close)

    if show_price and not candlecolor and not barstate.isconfirmed and barstate.isrealtime
        var open_line  = line.new(x1=rightbar(extend_right - 20), x2=rightbar(extend_right - 15), y1=close, y2=close, color = line_color, width=1, xloc = xloc.bar_time)
        var open_label = label.new(x=rightbar(extend_right - 15), y=close, text=str.tostring(close), style = label.style_none, textcolor = line_color, size = size.small, xloc = xloc.bar_time)
        line.set_x1(open_line, rightbar(extend_right - 20))
        line.set_x2(open_line, rightbar(extend_right - 15))
        line.set_y1(open_line, close)
        line.set_y2(open_line, close)
        label.set_x(open_label, rightbar(extend_right - 15))
        label.set_y(open_label, close)