Price Volume Trend Crosses 
// 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. 22, 2023
//@version=5

indicator("Price Volume Trend Crosses ", "PVTC ", false, format.volume)

// PVTC User Inputs
pvt_sig_length = input(22, "PVTC Signal Length", group = "PVTC Inputs")
pvt_sig_type = input.string(title = "PVTC Signal Type", group = "PVTC Inputs", defval = "EMA", options = ["EMA", "SMA"])
pvt_fill_gap = input.bool(true, "Fill Gaps", group = "PVTC Inputs")
pvt_plot_cross = input.bool(false, "Highlight Crosses", group = "PVTC Inputs")
// Colors
col_up = input.color(#3fa8c9 , "UP Color", group = "PVTC Inputs")
col_down = input.color(#c93f3f, "DOWN Color", group = "PVTC Inputs")
fill_col_up = input.color(color.new(#3fa8c9, 75), "UP Fill Color", group = "PVTC Inputs")
fill_col_down = input.color(color.new(#c93f3f, 75), "DOWN Fill Color", group = "PVTC Inputs")
// Price Volume Trend
pvt_src = close
pvt = ta.cum(ta.change(pvt_src)/pvt_src[1]*volume)
// Signal PVTC
pvt_sig = pvt_sig_type == "EMA" ? ta.ema(pvt, pvt_sig_length) : ta.sma(pvt, pvt_sig_length)
// Plot Rules PVTC
pvt_color_trend = pvt > pvt_sig ? col_up : col_down
pvt_color_fill = pvt > pvt_sig ? fill_col_up : fill_col_down
pvt_show_color_fill = pvt_fill_gap ? pvt_color_fill : na
pvt_cross_up = ta.crossover(pvt, pvt_sig)
pvt_cross_down = ta.crossunder(pvt, pvt_sig)
// Plot PVTC
plot_pvt = plot(pvt, color = pvt_color_trend)
plot_pvt_sig = plot(pvt_sig, color = pvt_color_trend)
fill(plot_pvt, plot_pvt_sig, color = pvt_show_color_fill)
bgcolor(pvt_plot_cross ? pvt_cross_up ? color.new(#3fa8c9, 50) : na : na)
bgcolor(pvt_plot_cross ? pvt_cross_down ? color.new(#c93f3f, 50) : na : na)
// Strategy Inputs
// pvtc_long = pvt > pvt_sig
// pvtc_short = pvt < pvt_sig
