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

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

stoch           = input.int(14, "Stochastic Length", 1)
stoch_smoothing = input.int(1, "Stochastic Smoothing", 1)
sum_window      = input.int(6, "Sum Window")

// Use the EMA for the stochastic calculation
k2 = ta.ema(ta.stoch(close, high, low, stoch), stoch_smoothing) - 50
sum = math.sum(k2,sum_window)
cum = ta.cum(sum - sum[1])

colour = (cum>=0 ? (cum[1] < cum ? color.rgb(89, 255, 186) : color.rgb(167, 255, 215)) : (cum[1] < cum ? color.rgb(255, 183, 183) : color.red))

// Add labels to the x- and y-axes
plot(cum, color = colour, style = plot.style_area,
 linewidth = 2, title = "Delta Stochastic")

// Add a signal line to the plot
signal = ta.sma(cum, 5)
plot(signal, color = color.orange, style = plot.style_line,
     linewidth = 2, title = "Signal Line")
