Tradingview places a limit on the number of indicators you can place on a chart. If you are on a free or lower paid plan, this means you need to choose your indicators wisely. Users on the free tier are limited to just three indicators and even the first paid pro plan is limited to five. Don’t get me wrong, I am not an indicator junkie but for those of us who like to keep an eye on the 100 and 200 moving average levels, we are going to find our quota used up quickly. Consequently, I decided to develop a simple “multi” SMA indicator so that multiple SMA’s can be monitored whilst only using a single indicator slot.
About the Indicator
Although the indicator does nothing more than it says on the tin, There are a couple of points worth mentioning:
- The indicator will let you view up to 4 SMA’s
- You can set the period for each SMA independently
- You can set the resolution for each SMA independently (So you can see the see the daily SMA level when on the 15-minute chart for example)
- Each SMA can be turned on/off independently to avoid clutter.
The Multiple SMA’s Indicator Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
//@version=3 study("Multi SMA's", overlay=true) //Get SMA Values smaA = input(title='SMA1', type=integer, minval=1, step=1, defval=20) smaB = input(title='SMA2', type=integer, minval=1, step=1, defval=50) smaC = input(title='SMA3', type=integer, minval=1, step=1, defval=100) smaD = input(title='SMA4', type=integer, minval=1, step=1, defval=200) //Set resolutions resA = input(title='SMA1 Resolution', type=resolution, defval="D") resB = input(title='SMA2 Resolution', type=resolution, defval="D") resC = input(title='SMA3 Resolution', type=resolution, defval="D") resD = input(title='SMA4 Resolution', type=resolution, defval="D") //Set switches smaAswitch = input(title="SMA 1 On/Off", type=bool, defval=true) smaBswitch = input(title="SMA 2 On/Off", type=bool, defval=true) smaCswitch = input(title="SMA 3 On/Off", type=bool, defval=true) smaDswitch = input(title="SMA 4 On/Off", type=bool, defval=true) //get data dataA = security(tickerid, resA, sma(close, smaA)) dataB = security(tickerid, resB, sma(close, smaB)) dataC = security(tickerid, resC, sma(close, smaC)) dataD = security(tickerid, resD, sma(close, smaD)) //Plotting plot(smaAswitch ? dataA : na, color=aqua) plot(smaBswitch ? dataB : na, color=orange) plot(smaCswitch ? dataC : na, color=green, linewidth=2) plot(smaDswitch ? dataD : na, color=red, linewidth=2) |
On the charts:
I am sure you know what to expect with an SMA but here is what the indicator looks like on the charts:
Defaults
Mixing daily and minute resolutions
The following screenshot mixes daily and 15-minute 50 and 200 SMA’s on the 15-minute chart.
And there we have it… Not much to it. I hope you find it useful!