Candle Volume (Alender)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mob.alender

//@version=5
indicator(title='Candle Volume (Alender)', overlay=true)

length = input(20, title='length', group='Candle Volume settings')

avrg = ta.sma(volume, length)

color_volume = #ffffff
red = 255
green = 255
blue = 255

if open < close
    if volume > avrg
        green := 15 + (240 - math.round(60 * (volume / avrg)))
        if green < 15
            green := 15
        red := 0
        blue := 0
    else
        blue := 15 + (240 - math.round(240 * (volume / avrg)))
        if blue < 15
            blue := 15
        red := 15 + (240 - math.round(240 * (volume / avrg)))
        if red < 15
            red := 15
else
    if volume > avrg
        red := 15 + (240 - math.round(60 * (volume / avrg)))
        if red < 15
            red := 15
        green := 0
        blue := 0
    else
        blue := 15 + (240 - math.round(240 * (volume / avrg)))
        if blue < 15
            blue := 15
        green := 15 + (240 - math.round(240 * (volume / avrg)))
        if green < 15
            green := 15

color_volume := color.rgb(red, green, blue)
barcolor(color_volume, title='Bar Colors')

