STOCHRSI (Stochastic RSI)
Stochastic RSI applies the Stochastic Oscillator formula to RSI values instead of price. This creates a more sensitive indicator that reaches overbought/oversold more frequently than standard RSI.
Declaration
function init(ctx) { ctx.indicator('stochRsi', 'STOCHRSI', { rsiPeriod: 14, stochPeriod: 14, kPeriod: 3, dPeriod: 3 }); }
Options
| Option | Type | Default | Description |
|---|---|---|---|
rsiPeriod | number | 14 | RSI calculation period |
stochPeriod | number | 14 | Stochastic lookback period |
kPeriod | number | 3 | %K smoothing period |
dPeriod | number | 3 | %D smoothing period |
Output
Returns an object with two series, accessed via underscore naming:
| Property | Description |
|---|---|
k | %K line (smoothed stochastic RSI) |
d | %D line (smoothed %K) |
Accessing Values
function onBar(ctx, i) { const k = ctx.ind.stochRsi_k[i]; const d = ctx.ind.stochRsi_d[i]; }
Use Cases
Sensitive Reversal Detection
function onBar(ctx, i) { const k = ctx.ind.stochRsi_k[i]; // StochRSI reaches extremes more often than plain RSI if (k < 0.1) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'stochrsi_extreme_low' }); } if (k > 0.9) { ctx.order.close('ASSET', { signal: 'sell', reason: 'stochrsi_extreme_high' }); } }
Calculation
- Compute RSI
- Apply stochastic formula: $StochRSI = \frac{RSI - Lowest(RSI)}{Highest(RSI) - Lowest(RSI)}$
- %K = SMA(StochRSI, kPeriod)
- %D = SMA(%K, dPeriod)
Related
- RSI - Standard RSI
- STOCH - Standard stochastic oscillator
- Williams %R - Range-based oscillator
indicatorstochrsistochasticrsimomentumoscillatorqsl