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

//@version=4
strategy("Double MA Cross", overlay=true, initial_capital=1)

type1 = input("EMA", "MA Type 1", options=["SMA", "EMA", "WMA", "HMA", "VWMA", "RMA", "TEMA"])
len1 = input(10, minval=1, title="Length 1")
src1 = input(close, "Source 1", type=input.source)

type2 = input("EMA", "MA Type 2", options=["SMA", "EMA", "WMA", "HMA", "VWMA", "RMA", "TEMA"])
len2 = input(20, minval=2, title="Length 2")
src2 = input(close, "Source 2", type=input.source)

yearStart = input(2000, 'Year start')
monthStart = input(1, 'Month start', minval=1, maxval=12)

tema(src, len)=>
    ema1 = ema(src, len)
    ema2 = ema(ema1, len)
    ema3 = ema(ema2, len)
    return = 3 * (ema1 - ema2) + ema3

getPoint(type, len, src)=>
    return = type == "SMA" ? sma(src, len) : type == "EMA" ? ema(src, len) : type == "WMA" ? wma(src, len) : type == "HMA" ? hma(src, len) : type == "VWMA" ? vwma(src, len) : type == "RMA" ? rma(src, len) : tema(src, len)

p1 = getPoint(type1, len1, src1)
p2 = getPoint(type2, len2, src2)

timeFilter = (year >= yearStart) and (year > yearStart or (month >= monthStart))
shortCondition = crossunder(p1, p2) and timeFilter
longCondition = crossover(p1, p2) and timeFilter

if (shortCondition)
    strategy.entry("Short", strategy.short)

if (longCondition)
    strategy.entry("Long", strategy.long)

plot(p1, "MA 1", p1 < p2 ? color.red : color.green)
plot(p2, "MA 2", color.blue)
