DocsStrategy APIindicators

RSI (Relative Strength Index)

The RSI measures the speed and magnitude of recent price changes on a 0-100 scale. It identifies overbought (>70) and oversold (<30) conditions.

Declaration

function init(ctx) { ctx.indicator('rsi', 'RSI', { period: 14, source: 'close' }); }

Options

OptionTypeDefaultDescription
periodnumber14Lookback period
sourcestring'close'Price source

Output

Returns a single number[] series with values between 0 and 100.

Accessing Values

function onBar(ctx, i) { const rsiValue = ctx.ind.rsi[i]; }

Use Cases

Overbought / Oversold

function onBar(ctx, i) { const rsi = ctx.ind.rsi[i]; if (rsi < 30) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'oversold' }); } if (rsi > 70) { ctx.order.close('ASSET', { signal: 'sell', reason: 'overbought' }); } }

RSI Divergence

function onBar(ctx, i) { const rsi = ctx.ind.rsi[i]; const close = ctx.series.close[i]; const prevRsi = ctx.ind.rsi[i - 5]; const prevClose = ctx.series.close[i - 5]; // Bullish divergence: price makes lower low, RSI makes higher low if (close < prevClose && rsi > prevRsi && rsi < 40) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'bullish_divergence' }); } }

Value Ranges

RangeInterpretation
0 - 30Oversold
30 - 70Neutral
70 - 100Overbought

Calculation

$$RSI = 100 - \frac{100}{1 + RS}$$

Where $RS = \frac{\text{Average Gain}}{\text{Average Loss}}$

Related

  • Stochastic RSI - RSI fed into stochastic formula
  • CCI - Another mean-reversion oscillator
  • Williams %R - Similar overbought/oversold indicator
indicatorrsimomentumoscillatoroverboughtoversoldqsl