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
| Option | Type | Default | Description |
|---|---|---|---|
period | number | 14 | Lookback period |
source | string | '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
| Range | Interpretation |
|---|---|
| 0 - 30 | Oversold |
| 30 - 70 | Neutral |
| 70 - 100 | Overbought |
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