Volume Gain
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © carlpwilliams2
// This shows the distance, as a percentage, that the volume is currently over the average volume.
//@version=5
indicator("Volume Gain %")
volumeTimeframe = input.timeframe("",title="Volume Timeframe", group="Volume")
volumeMaLength = input.int(30, title="Volume MA length", group="Volume")
volumeGainUpperLimit = input.float(50, title="Volume gain Upper Limit", group="Limits")
volumeGainLowerLimit = input.float(-50, title="Volume gain Lower Limit", group="Limits")


volumeSrc = request.security(syminfo.tickerid,volumeTimeframe,volume, barmerge.gaps_on)

volMa = ta.ema(volumeSrc, volumeMaLength)
volumeGain = ((volumeSrc-volMa)/volumeSrc)*100
volumeBullish = close>open

upper = plot(volumeGainUpperLimit, title="Volume Gain Upper line", color=color.new(color.gray,60))
lower = plot(volumeGainLowerLimit, title="Volume Gain lower line", color=color.new(color.gray,60))
fill(upper,lower,color.new(color.gray,80))
plot(volumeGain, title="Volume Gain", color=volumeBullish?color.green:color.red, linewidth=2)
