Clutter Fitler [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("Clutter Fitler [Loxx]",
     shorttitle = "CF [Loxx]",
     overlay = true, 
     timeframe="", 
     timeframe_gaps = true)

greencolor = #2DD204
redcolor = #D2042D 

clutterFilt(float src, float threshold)=>
    bool out = math.abs(ta.roc(src, 1)) > threshold
    out
    
src = input.source(close, "Source", group = "Basic Settings")
sth = input.float(0.2, "Threshold", group = "Basic Settings", step = 0.01)
per = input.int(30, "Period", group = "Basic Settings")
colorbars = input.bool(true, "Color bars?", group = "UI Options")

out = ta.ema(src, per)
filtTrend = clutterFilt(out, sth)
colorout = filtTrend ? (out > out[1] ? greencolor : out < out[1] ? redcolor : color.gray) : color.gray

plot(out, color = colorout, linewidth = 3)
barcolor(colorbars ? colorout : na)