RicardoSantos

[RS]Moving Average Cross System V0

moving average crossover with added functions:
if you want crossover with price set ma1 length to 1, or use as dual ma with both lengths, ability to turn ma's on and off leaving the crossover signals behind, ability to chose ma mode (sma, ema, rma, wma, vwma, swma and alma), ability to chose source (open, high, low, close, hl2, hlc3 or ohlc4).
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
study(title="[RS]Moving Average Cross System V0", shorttitle="[RS]MACS.V0", overlay=true)
matype = input("sma")
hidema = input(false)
sourcetype = input("close")
source = sourcetype == "open" ? open :
        sourcetype == "high" ? high :
        sourcetype == "low" ? low :
        sourcetype == "close" ? close :
        sourcetype == "hl2" ? hl2 :
        sourcetype == "hlc3" ? hlc3 :
        sourcetype == "ohlc4" ? ohlc4 : na

length1 = input(1)
length2 = input(10)

ma1 = matype == "sma" ? sma(source, length1) :
        matype == "ema" ? ema(source, length1) : 
        matype == "rma" ? rma(source, length1) :
        matype == "wma" ? wma(source, length1) :
        matype == "vwma" ? vwma(source, length1) :
        matype == "swma" ? sma(swma(source), length1) :
        matype == "alma" ? alma(source, length1, 0.85, 0) : na
ma2 = matype == "sma" ? sma(source, length2) :
        matype == "ema" ? ema(source, length2) : 
        matype == "rma" ? rma(source, length2) :
        matype == "wma" ? wma(source, length2) :
        matype == "vwma" ? vwma(source, length2) :
        matype == "swma" ? sma(swma(source), length2) :
        matype == "alma" ? alma(source, length1, 0.85, 0) : na

signal = cross(ma1, ma2) ? ma2 : na
signalcolor = source > ma2 ? green : maroon
plot(hidema ? na : ma1, color=gray, linewidth=1)
plot(hidema ? na : ma2, color=black, linewidth=1)
plot(signal, style=cross, color=signalcolor, linewidth=4)