OPEN-SOURCE SCRIPT

MA 20, 50, 200

//version=5
indicator("MA 20, 50, 200", overlay=true)

// Calculate the 20-period, 50-period, and 100-period Simple Moving Averages
ma20 = ta.sma(close, 20)
ma50 = ta.sma(close, 50)
ma200 = ta.sma(close, 200)

// Plot the moving averages on the chart
plot(ma20, color=color.green, linewidth=2, title="MA 20")
plot(ma50, color=color.blue, linewidth=2, title="MA 50")
plot(ma200, color=color.red, linewidth=2, title="MA 200")


This function plots each of the moving averages on the chart.
The color parameter sets the color for each SMA:
MA 20 is plotted in green
MA 50 is plotted in blue
MA 200 is plotted in red
Moving Averages

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 publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer