OPEN-SOURCE SCRIPT

20 SMA Cloud

//version=5
indicator("20 SMA Cloud", overlay=true)

// Input length for moving averages
length = 20

// Calculate the 20 SMA and 20 EMA
sma20 = ta.sma(close, length)
ema20 = ta.ema(close, length)

// Plot the SMA and EMA lines
plot(sma20, color=color.blue, linewidth=1, title="20 SMA")
plot(ema20, color=color.blue, linewidth=1, title="20 EMA")

// Fill the area between SMA and EMA to create a cloud
bgcolor = (sma20 > ema20) ? color.new(color.blue, 90) : color.new(color.blue, 90)
fill(plot(sma20), plot(ema20), color=bgcolor, title="SMA Cloud")
educational

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