Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Heuristic:TA Lib Ta lib python STOCHRSI Vs STOCH RSI

From Leeroopedia




Knowledge Sources
Domains Financial_Analysis, Debugging
Last Updated 2026-02-09 22:00 GMT

Overview

The `STOCHRSI` function internally uses `STOCHF` (Stochastic Fast) applied to RSI, not `STOCH` (Stochastic) applied to RSI, which produces different results than many users expect.

Description

A common source of confusion is that `talib.STOCHRSI(close)` does not produce the same results as `talib.STOCH(rsi, rsi, rsi)`. The TA-Lib `STOCHRSI` function internally applies the Fast Stochastic (`STOCHF`) formula to the RSI values, while many traders and charting platforms use the regular Stochastic (`STOCH`) applied to RSI. The difference lies in the smoothing applied: `STOCH` applies an additional SMA smoothing to the %K line that `STOCHF` does not.

Usage

Apply this heuristic when you are computing Stochastic RSI and your results do not match those from other charting platforms or reference implementations. If you need the more commonly expected "STOCH applied to RSI" result, compute RSI first and then apply STOCH manually.

The Insight (Rule of Thumb)

  • Action: If you want `STOCH` applied to `RSI` (the commonly expected result), compute it in two steps: `rsi = talib.RSI(close)` then `k, d = talib.STOCH(rsi, rsi, rsi)`.
  • Value: `talib.STOCHRSI(close)` is equivalent to `talib.STOCHF(rsi, rsi, rsi)`, not `talib.STOCH(rsi, rsi, rsi)`.
  • Trade-off: The two-step approach requires an extra function call but matches the behavior most traders expect.

Reasoning

This is a well-documented gotcha in the TA-Lib project. The confusion arises because different financial data providers and charting platforms implement "Stochastic RSI" differently. The TA-Lib C library chose the STOCHF variant, which is technically correct per the original academic definition but does not match the common industry convention.

Example demonstrating the difference (from `README.md:292-311`):

>>> import talib
>>> import numpy as np
>>> c = np.random.randn(100)

# This is the library function (uses STOCHF internally)
>>> k, d = talib.STOCHRSI(c)

# This produces the SAME result as STOCHRSI (calling STOCHF)
>>> rsi = talib.RSI(c)
>>> k, d = talib.STOCHF(rsi, rsi, rsi)

# You might want THIS instead (calling STOCH, with additional smoothing)
>>> rsi = talib.RSI(c)
>>> k, d = talib.STOCH(rsi, rsi, rsi)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment