ATR Daily Band
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © andrew51228

//@version=5
indicator("ATR Daily Band", overlay=true)
length = input.int(title="Length", defval=14, minval=1)
myColor = input.color(title="Color", defval=color.new(#d3b4b4, 0))

atr = request.security(syminfo.tickerid, "1D", ta.atr(14), lookahead=barmerge.lookahead_on)
dailyOpen = request.security(syminfo.tickerid, "1D", open, lookahead=barmerge.lookahead_on)
dailyClose = request.security(syminfo.tickerid, "1D", close)
dailyCloseOffset = request.security(syminfo.tickerid, "1D", close[1])
//dailyClose = 336

// plot(ta.rma(ta.tr(true) + dailyClose, length), title = "ATR", color=color.new(#B71C1C, 0))

plot(barstate.isrealtime ? dailyCloseOffset + atr : dailyClose + atr, color=myColor)
plot(barstate.isrealtime ? dailyCloseOffset - atr : dailyClose - atr, color=myColor)


//plot(dailyClose + atr, color=myColor)
//plot(dailyClose - atr, color=myColor)
//label.new(time[0], dailyOpen + atr, str.format("{0}", dailyOpen + atr), xloc = xloc.bar_index, style = label.style_none)

is_first_bar = hour(time) == 9 and minute(time) == 30 and dayofmonth(timenow) == dayofmonth(time) and month(timenow) == month(time) and year(timenow) == year(time)
if is_first_bar
    upLabel = label.new(x=bar_index, y=dailyClose + atr,text=str.format("{0,number,#.##}  +{1,number,#.##}%", dailyClose+atr, atr/dailyClose*100), textcolor=color.white, xloc=xloc.bar_index, color=myColor, style=label.style_label_lower_right, size=size.normal)
    dnLabel = label.new(x=bar_index, y=dailyClose - atr,text=str.format("{0,number,#.##}  -{1,number,#.##}%", dailyClose-atr, atr/dailyClose*100), textcolor=color.white, xloc=xloc.bar_index, color=myColor, style=label.style_label_upper_right, size=size.normal)

// plot(close)
// upper = ta.sma(close + atr, 200)
// lower = ta.sma(close - atr, 200)
// plot(upper, title = "+ATR", color=color.new(#d3b4b4, 0))
// plot(lower, title = "-ATR", color=color.new(#d3b4b4, 0))
