10 MAs Alpha Indicator by Monty
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MONTY
//@version=5

indicator('10 MAs Alpha Indicator by Monty',shorttitle = "Alpha 10 MAs by Monty", overlay=true)

showMAs = input.bool(title='Show All Moving Averages', defval=true, group='Moving Averages')

ShowMA1 = input.bool(title='', defval=true, group='Moving Averages', inline="01")
color MA1 = input.color(color.rgb(0, 255, 255, 0), group='Moving Averages', inline="01")
MA_Period1 = input.int(title='', defval=20, minval=1, group='Moving Averages', inline="01")
string MA1Period = str.tostring(MA_Period1)
MA_Res1 = input.timeframe(title='', defval='', group='Moving Averages', inline="01")
typeMA1 = input.string(title = "", defval = "SMA", options=["SMA", "EMA"], group='Moving Averages', inline="01") //options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]
MA1Period := MA1Period + typeMA1

ShowMA2 = input.bool(title='', defval=true,group='Moving Averages', inline="02")
color MA2 = input.color(color.rgb(0, 0, 255, 0), group='Moving Averages', inline="02")
MA_Period2 = input.int(title='', defval=50, minval=1, group='Moving Averages', inline="02")
string MA2Period = str.tostring(MA_Period2)
MA_Res2 = input.timeframe(title='   ', defval='', group='Moving Averages', inline="02")
typeMA2 = input.string(title = "", defval = "SMA", options=["SMA", "EMA"], group='Moving Averages', inline="02") //options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]
MA2Period := MA2Period + typeMA2

ShowMA3 = input.bool(title='', defval=true,group='Moving Averages', inline="03")
color MA3 = input.color(color.rgb(0, 255, 0, 0), group='Moving Averages', inline="03")
MA_Period3 = input.int(title='', defval=100, minval=1, group='Moving Averages', inline="03")
string MA3Period = str.tostring(MA_Period3)
MA_Res3 = input.timeframe(title='   ', defval='', group='Moving Averages', inline="03")
typeMA3 = input.string(title = "", defval = "SMA", options=["SMA", "EMA"], group='Moving Averages', inline="03") //options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]
MA3Period := MA3Period + typeMA3

ShowMA4 = input.bool(title='', defval=true,group='Moving Averages', inline="04")
color MA4 = input.color(color.rgb(0, 128, 0, 0), group='Moving Averages', inline="04")
MA_Period4 = input.int(title='', defval=200, minval=1, group='Moving Averages', inline="04")
string MA4Period = str.tostring(MA_Period4)
MA_Res4 = input.timeframe(title='   ', defval='', group='Moving Averages', inline="04")
typeMA4 = input.string(title = "", defval = "SMA", options=["SMA", "EMA"], group='Moving Averages', inline="04") //options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]
MA4Period := MA4Period + typeMA4

ShowMA5 = input.bool(title='', defval=false,group='Moving Averages', inline="05")
color MA5 = input.color(color.rgb(128, 128, 0, 80), group='Moving Averages', inline="05")
MA_Period5 = input.int(title='', defval=20, minval=1, group='Moving Averages', inline="05")
string MA5Period = str.tostring(MA_Period5)
MA_Res5 = input.timeframe(title='   ', defval='', group='Moving Averages', inline="05")
typeMA5 = input.string(title = "", defval = "EMA", options=["SMA", "EMA"], group='Moving Averages', inline="05") //options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]
MA5Period := MA5Period + typeMA5

ShowMA6 = input.bool(title='', defval=false,group='Moving Averages', inline="06")
color MA6 = input.color(color.rgb(128, 128, 0, 80), group='Moving Averages', inline="06")
MA_Period6 = input.int(title='', defval=20, minval=1, group='Moving Averages', inline="06")
string MA6Period = str.tostring(MA_Period6)
MA_Res6 = input.timeframe(title='   ', defval='', group='Moving Averages', inline="06")
typeMA6 = input.string(title = "", defval = "EMA", options=["SMA", "EMA"], group='Moving Averages', inline="06") //options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]
MA6Period := MA6Period + typeMA6

ShowMA7 = input.bool(title='', defval=false,group='Moving Averages', inline="07")
color MA7 = input.color(color.rgb(128, 128, 0, 80), group='Moving Averages', inline="07")
MA_Period7 = input.int(title='', defval=20, minval=1, group='Moving Averages', inline="07")
string MA7Period = str.tostring(MA_Period7)
MA_Res7 = input.timeframe(title='   ', defval='', group='Moving Averages', inline="07")
typeMA7 = input.string(title = "", defval = "EMA", options=["SMA", "EMA"], group='Moving Averages', inline="07") //options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]
MA7Period := MA7Period + typeMA7

ShowMA8 = input.bool(title='', defval=false,group='Moving Averages', inline="08")
color MA8 = input.color(color.rgb(128, 128, 0, 80), group='Moving Averages', inline="08")
MA_Period8 = input.int(title='', defval=20, minval=1, group='Moving Averages', inline="08")
string MA8Period = str.tostring(MA_Period8)
MA_Res8 = input.timeframe(title='   ', defval='', group='Moving Averages', inline="08")
typeMA8 = input.string(title = "", defval = "EMA", options=["SMA", "EMA"], group='Moving Averages', inline="08") //options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]
MA8Period := MA8Period + typeMA8

ShowMA9 = input.bool(title='', defval=false,group='Moving Averages', inline="09")
color MA9 = input.color(color.rgb(128, 128, 0, 80), group='Moving Averages', inline="09")
MA_Period9 = input.int(title='', defval=20, minval=1, group='Moving Averages', inline="09")
string MA9Period = str.tostring(MA_Period9)
MA_Res9 = input.timeframe(title='   ', defval='', group='Moving Averages', inline="09")
typeMA9 = input.string(title = "", defval = "EMA", options=["SMA", "EMA"], group='Moving Averages', inline="09") //options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]
MA9Period := MA9Period + typeMA9

ShowMA10 = input.bool(title='', defval=false,group='Moving Averages', inline="10")
color MA10 = input.color(color.rgb(128, 128, 0, 80), group='Moving Averages', inline="10")
MA_Period10 = input.int(title='', defval=20, minval=1, group='Moving Averages', inline="10")
string MA10Period = str.tostring(MA_Period10)
MA_Res10 = input.timeframe(title='   ', defval='', group='Moving Averages', inline="10")
typeMA10 = input.string(title = "", defval = "EMA", options=["SMA", "EMA"], group='Moving Averages', inline="10") //options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]
MA10Period := MA10Period + typeMA10


f_secureSecurity(_symbol, _res, _src) =>  // orignal code line
    request.security(_symbol, _res, _src[1], barmerge.gaps_on, lookahead=barmerge.lookahead_on)
MA_Function1 = f_secureSecurity(syminfo.tickerid, MA_Res1, ta.sma( close, MA_Period1))
MA_Function2 = f_secureSecurity(syminfo.tickerid, MA_Res2, ta.sma( close, MA_Period2))
MA_Function3 = f_secureSecurity(syminfo.tickerid, MA_Res3, ta.sma( close, MA_Period3))
MA_Function4 = f_secureSecurity(syminfo.tickerid, MA_Res4, ta.sma( close, MA_Period4))
MA_Function5 = f_secureSecurity(syminfo.tickerid, MA_Res5, ta.sma( close, MA_Period5))
MA_Function6 = f_secureSecurity(syminfo.tickerid, MA_Res6, ta.sma( close, MA_Period6))
MA_Function7 = f_secureSecurity(syminfo.tickerid, MA_Res7, ta.sma( close, MA_Period7))
MA_Function8 = f_secureSecurity(syminfo.tickerid, MA_Res8, ta.sma( close, MA_Period8))
MA_Function9 = f_secureSecurity(syminfo.tickerid, MA_Res9, ta.sma( close, MA_Period9))
MA_Function10 = f_secureSecurity(syminfo.tickerid, MA_Res10, ta.sma( close, MA_Period10))


switch typeMA1
    "SMA"=>
        MA_Function1 := f_secureSecurity(syminfo.tickerid, MA_Res1, ta.sma( close, MA_Period1))
    "EMA"=>
        MA_Function1 := f_secureSecurity(syminfo.tickerid, MA_Res1, ta.ema( close, MA_Period1))
switch typeMA2
    "SMA"=>
        MA_Function2 := f_secureSecurity(syminfo.tickerid, MA_Res2, ta.sma( close, MA_Period2))
    "EMA"=>
        MA_Function2 := f_secureSecurity(syminfo.tickerid, MA_Res2, ta.ema( close, MA_Period2))
switch typeMA3
    "SMA"=>
        MA_Function3 := f_secureSecurity(syminfo.tickerid, MA_Res3, ta.sma( close, MA_Period3))
    "EMA"=>
        MA_Function3 := f_secureSecurity(syminfo.tickerid, MA_Res3, ta.ema( close, MA_Period3))
switch typeMA4
    "SMA"=>
        MA_Function4 := f_secureSecurity(syminfo.tickerid, MA_Res4, ta.sma( close, MA_Period4))
    "EMA"=>
        MA_Function4 := f_secureSecurity(syminfo.tickerid, MA_Res4, ta.ema( close, MA_Period4))
switch typeMA5
    "SMA"=>
        MA_Function5 := f_secureSecurity(syminfo.tickerid, MA_Res5, ta.sma( close, MA_Period5))
    "EMA"=>
        MA_Function5 := f_secureSecurity(syminfo.tickerid, MA_Res5, ta.ema( close, MA_Period5))
switch typeMA6
    "SMA"=>
        MA_Function6 := f_secureSecurity(syminfo.tickerid, MA_Res6, ta.sma( close, MA_Period6))
    "EMA"=>
        MA_Function6 := f_secureSecurity(syminfo.tickerid, MA_Res6, ta.ema( close, MA_Period6))
switch typeMA7
    "SMA"=>
        MA_Function7 := f_secureSecurity(syminfo.tickerid, MA_Res7, ta.sma( close, MA_Period7))
    "EMA"=>
        MA_Function7 := f_secureSecurity(syminfo.tickerid, MA_Res7, ta.ema( close, MA_Period7))
switch typeMA8
    "SMA"=>
        MA_Function8 := f_secureSecurity(syminfo.tickerid, MA_Res8, ta.sma( close, MA_Period8))
    "EMA"=>
        MA_Function8 := f_secureSecurity(syminfo.tickerid, MA_Res8, ta.ema( close, MA_Period8))
switch typeMA9
    "SMA"=>
        MA_Function9 := f_secureSecurity(syminfo.tickerid, MA_Res9, ta.sma( close, MA_Period9))
    "EMA"=>
        MA_Function9 := f_secureSecurity(syminfo.tickerid, MA_Res9, ta.ema( close, MA_Period9))
switch typeMA10
    "SMA"=>
        MA_Function10 := f_secureSecurity(syminfo.tickerid, MA_Res10, ta.sma( close, MA_Period10))
    "EMA"=>
        MA_Function10 := f_secureSecurity(syminfo.tickerid, MA_Res10, ta.ema( close, MA_Period10))



ma1_plot = plot(showMAs and ShowMA1 ? MA_Function1 : na, title='Moving Average 1', color=MA1 , style=plot.style_line, linewidth=1)
var MA1Label = label.new(x = bar_index, y = MA_Function1, style = label.style_label_left, color = color.rgb(0, 0, 0, 100), textcolor = MA1, text = MA1Period)
label.set_xy(showMAs and ShowMA1 ? (MA1Label) : na, x = bar_index, y = MA_Function1)

ma2_plot = plot(showMAs and ShowMA2 ? MA_Function2 : na, title='Moving Average 2', color=MA2, style=plot.style_line, linewidth=1)
var MA2Label = label.new(x = bar_index, y = MA_Function1, style = label.style_label_left, color = color.rgb(0, 0, 0, 100), textcolor = MA2, text = MA2Period)
label.set_xy(showMAs and ShowMA2 ? (MA2Label) : na, x = bar_index, y = MA_Function2)

ma3_plot = plot(showMAs and ShowMA3 ? MA_Function3 : na, title='Moving Average 3', color=MA3, style=plot.style_line, linewidth=1)
var MA3Label = label.new(x = bar_index, y = MA_Function3, style = label.style_label_left, color = color.rgb(0, 0, 0, 100), textcolor = MA3, text = MA3Period)
label.set_xy(showMAs and ShowMA3 ? (MA3Label) : na, x = bar_index, y = MA_Function3)

ma4_plot = plot(showMAs and ShowMA4 ? MA_Function4 : na, title='Moving Average 4', color=MA4, style=plot.style_line, linewidth=1)
var MA4Label = label.new(x = bar_index, y = MA_Function4, style = label.style_label_left, color = color.rgb(0, 0, 0, 100), textcolor = MA4, text = MA4Period)
label.set_xy(showMAs and ShowMA4 ? (MA4Label) : na, x = bar_index, y = MA_Function4)

ma5_plot = plot(showMAs and ShowMA5 ? MA_Function5 : na, title='Moving Average 5', color=MA5, style=plot.style_line, linewidth=1)
var MA5Label = label.new(x = bar_index, y = MA_Function5, style = label.style_label_left, color = color.rgb(0, 0, 0, 100), textcolor = MA5, text = MA5Period)
label.set_xy(showMAs and ShowMA5 ? (MA5Label) : na, x = bar_index, y = MA_Function5)

ma6_plot = plot(showMAs and ShowMA6 ? MA_Function6 : na, title='Moving Average 6', color=MA6 , style=plot.style_line, linewidth=1)
var MA6Label = label.new(x = bar_index, y = MA_Function6, style = label.style_label_left, color = color.rgb(0, 0, 0, 100), textcolor = MA6, text = MA6Period)
label.set_xy(showMAs and ShowMA1 ? (MA1Label) : na, x = bar_index, y = MA_Function1)

ma7_plot = plot(showMAs and ShowMA7 ? MA_Function7 : na, title='Moving Average 7', color=MA7, style=plot.style_line, linewidth=1)
var MA7Label = label.new(x = bar_index, y = MA_Function7, style = label.style_label_left, color = color.rgb(0, 0, 0, 100), textcolor = MA7, text = MA7Period)
label.set_xy(showMAs and ShowMA7 ? (MA7Label) : na, x = bar_index, y = MA_Function7)

ma8_plot = plot(showMAs and ShowMA8 ? MA_Function8 : na, title='Moving Average 8', color=MA8, style=plot.style_line, linewidth=1)
var MA8Label = label.new(x = bar_index, y = MA_Function8, style = label.style_label_left, color = color.rgb(0, 0, 0, 100), textcolor = MA8, text = MA8Period)
label.set_xy(showMAs and ShowMA8 ? (MA8Label) : na, x = bar_index, y = MA_Function8)

ma9_plot = plot(showMAs and ShowMA9 ? MA_Function9 : na, title='Moving Average 9', color=MA9, style=plot.style_line, linewidth=1)
var MA9Label = label.new(x = bar_index, y = MA_Function9, style = label.style_label_left, color = color.rgb(0, 0, 0, 100), textcolor = MA9, text = MA9Period)
label.set_xy(showMAs and ShowMA9 ? (MA9Label) : na, x = bar_index, y = MA_Function9)

ma10_plot = plot(showMAs and ShowMA10 ? MA_Function10 : na, title='Moving Average 5', color=MA10, style=plot.style_line, linewidth=1)
var MA10Label = label.new(x = bar_index, y = MA_Function10, style = label.style_label_left, color = color.rgb(0, 0, 0, 100), textcolor = MA10, text = MA10Period)
label.set_xy(showMAs and ShowMA10 ? (MA10Label) : na, x = bar_index, y = MA_Function10)


if (ShowMA1==false)
    label.delete(MA1Label)
if (ShowMA2==false)
    label.delete(MA2Label)
if (ShowMA3==false)
    label.delete(MA3Label)
if (ShowMA4==false)
    label.delete(MA4Label)
if (ShowMA5==false)
    label.delete(MA5Label)
if (ShowMA6==false)
    label.delete(MA6Label)
if (ShowMA7==false)
    label.delete(MA7Label)
if (ShowMA8==false)
    label.delete(MA8Label)
if (ShowMA9==false)
    label.delete(MA9Label)
if (ShowMA10==false)
    label.delete(MA10Label)

