//@version=6
// Example script bundled with DegenView. Edit it freely.
// A small table pinned to the corner of the chart. It is rebuilt on the last bar
// only, so history stays cheap.
indicator("Stats Table", overlay = true)
atrLength = input.int(14, "ATR length", minval = 1)
rangeBars = input.int(24, "Range bars", minval = 2)
volumeLength = input.int(20, "Volume average length", minval = 2)
trendLength = input.int(200, "Trend EMA length", minval = 2)
atrPercent = ta.atr(atrLength) / close * 100
rangePercent = (ta.highest(high, rangeBars) - ta.lowest(low, rangeBars)) / close * 100
volumeRatio = volume / ta.sma(volume, volumeLength)
trendUp = close > ta.ema(close, trendLength)
var table stats = table.new(position.top_right, 2, 4, border_width = 1)
if barstate.islast
table.cell(stats, 0, 0, "ATR", text_color = color.white, bgcolor = color.gray)
table.cell(stats, 1, 0, str.tostring(atrPercent, "#.00") + "%", text_color = color.white, bgcolor = color.gray)
table.cell(stats, 0, 1, str.tostring(rangeBars) + "-bar range", text_color = color.white, bgcolor = color.gray)
table.cell(stats, 1, 1, str.tostring(rangePercent, "#.00") + "%", text_color = color.white, bgcolor = color.gray)
table.cell(stats, 0, 2, "Volume vs average", text_color = color.white, bgcolor = color.gray)
table.cell(stats, 1, 2, str.tostring(volumeRatio, "#.00") + "x", text_color = color.white, bgcolor = volumeRatio > 1.5 ? color.orange : color.gray)
table.cell(stats, 0, 3, "Trend", text_color = color.white, bgcolor = color.gray)
table.cell(stats, 1, 3, trendUp ? "Up" : "Down", text_color = color.white, bgcolor = trendUp ? color.green : color.red)