Search code examples
pine-scripttradingview-apirsipine-editor

Calculate RSI gain/difference in Pine Editor?


By using the command "crossover" I can successfully display the intersections of the RSI-value and the RSI-sma.

rsiValue = rsi(close, 14)
rsiSMA   = sma(rsiValue, 14)
bgcolor(color=crossover(rsiValue, rsiSMA) ? #ffc1cc : na, transp=60)
bgcolor(color=crossover(rsiSMA, rsiValue) ? #00ffaa : na, transp=80)

Next, I would like to use the same colored markers as above to indicate when the current RSI value is e.g. 5 points above the previous RSI value. What command can I use for this? So instead of "crossover" something like "previous value" ???


Solution

  • Found it out for myself through a YouTube video. The solution is:

    bgcolor(color=(rsiValue - rsiValue[1] >= 5) ?  #4cf346 : na, transp=80)
    bgcolor(color=(rsiValue[1] - rsiValue >= 5) ?  #ffc1cc : na, transp=70)
    

    The square bracket [1] means the previous candlestick.