Jurik Filtered Perfect CCI (PCCI) [Loxx]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © loxx

//@version=5
indicator("Jurik Filtered Perfect CCI (PCCI) [Loxx]", 
     shorttitle = "JFPCCI [Loxx]", 
     overlay = false, 
     timeframe="", 
     timeframe_gaps = true)
    
import loxx/loxxfsrrdspfilts/1
import loxx/loxxjuriktools/1

greencolor = #2DD204
redcolor = #D2042D 

dspinp = input.string("FATL - Fast Adaptive Trend Line", "Digital Filter Type", options = ["FATL - Fast Adaptive Trend Line", "SATL - Slow Adaptive Trend Line", 
     "RFTL - Reference Fast Trend Line", "RSTL - Reference Slow Trend Line"], group = "Digital Filter Settings")
   
src = input.source(hlc3, title="Source", group = "Basic Settings")
jper = input.int(5, title="Jurik Filter Period", group = "Basic Settings")
jphs = input.float(0, title="Jurik Filter Phase", group = "Basic Settings")

colorbars = input.bool(false, "Color bars?", group= "UI Options")

out = 
     dspinp == "FATL - Fast Adaptive Trend Line" ? loxxfsrrdspfilts.fatl(src) :
     dspinp == "SATL - Slow Adaptive Trend Line" ? loxxfsrrdspfilts.satl(src) :
     dspinp == "RFTL - Reference Fast Trend Line" ? loxxfsrrdspfilts.rftl(src) :
     loxxfsrrdspfilts.rstl(src)

val = loxxjuriktools.jurik_filt(src - out, jper, jphs)
colorout = val >= 0 ? greencolor : redcolor

val1p = plot(val, color = colorout, linewidth = 2)

zl = plot(0, color = bar_index % 2 ? color.gray : na, linewidth = 2) 
barcolor(colorbars ? colorout : na)
fcolorout = val >= 0 ? color.new(greencolor, 90) : color.new(redcolor, 90)

fill(val1p, zl, color = fcolorout)