Candle volume analysis 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlexeyWolf
// @version=5

funvolcalc(_i) =>
    bool f = true
    int i=_i
    while i>0
        if volume <= volume[i]
            f := false
            break 
        i:=i-1
    f

indicator(title = "Advanced VSA:Candle volume analysis ", shorttitle="Volume analysis [AlexeyWolf v2]", format = format.volume, precision = 0,max_bars_back=5000)
i_sw1 = input.int(2, "First number of candles ago", 1,4000,1, inline = '1')
effort1 = input.color(color.rgb(100, 101, 104), "Color 1", "Use this color when the volume of one candle is individually larger than the previous 'Number of candles ago First'", inline = '1')
i_sw2 = input.int(2, "Second number of candles ago", 1,5000,1, inline = '2')
effort2 = input.color(color.rgb(17, 70, 230), "Color 2", "Use this color when the volume of one candle is individually larger than the previous 'Number of candles ago Second'", inline = '2')
i_sw3 = input.bool(false, "Use the total volumes of the previous candles for the 'Second number of candles ago'","Compare the volume with the volume of each candle separately or with the sum of the volumes of previous candles")

color basic = color.rgb(178, 181, 190, 0)
color volumeColor = na
volumeColor := funvolcalc(i_sw1)? effort1 : basic
if i_sw2>i_sw1 and not i_sw3
    volumeColor := funvolcalc(i_sw2)? effort2 : volumeColor
else if i_sw3
    volumeColor := math.sum(volume,i_sw2+1)<2*volume? effort2 : volumeColor

plot(volume, style = plot.style_columns, color = volumeColor)
