In the RSI indicator in pinescript, it has the following :
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
What i don’t understand is why the math.max function is used? As i understand it, the RSI adds up the gains over a lookback period and takes an average of them (same for losses), so why is it using the math.max function?
I’m obviously missing something here, just eager to learn how this is put together.
Maybe someone could explain a bit more in layman’s terms how its calculating this.
Thanks