//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © QuantStreet
study("SPX Sentiment", shorttitle="SPX Sentiment")
length = input(50)
vix_close = security("VIX", timeframe.period, close)
spx_close = security("SPX", timeframe.period, close)
smoothness = input(title="Smoothnees", defval=3, minval=0)
mean_line = input(title="Mean Length", defval=100, minval=0)
ratio = spx_close / vix_close
bg_sma = sma(ratio, 200)
bg_color = ratio > bg_sma ? color.green : color.red
calc_zvwap(pds) =>
mean = wma(ratio, length)
vwapsd = sqrt(sma(pow(ratio - mean, 2), pds))
(ratio - mean) / vwapsd
plot(0)
upperTop = input(5) * 10
upperBottom = input(5.0) * 10
lowerTop = input(-5) * 10
lowerBottom = input(-5.0) * 10
line_color = color.black
//plot(10, style=hline.style_dashed, color=color.gray)
//plot(-10, style=hline.style_dashed, color=color.gray)
cg = change(close, 1)
zwap = ema(calc_zvwap(length), smoothness) * 20
zwap_correlation = correlation(zwap, close, 10) * 20
plot(correlation(sma(cg,10), zwap, 10) * 10, color=color.yellow)
//plot(zwap_correlation, color=black, linewidth=2)
plot(sma(zwap, 50), color=color.black)
plot(zwap, title="ZVWAP", color=zwap > 0 ? color.green : color.red, style=plot.style_columns, linewidth=2)
bgcolor(bg_color)