RSI indicators are group of technical tools that market traders use to gauge momentum of a market.
The group of RSI-based indicators includes the default RSI, which is the short for relative strength index, as well as various transformations of it. Most popular one would be the stochastic RSI, the easiest to use but lesser known would be the Inverse Fisher RSI.
This is the basic RSI indicator source code in pine:
//@version=4 study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="") len = input(14, minval=1, title="Length") src = input(close, "Source", type = input.source) up = rma(max(change(src), 0), len) down = rma(-min(change(src), 0), len) rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down)) plot(rsi, "RSI", color=#7E57C2) band1 = hline(70, "Upper Band", color=#787B86) bandm = hline(50, "Middle Band", color=color.new(#787B86, 50)) band0 = hline(30, "Lower Band", color=#787B86) fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")
Translation from pine into English:
- Call it Relative Strength Index.
- Take 14 past candles for the length.
- Retrieve their values at Close all over your length. up and down: Compare every two consecutive Closes and find out if the price went up or down between them.
- If the price went up, set the down value to 0. If the price went down, set to up value to 0.
- Still on the same line: Get the weighted moving average of both up and down over your length.
- Scale the ratio of averaged up vs down to fit between values of 0 and 100 to make it into a relative index.
- Color it pretty!