Rolling Candle Closes Summation
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pzyxian

//@version=5
indicator("Rolling Candle Closes Summation")

// Prompt the user to input the number of candles to sum
n = input.int(title="Number of Candles to Sum", defval=20, minval=1)


// Get the last 20 candle's close prices
last20Closes = array.new_float(n)
for i = 0 to n-1
    array.push(last20Closes, close[i])

// Add the last 20 candle's close prices together
last20ClosesSum = array.sum(last20Closes)

// Plot the last 20 candle's close prices sum on the chart
plot(last20ClosesSum, color=color.green, linewidth=2)