4C Moving Avg Cloud
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FourC
//@version=5
//This indicator plots 2 moving averages with a cloud filling the area between the two. 
//Features the ability to choose the average type for each of the moving averages.
//Also includes moving average slope direction coloring.
//Some aspects of this indicator were adapted by a few other available indicators by 4C.

indicator(title='4C Moving Avg Cloud', shorttitle='4C MA Cloud', overlay=true)
source = input.source(close, "Source")

lengthshort = input.int(21, minval=1, title='Short Avg Length')
shortavgtype = input.string(title="Short Avg Type", defval="EMA", options=["SMA", "EMA", "WMA", "RMA"])
ma_function1(source, length) =>
	switch shortavgtype
		"RMA" => ta.rma(source, length)
		"SMA" => ta.sma(source, length)
		"EMA" => ta.ema(source, length)
		"WMA" => ta.wma(source, length)

lengthlong = input.int(200, minval=1, title='Long Avg Length')
longavgtype = input.string(title="Long Avg Type", defval="SMA", options=["SMA", "EMA", "WMA", "RMA"])
ma_function2(source, length) =>
	switch longavgtype
		"RMA" => ta.rma(source, length)
		"SMA" => ta.sma(source, length)
		"EMA" => ta.ema(source, length)
		"WMA" => ta.wma(source, length)

showthirdavg = input(title='Show Third Moving Avg?', defval=true)
thirdavglength = input.int(8, minval=1, title='Third Avg Length')
thirdavgtype = input.string(title="Third Avg Type", defval="EMA", options=["SMA", "EMA", "WMA", "RMA"])
ma_function3(source, length) =>
	switch thirdavgtype
		"RMA" => ta.rma(source, length)
		"SMA" => ta.sma(source, length)
		"EMA" => ta.ema(source, length)
		"WMA" => ta.wma(source, length)


mashort = ma_function1(source, lengthshort)
malong = ma_function2(source, lengthlong)
thirdma = ma_function3(source, thirdavglength)

mashortcolor = mashort >= mashort[1] ? color.rgb(0,255,0) : color.rgb(255,0,0)
mashortline = plot(mashort, color=mashortcolor, linewidth=2, title='Short Avg')

malongcolor = malong >= malong[1] ? color.fuchsia : color.rgb(255,0,0)
malongline = plot(malong, color=malongcolor, linewidth=3, title='Long Avg')

thirdmacolor = thirdma >= thirdma[1] ? color.rgb(0,255,255) : color.rgb(255,0,0)
thirdmaline = plot(showthirdavg ? thirdma : na, color=thirdmacolor, linewidth=1, title='Third Avg')


//CLOUD//

cloudcolor = mashort >= malong ? color.new(color.green,85) : color.new(color.red,85)

showstate = input(title='Show Wide State Cloud Shading?', defval=true)
wide = input(title='Wide State Multiplier', defval=8)

[kcmiddle, kcupper, kclower] = ta.kc(close, lengthlong, wide)
widestatecolor = showstate and mashort >= kcupper or mashort <= kclower and showstate ? color.new(color.blue,85) : cloudcolor

fill(mashortline, malongline, color=widestatecolor, title='MA Cloud')
