//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Tykhe_Ideas
study("HWAP", shorttitle="HWAP")
length = input(20)
smoothness = input(1)
src = input(close)
//--------------------------- Hull Moving average -----------------------------------
hull(x, longitud) =>
hullma = wma(2*wma(x, longitud/2)-wma(x, longitud), round(sqrt(longitud)))
calc_zvwap(pds) =>
//mean = sum(volume * close, pds) / sum(volume, pds)
mean = hull(src, 50)
vwapsd = sqrt(sma(pow(close - mean, 2), pds))
(close - mean) / vwapsd
plot(0)
upperTop = input(2.5)
upperBottom = input(2.0)
lowerTop = input(-2.5)
lowerBottom = input(-2.0)
plot(1, style=3, color=color.gray)
plot(-1, style=3, color=color.gray)
ul1 = plot(upperTop, "OB High")
ul2 = plot(upperBottom, "OB Low")
fill(ul1, ul2, color=color.red)
ll1 = plot(lowerTop, "OS High")
ll2 = plot(lowerBottom, "OS Low")
fill(ll1, ll2, color=color.green)
wvap_smoothness = ema(calc_zvwap(length), smoothness)
plot(wvap_smoothness, title="ZVWAP", color=color.black, linewidth=2)
// Correlation HWAP y activo
c = correlation(wvap_smoothness, close, 21) * 2.5
plot(c)