4c ATR Threshold
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FourC
//This script paints the chart background color when the ATR is below the user defined minimum. A good visual that can help to keep you out of trades that require a certain ATR or greater.
//@version=5

indicator(title="4c ATR Threshold", shorttitle="4C ATR Paint", overlay=true, timeframe="", timeframe_gaps=true)
source = input.source(title="Source", defval=close)
length = input.int(title="Length", defval=14, minval=1)
atrmin = input.float(title="ATR Minimum", defval=2, step=0.1)
smoothing = input.string(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])

ma_function(source, length) =>
	switch smoothing
		"RMA" => ta.rma(source, length)
		"SMA" => ta.sma(source, length)
		"EMA" => ta.ema(source, length)
		"WMA" => ta.wma(source, length)

atrref = ma_function(ta.tr(true), length)

bgcolor(atrref < atrmin ? color.rgb(255,0,0,95) : na)