Rango en los últimos 14 días - Tabla

//@version=5
indicator("Range of Last 14 Days Table", overlay=true)

// Check if the current timeframe is set to 1 day
isDailyTimeframe = timeframe.isdaily

totalDays = input(14)

// Function to calculate the range of a specific day
dailyRange(day) =>
    highOfDay = high[day]
    lowOfDay = low[day]
    highOfDay - lowOfDay


if isDailyTimeframe
    // Calculate the range of each day for the last 14 days
    var float[] dailyRanges = array.new_float(totalDays)
    for i = 0 to totalDays - 1
        array.set(dailyRanges, i, dailyRange(i))

    // Calculate the daily ATR(14)
    dailyATR = ta.atr(totalDays)

    // Create and display the table, highlighting days with range larger than ATR
    tableInfo = table.new(position = position.bottom_right, columns = 1, rows = totalDays)
    for i = 0 to totalDays - 1
        isLargerThanATR = array.get(dailyRanges, i) > dailyATR
        bgColor = isLargerThanATR ? color.new(color.green, 0) : na
        table.cell(table_id = tableInfo, column = 0, row = i, text = "Day " + str.tostring(i + 1) + ": " + str.tostring(array.get(dailyRanges, i), format.mintick), bgcolor = bgColor, text_color= color.white)