Plotting SMA and MA of RSI together

2.1k views Asked by At

I am trying to plot an SMA and an SMA of RSI together in one indicator window. Here is my script (based on another script that plotted 2 MAs of RSI, I just changed ma2 from basis to close):

study(title="MAofRSI / MA", shorttitle="MAoRSI / MA", overlay=false)

basis = rsi(close, input(14))

ma1 = sma(basis, input(2))
ma2 = sma(close,input(13))

oversold = input(30)
overbought = input(70)

plot(ma1, title="MA of RSI", color=teal)
plot(ma2, title="SMA", color=orange)

obhist = ma1 >= overbought ? ma1 : overbought
oshist = ma1 <= oversold ? ma1 : oversold

plot(obhist, title="Overbought Highlight", style=histogram, color=maroon, histbase=overbought)
plot(oshist, title="Oversold Highlight", style=histogram, color=green, histbase=oversold)

i1 = hline(oversold, title="Oversold Level", color=green)
i2 = hline(overbought, title="Overbought Level", color=maroon)

fill(i1, i2, color=olive, transp=70)

hline(50, title="50 Level", color=black)

However, my new SMA is just a flat line in the bottom:

enter image description here

I was hoping to see them interact together, crossing over one another in a beautiful dance. Obviously something is amiss with my methods here...

1

There are 1 answers

3
e2e4 On BEST ANSWER

Your moving averages are based on different scales:

ma2 is based on close price of the current ticker, and ma1 is based on your rsi function.

While the rsi is a bounded (0,100) oscillator and the moving average of rsi could not leave those bounds, MA based on current ticker's price has no bounds (0, +infinity) and they could not be compared on the same scale.

In pinescript you cannot plot at different scales (rsi's and ticker's) at the same time, only one to select. So you have to plot SMA of close as a separate script on the chart's scale, or invent a boundaries logic and scale to the rsi's Y axis.