Aggregated Moving Averages
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hudock

//@version=5
indicator("Aggregated Moving Averages", shorttitle = "AMA", overlay = true, timeframe = "D")

visible1 = input.bool(true, "", inline = "I1")
visible2 = input.bool(true, "", inline = "I2")
visible3 = input.bool(true, "", inline = "I3")
visible4 = input.bool(true, "", inline = "I4")

length1 = input.int(9, "Length", step = 1, inline = "I1")
length2 = input.int(20, "Length", step = 1, inline = "I2")
length3 = input.int(50, "Length", step = 1, inline = "I3")
length4 = input.int(200, "Length", step = 1, inline = "I4")

type1 = input.string("EMA", "Average Type", ["EMA", "SMA"], inline = "I1")
type2 = input.string("EMA", "Average Type", ["EMA", "SMA"], inline = "I2")
type3 = input.string("EMA", "Average Type", ["EMA", "SMA"], inline = "I3")
type4 = input.string("EMA", "Average Type", ["EMA", "SMA"], inline = "I4")

color1 = input.color(color.white, "Color", inline = "I1")
color2 = input.color(color.blue, "Color", inline = "I2")
color3 = input.color(color.red, "Color", inline = "I3")
color4 = input.color(color.green, "Color", inline = "I4")



ema1 = ta.ema(close, length1)
ema2 = ta.ema(close, length2)
ema3 = ta.ema(close, length3)
ema4 = ta.ema(close, length4)

sma1 = ta.sma(close, length1)
sma2 = ta.sma(close, length2)
sma3 = ta.sma(close, length3)
sma4 = ta.sma(close, length4)

ma1 = 0.0
ma2 = 0.0
ma3 = 0.0
ma4 = 0.0

if(visible1)
    ma1 := type1 == 'EMA' ? ta.ema(close,length1) : ta.sma(close, length1)

if(visible2)
    ma2 := type2 == 'EMA' ? ta.ema(close,length2) : ta.sma(close, length2)
    
if(visible3)
    ma3 := type3 == 'EMA' ? ta.ema(close,length3) : ta.sma(close, length3)
    
if(visible4)
    ma4 := type4 == 'EMA' ? ta.ema(close,length4) : ta.sma(close, length4)
    
    
plot(ma1, style = plot.style_stepline, color = color1) 
plot(ma2, style = plot.style_stepline, color = color2) 
plot(ma3, style = plot.style_stepline, color = color3) 
plot(ma4, style = plot.style_stepline, color = color4) 










    


