Skip to Content

Stochastic RSI Indicator

The Stochastic RSI (StochRSI) combines the Relative Strength Index with Stochastic oscillator mathematics to provide momentum and overbought/oversold signals on the 1-hour timeframe.

Overview

StochRSI is an oscillator that ranges from 0 to 100, measuring the level of RSI relative to its high-low range over a set period. It’s more sensitive than standard RSI, making it ideal for identifying momentum shifts.

How It Works

Calculation

  1. Calculate RSI over the specified period
  2. Apply Stochastic formula to RSI values:
    StochRSI = (RSI - Lowest RSI) / (Highest RSI - Lowest RSI) × 100
  3. Smooth with moving averages for %K and %D lines

Implementation

# indicators/stochrsi.py import pandas as pd import pandas_ta as ta def calculate_stochrsi( df: pd.DataFrame, length: int = 14, stoch_length: int = 14, smooth_k: int = 3, smooth_d: int = 3 ) -> pd.DataFrame: """ Calculate Stochastic RSI indicator. Args: df: DataFrame with OHLCV data length: RSI period stoch_length: Stochastic period smooth_k: %K smoothing period smooth_d: %D smoothing period Returns: DataFrame with StochRSI columns """ # Calculate StochRSI using pandas-ta stochrsi = ta.stochrsi( close=df['close'], length=length, rsi_length=length, k=smooth_k, d=smooth_d ) # Add columns to dataframe df['stochrsi_k'] = stochrsi[f'STOCHRSIk_{length}_{length}_{smooth_k}_{smooth_d}'] df['stochrsi_d'] = stochrsi[f'STOCHRSId_{length}_{length}_{smooth_k}_{smooth_d}'] return df

Signal Interpretation

Zones

Zone%K RangeInterpretation
Oversold0-20Potential buying opportunity
Neutral20-80Normal momentum
Overbought80-100Potential selling opportunity

Crossover Signals

SignalConditionAction
Bullish Cross%K crosses above %D in oversoldLook for long entry
Bearish Cross%K crosses below %D in overboughtLook for short entry

Role in VRVP Strategy

StochRSI provides momentum timing for entries:

Long Entry Conditions

  • %K crossing above oversold level (20), OR
  • %K moving from oversold while below 60

Short Entry Conditions

  • %K crossing below overbought level (80), OR
  • %K moving from overbought while above 40
def check_stochrsi_signal(df: pd.DataFrame, config: StochRSIConfig) -> str: """Check StochRSI signal for entry.""" k = df['stochrsi_k'].iloc[-1] k_prev = df['stochrsi_k'].iloc[-2] # Bullish: crossing above oversold or recovering from oversold if k_prev < config.oversold and k > config.oversold: return "BULLISH_CROSS" elif k < 60 and k > k_prev and k_prev < config.oversold: return "BULLISH_MOMENTUM" # Bearish: crossing below overbought or falling from overbought if k_prev > config.overbought and k < config.overbought: return "BEARISH_CROSS" elif k > 40 and k < k_prev and k_prev > config.overbought: return "BEARISH_MOMENTUM" return "NEUTRAL"

Configuration

@dataclass class StochRSIConfig: length: int = 14 # RSI period stoch_length: int = 14 # Stochastic period smooth_k: int = 3 # %K smoothing smooth_d: int = 3 # %D smoothing oversold: float = 20.0 # Oversold threshold overbought: float = 80.0 # Overbought threshold

Parameters

ParameterDefaultRangeDescription
length147-21RSI calculation period
stoch_length147-21Stochastic lookback
smooth_k32-5%K smoothing
smooth_d32-5%D smoothing
oversold2010-30Oversold threshold
overbought8070-90Overbought threshold

Parameter Effects

Smoothing (K/D):

  • Higher values → Smoother lines, fewer false signals
  • Lower values → More responsive, more noise

Thresholds:

  • Wider (10/90) → Fewer but stronger signals
  • Narrower (30/70) → More frequent signals

Usage Example

from indicators.stochrsi import calculate_stochrsi from config.settings import StochRSIConfig # Load price data df = load_ohlcv_data("EUR_USD", "1H") # Configure indicator config = StochRSIConfig( length=14, oversold=20.0, overbought=80.0 ) # Calculate df = calculate_stochrsi( df, length=config.length, smooth_k=config.smooth_k, smooth_d=config.smooth_d ) # Check current state k = df['stochrsi_k'].iloc[-1] d = df['stochrsi_d'].iloc[-1] print(f"StochRSI K: {k:.1f}, D: {d:.1f}") if k < config.oversold: print("Currently OVERSOLD - Watch for bullish reversal") elif k > config.overbought: print("Currently OVERBOUGHT - Watch for bearish reversal")

Visual Representation

StochRSI Chart (1H) 100 ┬──────────────────────────────────────── │ ╭─╮ OVERBOUGHT 80 ├─────────────────────────────────────── ← Overbought Level │ ╱ ╲ │ ╱ ╲ 60 ├─────────────────╱───────╲───────────── │ ╭──╮ ╱ ╲ 40 ├────────╱────╲─╱───────────╲─────────── │ ╱ X ╲ │ ╱ ╱ ╲ ╲ 20 ├─────╱──────────────────────────────── ← Oversold Level │ ╱ OVERSOLD 0 ┴──────────────────────────────────────── │ │ │ Bullish Bullish Bearish Cross Momentum Cross

Best Practices

Tips for Using StochRSI:

  1. Wait for zone exit - Don’t trade just because indicator is oversold/overbought
  2. Confirm with trend - Only take signals in Supertrend direction
  3. Watch for divergence - Price making new highs while StochRSI isn’t
  4. Use with confluence - Combine with FVG and Volume Profile

Common Patterns

Bullish Divergence

Price makes lower low, StochRSI makes higher low → Potential reversal up

Bearish Divergence

Price makes higher high, StochRSI makes lower high → Potential reversal down

Last updated on