ATR Delta
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LeafAlgo

//@version=5
indicator("ATR Delta", overlay=false)

// Calculation Inputs
length = input(20, "ATR Length")

// Calculate ATR
atr = ta.atr(length)

// Calculate ATR Delta
atrDelta = atr - ta.atr(length)[1]

// Signal Line
signalLength = input(14, "Signal Line Length")
signalLine = ta.ema(atrDelta, signalLength)

// Coloration
deltaColor = signalLine > 0 and atrDelta > 0  and atrDelta > signalLine ? color.green : signalLine < 0 and atrDelta < 0 and atrDelta < signalLine ? color.red : color.gray
signalColor = signalLine > 0 ? color.lime : color.fuchsia

// Plotting
plot(atrDelta, color = deltaColor, linewidth=2, title="ATR Delta", style = plot.style_columns)
plot(signalLine, color=signalColor, linewidth=4, title="Signal Line")
hline(0, linewidth = 3)

// Bar Color
barcolor(deltaColor)
bgcolor(color.new(signalColor, 80))
