//@version=5
//@author= Day Trading Con David
indicator("Daily 14 ATR", overlay=true)
// Days to calculate
atrLength = input(14, title="ATR Length")
// Adjust the conversion formatting string to the instrument: e.g., "#.########" for crypto.
numberFormat = input('#.##', title="Number Format")
// Label Background Color
lblbgcolor = input(color.rgb(0, 0, 0), title="Label Background Color")
// Text Label Color
textcolor = input(color.rgb(255, 255, 255), title="Text Label Color")
// Fetch daily ATR. We want the current daily value, so we use a repainting security() call.
dAtr = request.security(syminfo.tickerid, 'D', ta.atr(atrLength), lookahead=barmerge.lookahead_on)
// Calculate Range of the day
HoD = request.security(syminfo.tickerid, "D", high)
LoD = request.security(syminfo.tickerid, "D", low)
Open = request.security(syminfo.tickerid, "D", open)
rotd = HoD - LoD
positiveMove = HoD - Open
negativeMove = LoD - Open
percentage = (rotd * 100) / dAtr
postiveMovePer = (positiveMove * 100) / dAtr
negativeMovePer = (negativeMove * 100) / dAtr
// Display table
var testTable = table.new(position=position.top_left, columns=7, rows=5, bgcolor=lblbgcolor, border_width=1)
if barstate.islast
table.cell(testTable, 0, 0, "ATR", text_color=textcolor)
table.cell(testTable, 1, 0, "T Range", text_color=textcolor)
table.cell(testTable, 2, 0, "Percentage", text_color=textcolor)
table.cell(testTable, 3, 0, "Positive %", text_color=textcolor)
table.cell(testTable, 4, 0, "Negative %", text_color=textcolor)
table.cell(testTable, 0, 1, "$ " + str.tostring(dAtr, numberFormat), text_color=textcolor)
table.cell(testTable, 1, 1, "$ " + str.tostring(rotd, numberFormat), text_color=(rotd > dAtr ? color.blue : textcolor))
table.cell(testTable, 2, 1, "% " + str.tostring(percentage, numberFormat), text_color=(rotd > dAtr ? color.blue : textcolor))
table.cell(testTable, 3, 1, "% " + str.tostring(postiveMovePer, numberFormat), text_color=(rotd > dAtr ? color.green : textcolor))
table.cell(testTable, 4, 1, "% " + str.tostring(negativeMovePer, numberFormat), text_color=(rotd > dAtr ? color.red : textcolor))