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

//@version=5
indicator("MA COLOR CODED")

ma(source, length, type) =>
    type == "SMA" ? ta.sma(source, length) :
     type == "EMA" ? ta.ema(source, length) :
     type == "SMMA (RMA)" ? ta.rma(source, length) :
     type == "WMA" ? ta.wma(source, length) :
     type == "VWMA" ? ta.vwma(source, length) :
     na



ma_type   = input.string(defval="VWMA", title="1-MA Type: ", options=["SMA", "EMA", "WMA",  "VWMA", "SMMA(RMA)"])


mas  = input(close, "MA Source")
ma1l = input(13, "MA 1 Length") 
ma2l = input(21, "MA 2 Length")
ma1 = ma(mas, ma1l, ma_type)
ma2 = ma(mas, ma2l, ma_type)

ma1p = ma1 > ma1[1]
ma1n = ma1 < ma1[1]

ma2p = ma2 > ma2[1]
ma2n = ma2 < ma2[1]

colorMA = ma1p and ma2p ? color.green : ma1n and ma2n ? color.red : color.black

plot(ma1, color = colorMA, linewidth = 2)
plot(ma2, color = colorMA, linewidth = 2)
