OPEN-SOURCE SCRIPT

Trend Showing SMA (10D, 21D, 30W, 50D)

90
//version=6
indicator("Trend Showing SMA (10D, 21D, 10W, 30W, 50D)", overlay=true)

// Define Moving Average Periods
sma10d_length = 10
sma21d_length = 21
sma30w_length = 30
sma50d_length = 50

// Calculate Daily SMAs
sma10d = ta.sma(close, sma10d_length) // 10-day SMA
sma21d = ta.sma(close, sma21d_length) // 21-day SMA
sma50d = ta.sma(close, sma50d_length) // 50-day SMA

// Calculate Weekly SMAs (Using Weekly Data)
sma30w = request.security(syminfo.tickerid, 'W', ta.sma(close, sma30w_length)) // 30-week SMA

// Plot the Moving Averages
plot(sma10d, linewidth=2, color=color.blue, title="10-Day SMA")
plot(sma21d, linewidth=2, color=color.white, title="21-Day SMA")
plot(sma50d, linewidth=1, color=color.orange, title="50-Day SMA")
plot(sma30w, linewidth=2, color=color.green, title="30-Week SMA")

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.