ATR Day Grid by RSU
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rsu9111

//@version=5
indicator("ATR Day Grid by RSU",overlay=true)

atrgrid=input.bool(true, "On/Off ATR_D Grid Show")
Atrp=input.int(14, "ATR Len", minval=5, maxval=200, step=1)

dt = time - time[1]
label chasehigh1=na
//Day Warning
if timeframe.isdaily and atrgrid
    atr14=ta.atr(Atrp)
    safe_top = line.new(time+dt, low+atr14*0.5, time+dt*7, low+atr14*0.5, xloc=xloc.bar_time,color=color.green)
    risk_top = line.new(time+dt, low+atr14, time+dt*7, low+atr14, xloc=xloc.bar_time,color=color.red)
    
    if close>(low+atr14)
        line.set_width(risk_top,5)
        chasehigh1:=label.new(bar_index,low+atr14*1.5,text="Don‘t chasing!",color=color.new(color.red,100),style=label.style_label_left,textcolor=color.new(color.red,20))
    
    label.delete(chasehigh1[1])
    line.delete(safe_top[1])
    line.delete(risk_top[1])
    
    if close<open
        line.delete(safe_top)
        line.delete(risk_top)
//intraday Warning
[time_D,atr_D,open_D,close_D]=request.security(syminfo.tickerid,"D",[time,ta.atr(Atrp),open,close],barmerge.gaps_off, barmerge.lookahead_on)
if timeframe.isminutes and atrgrid
    startK=ta.barssince(ta.change(time_D))
    safe_top_1h=line.new(time[startK],low[startK]+atr_D*0.5,time+dt*7,low[startK]+atr_D*0.5,xloc=xloc.bar_time,color=color.new(color.green,50))
    risk_top_1h = line.new(time[startK],low[startK]+atr_D,time+dt*7,low[startK]+atr_D,xloc=xloc.bar_time,color=color.red)
    
    if close>(low[startK]+atr_D)
        line.set_width(risk_top_1h,20)
        chasehigh1:=label.new(bar_index,low[startK]+atr_D*1.1,text="Don‘t chasing!",color=color.new(color.red,100),style=label.style_label_left,textcolor=color.new(color.red,20))
    
    label.delete(chasehigh1[1])
    line.delete(safe_top_1h[1])
    line.delete(risk_top_1h[1])
    if close_D<open_D
        line.delete(safe_top_1h)
        line.delete(risk_top_1h)
