MA with options
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Shad0wCrypt0

//@version=5
indicator("MA with options", shorttitle = 'MA type', overlay= true)

//User can select the  MA type and length of his choice
//defining the first MA length as 12 and creating the drop down menu for the MA type
//Similarly the length and option menus are created for 6 MAs

MA1 = input(12, 'Length of MA1')
MA1_type= input.string(defval="EMA", title = 'MA1 Type', options = ["SMA", "EMA", "RMA", "WMA", "VWMA"])

MA2 = input(21, 'Length of MA2')  
MA2_type= input.string(defval="EMA", title = 'MA2 Type', options = ["SMA", "EMA", "RMA", "WMA", "VWMA"])

MA3 = input(34, 'Length of MA3') 
MA3_type= input.string(defval="EMA", title = 'MA3 Type', options = ["SMA", "EMA", "RMA", "WMA", "VWMA"])

MA4 = input(50, 'Length of MA4')
MA4_type= input.string(defval="SMA", title = 'MA4 Type', options = ["SMA", "EMA", "RMA", "WMA", "VWMA"])

MA5 = input(100, 'Length of MA5') 
MA5_type= input.string(defval="SMA",title = 'MA5 Type', options = ["SMA", "EMA", "RMA", "WMA", "VWMA"])

MA6 = input(200, 'Length of MA6') 
MA6_type= input.string(defval="SMA", title = 'MA6 Type', options = ["SMA", "EMA", "RMA", "WMA", "VWMA"])


//Conditional statements for plotting the type of MA based on the user selection.
//The IF and ELSE statements are applied for all the 6 MAs

MA_1 = if MA1_type == 'SMA'
    ta.sma(close, MA1)
else
    if MA1_type == 'EMA'
        ta.ema(close, MA1)
    else
        if MA1_type == 'RMA'
            ta.rma(close, MA1)
        else
            if MA1_type == 'WMA'
                ta.wma(close, MA1)
            else
                if MA1_type == 'VWMA'
                    ta.vwma(close, MA1)

                            
MA_2 = if MA2_type == 'SMA'
    ta.sma(close, MA2)
else
    if MA2_type == 'EMA'
        ta.ema(close, MA2)
    else
        if MA2_type == 'RMA'
            ta.rma(close, MA2)
        else
            if MA2_type == 'WMA'
                ta.wma(close, MA2)
            else
                if MA2_type == 'VWMA'
                    ta.vwma(close, MA2)

                            
MA_3 = if MA3_type == 'SMA'
    ta.sma(close, MA3)
else
    if MA3_type == 'EMA'
        ta.ema(close, MA3)
    else
        if MA3_type == 'RMA'
            ta.rma(close, MA3)
        else
            if MA3_type == 'WMA'
                ta.wma(close, MA3)
            else
                if MA3_type == 'VWMA'
                    ta.vwma(close, MA3)

                            
MA_4 = if MA4_type == 'SMA'
    ta.sma(close, MA4)
else
    if MA4_type == 'EMA'
        ta.ema(close, MA4)
    else
        if MA4_type == 'RMA'
            ta.rma(close, MA4)
        else
            if MA4_type == 'WMA'
                ta.wma(close, MA4)
            else
                if MA4_type == 'VWMA'
                    ta.vwma(close, MA4)
                            

MA_5 = if MA5_type == 'SMA'
    ta.sma(close, MA5)
else
    if MA5_type == 'EMA'
        ta.ema(close, MA5)
    else
        if MA5_type == 'RMA'
            ta.rma(close, MA5)
        else
            if MA5_type == 'WMA'
                ta.wma(close, MA5)
            else
                if MA5_type == 'VWMA'
                    ta.vwma(close, MA5)

MA_6 = if MA6_type == 'SMA'
    ta.sma(close, MA6)
else
    if MA6_type == 'EMA'
        ta.ema(close, MA6)
    else
        if MA6_type == 'RMA'
            ta.rma(close, MA6)
        else
            if MA6_type == 'WMA'
                ta.wma(close, MA6)
            else
                if MA6_type == 'VWMA'
                    ta.vwma(close, MA6)

//To plot all the Moving Averages on the chart with different colours.

plot(MA_1, 'ma1', color= color.blue)
plot(MA_2, 'ma2', color= color.purple)
plot(MA_3, 'ma3', color= color.orange)
plot(MA_4, 'ma4', color= color.yellow)
plot(MA_5, 'ma5', color= color.gray)
plot(MA_6, 'ma6', color= color.aqua)

//EMA Crossover between EMA21 and EMA34. The crossover and crossunder function is used for MA2 and MA3
EMA_crossover = ta.crossover(MA_2,MA_3)
EMA_crossunder = ta.crossunder(MA_2,MA_3)

//The buy and sell signals are plotted
plotshape(EMA_crossover, title='BUY Signal', style=shape.triangleup, location=location.belowbar, color=color.green, text="BUY", textcolor=color.green, size=size.small)
plotshape(EMA_crossunder, title='SELL Signal', style=shape.triangledown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.red, size=size.small)
