Price Volume Divergence
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kikfraben
// Updated last on Sep. 24, 2023
//@version=5

indicator("Price Volume Divergence", shorttitle = "PVD", overlay = false)

// User Inputs
pvd_cor_len = input(30, "PVD Length", group = "PVD Inputs")
// Calculations
pvd_price = close
pvd_vol = volume
pvd_cor = ta.correlation(pvd_price, pvd_vol, pvd_cor_len)
pvd_col = pvd_cor > 0 ? #3fa8c9 : #c93f3f
// Plots
plot(pvd_cor, color = pvd_col)
// H-Lines
zero_line = hline(0, color = color.gray, linestyle = hline.style_dashed, linewidth = 1)
l = hline(-0.75, color = color.new(#c93f3f, 90), linestyle = hline.style_solid)
ll = hline(-1, color = color.new(#c93f3f, 90), linestyle = hline.style_solid)
h = hline(0.75, color = color.new(#3fa8c9, 90), linestyle = hline.style_solid)
hh = hline(1, color = color.new(#3fa8c9, 90), linestyle = hline.style_solid)
// H-Line Fill
fill(l, ll, color = color.new(#c93f3f, 90))
fill(h, hh, color = color.new(#3fa8c9, 90))