High Liquidity Zones and Threshold Volume
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LeafAlgo

//@version=5
indicator("High Liquidity Zones", overlay=false)

lookbackPeriod = input(20, "Lookback Period")
thresholdPercentage = input(100, "Threshold Percentage")

// Calculate average volume over the lookback period
averageVolume = ta.sma(volume, lookbackPeriod)

// Calculate the threshold volume level
thresholdVolume = averageVolume * (thresholdPercentage / 100)

// Calculate the threshold volume SMA
tvsma = ta.sma(thresholdVolume, lookbackPeriod)

// Identify high liquidity zones
isHighLiquidity = volume > thresholdVolume

hlcolor = isHighLiquidity ? color.lime : color.fuchsia

// Plotting high liquidity zones and threshold volume
plotshape(isHighLiquidity, "High Liquidity", shape.square, location.belowbar, color=color.lime, size=size.small)
plot(thresholdVolume, 'Threshold Volume Histogram', color=hlcolor, style=plot.style_histogram, linewidth=4)
plot(thresholdVolume, 'Threshold Volume Outline', color=color.yellow, linewidth=3)
plot(tvsma, 'Threshold Volume SMA', color=color.maroon, linewidth=3)

// Plotting barcolor
barcolor(hlcolor)
