Skip to main content

ta.rsi#

Wilder-smoothed Relative Strength Index over values ending at index i.

SYNTAX#

function ta.rsi(values: (number | null)[], length: number, i: number): number | null

ARGUMENTS#

  • values ((number | null)[]) — Series of input values, oldest-first (typically closes).
  • length (number) — Lookback period. Must be positive.
  • i (number) — Current bar index. First valid output at i = length.

RETURNS#

number | null — RSI in [0, 100]. Returns 50 when both average gain and average loss are zero (flat series); 100 when only gains, 0 when only losses.

REMARKS#

Needs length price changes → length + 1 values → first valid i is length (one bar later than SMA/EMA).

EXAMPLE#

// @indicator { name: "RSI", overlay: false }
const closes = [];
function onBar(i, ctx) {
  closes[i] = candles[i].close;
  const v = ta.rsi(closes, 14, i);
  if (v !== null) {
    plot('rsi', v, { color: '#a78bfa', width: 1.5 });
    plot('overbought', 70, { color: '#ef5350', style: 'dashed' });
    plot('oversold',   30, { color: '#26a69a', style: 'dashed' });
  }
}

SEE ALSO#

ta.ema, ta.atr, ta.stdev