Price Variation Percent (PVP)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Jompatan

//@version=4
study("Price Variation Percent (PVP)")

length = input(1,"Length (bars)")
source = input(close, "Source")
apper_band = input(1.0, "Apper Band (% variation)")
lower_band = input(-1.0, "Lower Band (% variation)")
crossover  = input(true, "Show Crossover")
crossunder = input(true, "Show Crossunder")

//======================================================

pvp= (source - source[length]) / source[length] * 100
cross_over  = crossover(pvp, apper_band)
cross_under = crossunder(pvp, lower_band)

p1= plot(pvp, color=color.white)
p0= plot(0, color= color.new(color.white, 100))

h0 = hline(0, linestyle = hline.style_dotted, color= color.new(color.white, 80))
h1 = hline(apper_band, color= color.new(color.white, 60))
h2 = hline(lower_band, color= color.new(color.white, 60))
fill(h1, h2)
fill(p1, p0, color= pvp > 0 ? color.lime : color.red, transp=0)

//======================================================

plotshape(crossover and cross_over ? pvp+1 : na, style=shape.triangledown, location= location.absolute, size=size.tiny, color=color.lime)
plotshape(crossunder and cross_under ? pvp-1 : na, style=shape.triangleup, location= location.absolute, size=size.tiny, color=color.fuchsia)



