Z Score (Close + High and Low bands)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sp3ed

//@version=5
indicator('Z Score (Close + High and Low)', 'Z Score')

length      = input(34)

src         = input(hlcc4)

z           = (src - ta.ema(src, length)) / ta.stdev(src, length)
z_low       = (low - ta.ema(src, length)) / ta.stdev(src, length)
z_high      = (high - ta.ema(src, length)) / ta.stdev(src, length)

stdev       = input(2)

gradient = color.from_gradient(z, -1, 1, color.new(#e91e63, 0), color.new(#4caf50, 0))

c = plot(z, color=gradient, linewidth=2)
l = plot(z_low, color=na)
h = plot(z_high, color=na)

fill(l, h, color.new(gradient, 70))


h0 = hline(0, linestyle=hline.style_dotted, color=color.new(color.gray, 0))
h_upper = hline(stdev, linestyle=hline.style_dotted, color=color.new(color.gray, 0))
h_lower = hline(-stdev, linestyle=hline.style_dotted, color=color.new(color.gray, 0))
