DocsStrategy APIindicators

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

OptionTypeDefaultDescription
rsiPeriodnumber14RSI calculation period
stochPeriodnumber14Stochastic lookback period
kPeriodnumber3%K smoothing period
dPeriodnumber3%D smoothing period

Output

Returns an object with two series, accessed via underscore naming:

PropertyDescription
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

  1. Compute RSI
  2. Apply stochastic formula: $StochRSI = \frac{RSI - Lowest(RSI)}{Highest(RSI) - Lowest(RSI)}$
  3. %K = SMA(StochRSI, kPeriod)
  4. %D = SMA(%K, dPeriod)

Related

  • RSI - Standard RSI
  • STOCH - Standard stochastic oscillator
  • Williams %R - Range-based oscillator
indicatorstochrsistochasticrsimomentumoscillatorqsl