Dual Commodity Channel Index
//This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
//@author  = Morogan
//© Morogan

//DUAL COMMODITY CHANNEL INDEX
//This script plots two CCI indicators with independent lengths. It also provides a Zero line and a MACD-like histogram for reference.
//Using two CCI indicators with independent lengths instead of just one provides de-noising functionality similarly to MACD.
//When both CCIs cross the Zero line, it can serve as confirmation of position entry/exit.

indicator(title="Dual Commodity Channel Index", shorttitle="DCCI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)

col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")

length1 = input.int(25, minval=1)
length2 = input.int(50, minval=1)
src = input(hlc3, title="Source")
ma1 = ta.sma(src, length1)
ma2 = ta.sma(src, length2)
cci1 = (src - ma1) / (0.015 * ta.dev(src, length1))
cci2 = (src - ma2) / (0.015 * ta.dev(src, length2))
hist = cci1 - cci2
plot(cci1, "CCI1", color=color.red)
plot(cci2, "CCI2", color=color.blue, linewidth=2)
plot(hist, "Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
hline(0, title="Zero", color=color.gray, linestyle=hline.style_dotted)
band1 = hline(100, "Upper Band", color=#787B86, linestyle=hline.style_dashed)
band0 = hline(-100, "Lower Band", color=#787B86, linestyle=hline.style_dashed)
fill(band1, band0, color=color.rgb(33, 150, 243, 90), title="Background")