SonicR PVA Volumes
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © crypteisfuture

//@version=5
indicator("Sonic PVA Volumes")

neutralColor        = color.gray
risingBullColor     = color.green
risingBearColor     = color.red
climaxBullColor     = color.blue
climaxBearColor     = color.maroon

PVA_Climax_Period   = input(14, title='Climax Period')
PVA_Rising_Factor   = input.float(1.61, title='Rising Factor')
PVA_Extreme_Factor  = input.float(4, title='Extreme Factor')

// Normalize volume for Forex and Crypto markets
normalized_volume   = volume / 1000

ma_volume           = ta.sma(normalized_volume, PVA_Climax_Period)

_color = neutralColor
if normalized_volume >= ma_volume * PVA_Rising_Factor
    _color := close > open ? risingBullColor : risingBearColor
    _color

range_1 = (high - low) * normalized_volume
maxRange = math.max(range_1[PVA_Climax_Period], range_1[1])

if range_1 >= maxRange or normalized_volume >= ma_volume * PVA_Extreme_Factor
    _color := close > open ? climaxBullColor : climaxBearColor
    _color

plot(range_1, color=_color, style=plot.style_columns)


strongBullVolume = _color == climaxBullColor
strongBearVolume = _color == climaxBearColor

standartBullVolume = _color == risingBullColor
standartBearVolume = _color == risingBearColor

alertcondition(strongBullVolume, title = 'Strong Bull Volume!', message = 'Strong Bull Volume!')
alertcondition(strongBearVolume, title = 'Strong Bear Volume!', message = 'Strong Bear Volume!')

alertcondition(standartBullVolume, title = 'Standart Bull Volume!', message = 'Standart Bull Volume!')
alertcondition(standartBearVolume, title = 'Standart Bear Volume!', message = 'Standart Bear Volume!')
