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

//@version=5
indicator("5 Moving Averages", "5 MA", overlay = true, timeframe = "", timeframe_gaps = true)

use_ma1 = input.bool(defval = true, title = "", group = "MA 1", inline = "MA 1")
ma1_type = input.string(defval = "SMA", title = "Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = "MA 1", inline = "MA 1")
ma1_length = input.int(defval = 25, title = "Length", group = "MA 1")
ma1_source = input(defval = close, title="Source", group = "MA 1")
ma1_x_offset = input.int(defval=0, minval=-500, maxval=500, title = "X offset", group = "MA 1")
ma1_y_multiplier = input.float(defval = 1, title  = "Y multiplier", minval = .1, step = 0.1, group = "MA 1")

use_ma2 = input.bool(defval = true, title = "", group = "MA 2", inline = "MA 2")
ma2_type = input.string(defval = "SMA", title = "Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = "MA 2", inline = "MA 2")
ma2_length = input.int(defval = 50, title = "Length", group = "MA 2")
ma2_source = input(defval = close, title="Source", group = "MA 2")
ma2_x_offset = input.int(defval=0, minval=-500, maxval=500, title = "X offset", group = "MA 2")
ma2_y_multiplier = input.float(defval = 1, title  = "Y multiplier", minval = .1, step = 0.1, group = "MA 2")

use_ma3 = input.bool(defval = true, title = "", group = "MA 3", inline = "MA 3")
ma3_type = input.string(defval = "SMA", title = "Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = "MA 3", inline = "MA 3")
ma3_length = input.int(defval = 100, title = "Length", group = "MA 3")
ma3_source = input(defval = close, title="Source", group = "MA 3")
ma3_x_offset = input.int(defval=0, minval=-500, maxval=500, title = "X offset", group = "MA 3")
ma3_y_multiplier = input.float(defval = 1, title  = "Y multiplier", minval = .1, step = 0.1, group = "MA 3")

use_ma4 = input.bool(defval = true, title = "", group = "MA 4", inline = "MA 4")
ma4_type = input.string(defval = "SMA", title = "Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = "MA 4", inline = "MA 4")
ma4_length = input.int(defval = 200, title = "Length", group = "MA 4")
ma4_source = input(defval = close, title="Source", group = "MA 4")
ma4_x_offset = input.int(defval=0, minval=-500, maxval=500, title = "X offset", group = "MA 4")
ma4_y_multiplier = input.float(defval = 1, title  = "Y multiplier", minval = .1, step = 0.1, group = "MA 4")

use_ma5 = input.bool(defval = true, title = "", group = "MA 5", inline = "MA 5")
ma5_type = input.string(defval = "SMA", title = "Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = "MA 5", inline = "MA 5")
ma5_length = input.int(defval = 300, title = "Length", group = "MA 5")
ma5_source = input(defval = close, title="Source", group = "MA 5")
ma5_x_offset = input.int(defval=0, minval=-500, maxval=500, title = "X offset", group = "MA 5")
ma5_y_multiplier = input.float(defval = 1, title  = "Y multiplier", minval = .1, step = 0.1, group = "MA 5")

fun_ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

ma1 = fun_ma(ma1_source, ma1_length, ma1_type)
ma1 := ma1 * ma1_y_multiplier
ma2 = fun_ma(ma2_source, ma2_length, ma2_type)
ma2 := ma2 * ma2_y_multiplier
ma3 = fun_ma(ma3_source, ma3_length, ma3_type)
ma3 := ma3 * ma3_y_multiplier
ma4 = fun_ma(ma4_source, ma4_length, ma4_type)
ma4 := ma4 * ma4_y_multiplier
ma5 = fun_ma(ma5_source, ma5_length, ma5_type)
ma5 := ma5 * ma5_y_multiplier

plot(use_ma1? ma1 : na, title = "MA 1", offset = ma1_x_offset, color = color.rgb(33, 243, 65))
plot(use_ma2? ma2 : na, title = "MA 2", offset = ma2_x_offset, color = color.rgb(33, 243, 226))
plot(use_ma3? ma3 : na, title = "MA 3", offset = ma3_x_offset, color = color.rgb(44, 33, 243))
plot(use_ma4? ma4 : na, title = "MA 4", offset = ma4_x_offset, color = color.rgb(187, 33, 243))
plot(use_ma5? ma5 : na, title = "MA 5", offset = ma5_x_offset, color = color.rgb(243, 33, 68))
