Volume Z-Score [SuperJump]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SuperJump

//@version=4
study("Volume Z-Score [SuperJump]",max_bars_back=5000, format = format.volume)

len = input(1000, "Z-score Length")
isVolume = input(true, "Bar is Volume (false : Z-Score)")
alertZscore = input(3, "Alert Z-Score")

score1 = input(6.0, "1st Level - Highest trading volume")
score2 = input(4.5, "2nd Level - 2nd highest trading volume")
score3 = input(3, "3rd Level - 3rd highest trading volume")
score4 = input(1.5, "4th Level - 4th highest trading volume")
score5 = input(0, "5th Level - 5th highest trading volume")


volumeData = volume


avgVolume = sma(volumeData, len)
stdDevVolume = stdev(volumeData, len)


zScore = (volumeData - avgVolume) / stdDevVolume


colorPalette = array.new_color(6)
array.set(colorPalette, 0, color.red)
array.set(colorPalette, 1, color.orange)
array.set(colorPalette, 2, color.yellow)
array.set(colorPalette, 3, color.green)
array.set(colorPalette, 4, color.gray)
array.set(colorPalette, 5, color.navy)




zScoreColor = zScore >= score1 ? array.get(colorPalette,0) :
              zScore >= score2 ? array.get(colorPalette,1) :
              zScore >= score3 ? array.get(colorPalette,2) :
              zScore >= score4 ? array.get(colorPalette,3) :
              zScore >= score5 ? array.get(colorPalette,4) :
              array.get(colorPalette,5)


plot(isVolume? volume :zScore, style=plot.style_columns, color=zScoreColor, title="Volume Z-Score")

alertcondition(zScore >= alertZscore, title="Volume Alert", message = "Volume Zscore Alert" )