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

//@version=5
indicator("Volume Surge", overlay=true, format=format.volume)

lookback = input.int(30, 'Lookback period for average volume')
multiplier = input.float(2, 'Volume surge X')
alert = input.bool(true, 'Sending Alerts when volume surge happened')

vol = volume
sumVol = math.sum(volume, lookback)
avgVol = sumVol / lookback

volSurge = (vol > (avgVol * multiplier))

alertcondition(alert ? volSurge : na, title='Alert if Volume surged', message='Volume surge happened on {{ticker}}')

bgcolor(color= volSurge and (close>open) ? color.new(color.green, 80) : volSurge and (close<open) ? color.new(color.red, 80) : na)


