Momentum Cloud
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TheRiskChair
// @version=5
indicator(title="Momentum Cloud", shorttitle="Mom. Cloud", overlay=true)


conversionPeriods = input.int(20, minval=1, title="Conversion Line Length")
basePeriods = input.int(60, minval=1, title="Base Line Length")
laggingSpan2Periods = input.int(120, minval=1, title="Leading Span B Length")
displacement = input.int(30, minval=1, title="Displacement")
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
avLine = (leadLine1 + leadLine2) / 2


p1 = plot(leadLine1, offset = displacement - 1, color=#1dc400,
	 title="Leading Span A")
p2 = plot(leadLine2, offset = displacement - 1, color=#c40000,
	 title="Leading Span B")
	 
fillColor = leadLine1 > leadLine2 ? (color.from_gradient(close, leadLine2, leadLine1, color.new(#3363ff85, 85), color.new(#36ff4a,85))) : leadLine1 < leadLine2 ? color.from_gradient(close, leadLine1, leadLine2, color.new(#fc0000,85), color.new(#3363ff,85)) : na
fill(p1, p2, fillColor)