Moving Averages Different Type & Source
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradersoumya

//@version=5
indicator('Moving Averages Different Type & Source', shorttitle='MA', overlay=true)

toggleColor = input(defval=true, title='Toggle Color on Crossovers')

MA1Visible = input.bool(title='MA1', defval=true, inline='I1', group='Moving Averages')
MA2Visible = input.bool(title='MA2', defval=true, inline='I2', group='Moving Averages')
MA3Visible = input.bool(title='MA3', defval=true, inline='I3', group='Moving Averages')
MA4Visible = input.bool(title='MA4', defval=true, inline='I4', group='Moving Averages')
MA5Visible = input.bool(title='MA5', defval=true, inline='I5', group='Moving Averages')
MA6Visible = input.bool(title='MA6', defval=true, inline='I6', group='Moving Averages')

MA1Length = input.int(title='Len', minval=1, maxval=500, defval=9, inline='I1', group='Moving Averages')
MA2Length = input.int(title='Len', minval=1, maxval=500, defval=20, inline='I2', group='Moving Averages')
MA3Length = input.int(title='Len', minval=1, maxval=500, defval=50, inline='I3', group='Moving Averages')
MA4Length = input.int(title='Len', minval=1, maxval=500, defval=100, inline='I4', group='Moving Averages')
MA5Length = input.int(title='Len', minval=1, maxval=500, defval=150, inline='I5', group='Moving Averages')
MA6Length = input.int(title='Len', minval=1, maxval=500, defval=200, inline='I6', group='Moving Averages')

MA1Type = input.string(title='Type', options=['SMA','EMA'], defval='SMA', inline='I1', group='Moving Averages')
MA2Type = input.string(title='Type', options=['SMA','EMA'], defval='EMA', inline='I2', group='Moving Averages')
MA3Type = input.string(title='Type', options=['SMA','EMA'], defval='EMA', inline='I3', group='Moving Averages')
MA4Type = input.string(title='Type', options=['SMA','EMA'], defval='EMA', inline='I4', group='Moving Averages')
MA5Type = input.string(title='Type', options=['SMA','EMA'], defval='EMA', inline='I5', group='Moving Averages')
MA6Type = input.string(title='Type', options=['SMA','EMA'], defval='EMA', inline='I6', group='Moving Averages')

MA1Source = input.source(title='Src', defval=high, inline='I1', group='Moving Averages')
MA2Source = input.source(title='Src', defval=close, inline='I2', group='Moving Averages')
MA3Source = input.source(title='Src', defval=close, inline='I3', group='Moving Averages')
MA4Source = input.source(title='Src', defval=close, inline='I4', group='Moving Averages')
MA5Source = input.source(title='Src', defval=close, inline='I5', group='Moving Averages')
MA6Source = input.source(title='Src', defval=close, inline='I6', group='Moving Averages')


//***************************************************************************************
// Plot moving averages
//***************************************************************************************

MA1 = MA1Type == 'SMA' ? ta.sma(MA1Source, MA1Length) : ta.ema(MA1Source, MA1Length)
MA2 = MA2Type == 'SMA' ? ta.sma(MA2Source, MA2Length) : ta.ema(MA2Source, MA2Length)
MA3 = MA3Type == 'SMA' ? ta.sma(MA3Source, MA3Length) : ta.ema(MA3Source, MA3Length)
MA4 = MA4Type == 'SMA' ? ta.sma(MA4Source, MA4Length) : ta.ema(MA4Source, MA4Length)
MA5 = MA5Type == 'SMA' ? ta.sma(MA5Source, MA5Length) : ta.ema(MA5Source, MA5Length)
MA6 = MA6Type == 'SMA' ? ta.sma(MA6Source, MA6Length) : ta.ema(MA6Source, MA6Length)

plotColor1 = toggleColor ? close < MA1 ? color.red : color.lime : color.maroon
plotColor2 = toggleColor ? close < MA2 ? color.red : color.lime : color.red
plotColor3 = toggleColor ? close < MA3 ? color.red : color.lime : color.green
plotColor4 = toggleColor ? close < MA4 ? color.red : color.lime : color.blue
plotColor5 = toggleColor ? close < MA5 ? color.red : color.lime : color.orange
plotColor6 = toggleColor ? close < MA6 ? color.red : color.lime : color.yellow

plot(MA1Visible and MA1 ? MA1 : na, color=plotColor1, linewidth=1)
plot(MA2Visible and MA2 ? MA2 : na, color=plotColor2, linewidth=2)
plot(MA3Visible and MA3 ? MA3 : na, color=plotColor3, linewidth=3)
plot(MA4Visible and MA4 ? MA4 : na, color=plotColor4, linewidth=4)
plot(MA5Visible and MA5 ? MA5 : na, color=plotColor5, linewidth=5)
plot(MA6Visible and MA6 ? MA6 : na, color=plotColor6, linewidth=6)

//======MA Table========//
baseSymbol = request.security(syminfo.tickerid, timeframe.period, close)

var table maTable = table.new(position.top_right, 1, 10, border_width=1)

table.cell(maTable, 0, 0, 'MA', bgcolor=color.new(color.blue, 0), text_color=color.white)
table.cell(maTable, 0, 1, str.tostring(math.round(MA1)), bgcolor=baseSymbol >= MA1 ? color.new(color.green, 0) : color.new(color.red, 0), text_color=color.white)
table.cell(maTable, 0, 2, str.tostring(math.round(MA2)), bgcolor=baseSymbol >= MA2 ? color.new(color.green, 0) : color.new(color.red, 0), text_color=color.white)
table.cell(maTable, 0, 3, str.tostring(math.round(MA3)), bgcolor=baseSymbol >= MA3 ? color.new(color.green, 0) : color.new(color.red, 0), text_color=color.white)
table.cell(maTable, 0, 4, str.tostring(math.round(MA4)), bgcolor=baseSymbol >= MA4 ? color.new(color.green, 0) : color.new(color.red, 0), text_color=color.white)
table.cell(maTable, 0, 5, str.tostring(math.round(MA5)), bgcolor=baseSymbol >= MA5 ? color.new(color.green, 0) : color.new(color.red, 0), text_color=color.white)
table.cell(maTable, 0, 6, str.tostring(math.round(MA6)), bgcolor=baseSymbol >= MA6 ? color.new(color.green, 0) : color.new(color.red, 0), text_color=color.white)
