Volume Strength
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AngelAlgo


//@version=5

indicator("Volume Strength", overlay = false)

// Input parameters
length = input.int(14, title="Length", minval=1)

// Define a function that calculates cumulative volume for a given period
CumVol(Period) => 
    sum = volume
    for i = 1 to Period 
        sum := sum + nz(volume[i]) 
    sum 

// Calculate the cumulative volume
vol_sum = CumVol(length)

// Calculate the average cumulative volume
avg_vol = ta.sma(vol_sum, length)

// Devide the cumulative volume by the average value
vol_strength = vol_sum  / avg_vol 

// Add horizontal lines to show overbought/oversold levels
hline(1.2, color=color.red, linewidth=2)
hline(0.8, color=color.green, linewidth=2)

// Define a conditional coloring for the volume strength indicator line
volume_strength_color = vol_strength > 1.2 ? color.red : vol_strength < 0.8 ? color.green : color.blue

// Plot the volume strength
plot(vol_strength, title="Volume Strength", color=volume_strength_color, linewidth=2)

// Add alerts for overbought/oversold levels
alertcondition(vol_strength > 1.2, title="Volume Strength Overbought", message="Volume strength is overbought")
alertcondition(vol_strength < 0.8, title="Volume Strength Oversold", message="Volume strength is oversold")
