ATR vs Day Trading Range and Percentage
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TraderCreatorPro

//@version=5
indicator("ATR/DTR", overlay = true)
//inputs
TimeFrame = input.timeframe("D", "Timeframe the ATR is Calculated off of")
percolor = input.int(100, "Percentage the color will change at")// the percerntage the color will change with
normalcolor = input.color (color.gray, "Color under percentage") // the color if it is under the certain percentage
colorchange = input.color(color.white, "Color over percentage") //the color it will change to if... 

BoxPlacement = input.string(position.bottom_right, "Box Placement", options = [position.bottom_right, position.bottom_left, position.top_right, position.top_center, position.bottom_center])


//Prepare a table
var table atrdtr = table.new(BoxPlacement, 3, 1, bgcolor = normalcolor, border_color = color.teal, border_width = 2)

//Indicator math stuff
atr = request.security(syminfo.ticker, TimeFrame, ta.atr(14))
atr2 = math.round(atr,2)
dtr = request.security(syminfo.ticker,TimeFrame, math.round(high - low,2))
atrp = math.round(dtr/atr * 100)

//Draw Table
if barstate.islast
    table.cell(atrdtr, 0,0, text = "ATR: " + str.tostring(atr2))
    table.cell(atrdtr, 1,0, text = "DTR: " + str.tostring(dtr))
    table.cell(atrdtr, 2,0, text = str.tostring(atrp)+ "%")
    if atrp > percolor
        table.set_bgcolor(atrdtr, colorchange)

plot(na)
