I can give an alternative code for this indicator from a library I'm developing for learning purposes:
def RSI(data: pd.DataFrame, window_length=14) -> pd.Series:
"""
Calculate the RSI indicator on a moving window.
Ref: https://www.investopedia.com/terms/r/rsi.asp
"""
df_ = data.copy()
close = df_['Close']
delta = close.diff()
up = delta.clip(lower=0) # Convert negatives to zero.
down = -1 * delta.clip(upper=0) # Convert positives to zero.
# WMA
roll_up = up.ewm(com=window_length - 1, adjust=True, min_periods=window_length).mean()
roll_down = down.ewm(com=window_length - 1, adjust=True, min_periods=window_length).mean()
# Calculate the RSI
RS = roll_up / roll_down
return 100.0 - (100.0 / (1.0 + RS))
def Stochastic_RSI(data: pd.DataFrame, window_length=14) -> pd.Series:
"""
The Stochastic RSI (StochRSI) is an indicator used in technical analysis that ranges between zero and one (or zero and 100 on
some charting platforms) and is created by applying the Stochastic oscillator formula to a set of relative strength index (RSI)
values rather than to standard price data.
Ref: https://www.investopedia.com/terms/s/stochrsi.asp
"""
df_ = data.copy()
rsi = RSI(data=df_, window_length=window_length)
return (rsi - rsi.rolling(window_length).min()) / (rsi.rolling(window_length).max() - rsi.rolling(window_length).min())
A graph:

Technical Analysis Library in Python
technical-analysis-library-in-python.readthedocs.io › en › latest › ta.html
Documentation — Technical Analysis Library in Python 0.1.4 documentation
ta.momentum.stoch(high, low, close, ... Lane. The stochastic oscillator presents the location of the closing price of a stock in relation to the high and low range of the price of a stock over a period of time, typically a 14-day period....
Trading Strategy
tradingstrategy.ai › docs › _modules › pandas_ta › momentum › stoch.html
pandas_ta.momentum.stoch - Trading Strategy documentation
# -*- coding: utf-8 -*- from pandas import DataFrame from pandas_ta.overlap import ma from pandas_ta.utils import get_offset, non_zero_range, verify_series · [docs]def stoch(high, low, close, k=None, d=None, smooth_k=None, mamode=None, offset=None, **kwargs): """Indicator: Stochastic Oscillator (STOCH)""" # Validate arguments k = k if k and k > 0 else 14 d = d if d and d > 0 else 3 smooth_k = smooth_k if smooth_k and smooth_k > 0 else 3 _length = max(k, d, smooth_k) high = verify_series(high, _length) low = verify_series(low, _length) close = verify_series(close, _length) offset = get_offset(
Videos
Stack Overflow
stackoverflow.com › questions › 69856011 › stochastic-oscillator-not-working-on-self-made-dataframe
python - Stochastic Oscillator not working on self-made DataFrame - Stack Overflow
df.ta.stoch(high='high', low='low', k=14, d=3, append=True) However after adding this code, my DataFrame won't show anymore by the print statement and neither does the stochastic when I try to print it. How do I make the stochastic work with my self made DataFrame? If you have any questions, ask away! Thanks in advance! ... #import threading import pandas_ta as ta import websocket import json import pandas as pd from binance import Client client = Client('5Z5VtpcArDgm525AC6sUoy8TJer4tlel4Twt1ENf7OIzeLB2qx6oaLICHL9jVKoa', 'e641miivoiguEU3gOKjuYEvVKdFNazehtovZtJKdQXb2NVxwTeo1AQ2TBDArocWU') histo
Trading Strategy
tradingstrategy.ai › docs › api › technical-analysis › momentum › help › pandas_ta.momentum.stochrsi.html
stochrsi function in pandas_ta.momentum
API documentation for ... Chande and Stanley Kroll and published in Stock & Commodities V.11:5 (189-199) It is a range-bound oscillator with two lines moving between 0 and 100....
Medium
medium.com › @rbdundas › calculate-stochastic-oscillator-in-python-and-pandas-and-chart-with-matplotlib-aafde26b4a1f
Calculate Stochastic Oscillator in Python and Pandas ...
Attorney, Python enthusiast, insurance technology guru, canine aficionado, musician
alpharithms
alpharithms.com › home › tutorials › using the stochastic oscillator in python for algorithmic trading
Using the Stochastic Oscillator in Python for Algorithmic Trading - αlphαrithms
April 10, 2023 - This gives us two new columns: STOCHk_14_3_3 (%k) and STOCHd_14_3_3 (%d), doesn’t bother us with the high/low columns, and only takes a single line of code. The best part? We don’t have to bother ourselves with remembering the stochastic oscillator formula! The pandas_ta library really ...
Trading Strategy
tradingstrategy.ai › docs › api › technical-analysis › momentum › help › pandas_ta.momentum.stoch.html
stoch function in pandas_ta.momentum
API documentation for pandas_ta.momentum.stoch Python function. stoch(high, low, close, k=None, d=None, smooth_k=None, mamode=None, offset=None, **kwargs)[source]# ... The Stochastic Oscillator (STOCH) was developed by George Lane in the 1950’s.
YouTube
youtube.com › watch
Pandas TA: A complete Guide - YouTube
We cover the pandas-ta library, how to calculate various technical indicators, how to create strategies, how to use multi-processing, etc.⭐ Code:https://gith...
Published October 9, 2022
PyPI
pypi.org › project › pandas-ta
pandas-ta · PyPI
A Comprehensive Python 3 Technical Analysis Library with Pandas Dataframe Extension for Quantitative Researchers, Traders, and Investors. ... Tags ai , dataframe extension , finance , indicators , library , machine learning , pandas , ta , technical analysis , trading
» pip install pandas-ta
Trading Strategy
tradingstrategy.ai › docs › _modules › pandas_ta › momentum › stc.html
pandas_ta.momentum.stc - Trading Strategy documentation
Feed external moving averages: Internally calculation.. stc = ta.stc(close=df["close"], tclen=stc_tclen, fast=ma1_interval, slow=ma2_interval, factor=stc_factor) becomes.. extMa1 = df.ta.zlma(close=df["close"], length=ma1_interval, append=True) extMa2 = df.ta.ema(close=df["close"], length=ma2_interval, append=True) stc = ta.stc(close=df["close"], tclen=stc_tclen, ma1=extMa1, ma2=extMa2, factor=stc_factor) The same goes for osc=, which allows the input of an externally calculated oscillator, overriding ma1 & ma2. Sources: Implemented by rengel8 based on work found here: https://www.prorealcode.com/prorealtime-indicators/schaff-trend-cycle2/ Calculation: STCmacd = Moving Average Convergance/Divergance or Oscillator STCstoch = Intermediate Stochastic of MACD/Osc.
GitHub
github.com › Data-Analisis › Technical-Analysis-Indicators---Pandas
GitHub - Data-Analisis/Technical-Analysis-Indicators---Pandas: Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 130+ Indicators · GitHub
Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 130+ Indicators - Data-Analisis/Technical-Analysis-Indicators---Pandas
Starred by 155 users
Forked by 47 users
Languages Python 99.9% | Makefile 0.1%
PyPI
pypi.org › project › pandas-ta-remake › 1.0.4
pandas-ta-remake · PyPI
January 12, 2025 - Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 150+ Indicators
» pip install pandas-ta-remake
Published Jan 12, 2025
Version 1.0.4
Read the Docs
app.readthedocs.org › projects › technical-analysis-library-in-python › downloads › pdf › latest pdf
Technical Analysis Library in Python Documentation Release 0.1.4
August 23, 2022 - Stochastic RSI %k · Returns New feature generated. Return type pandas.Series · class ta.momentum.StochasticOscillator(high: pandas.core.series.Series, low: pandas.core.series.Series, close: pan- das.core.series.Series, window: int · = 14, smooth_window: int = 3, fillna: bool = False) Stochastic Oscillator ·
Xgboosted
xgboosted.github.io › pandas-ta-classic › indicators.html
Indicators Reference — Pandas TA Classic Documentation
Stochastic RSI: stochrsi · TD Sequential: td_seq (Excluded from df.ta.strategy()) Trix: trix · TRIX Histogram: trixh · True strength index: tsi · Ultimate Oscillator: uo · Volume Weighted MACD: vwmacd · Williams %R: willr · Moving averages and trend-following indicators: Arnaud Legoux Moving Average: alma ·
GitHub
github.com › 0xAVX › pandas-ta
GitHub - 0xAVX/pandas-ta: Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 150+ Indicators
Klinger Volume Oscillator (kvo) was developed by Stephen J. Klinger. It is designed to predict price reversals in a market by comparing volume to price.. See help(ta.kvo) Schaff Trend Cycle (stc) is an evolution of the popular MACD incorportating two cascaded stochastic calculations with additional smoothing.
Author 0xAVX
Top answer 1 of 3
11
You can use the following simple function to handle both slow and fast stochastics.
def stochastics(dataframe, low, high, close, k, d ):
"""
Fast stochastic calculation
%K = (Current Close - Lowest Low)/
(Highest High - Lowest Low) * 100
%D = 3-day SMA of %K
Slow stochastic calculation
%K = %D of fast stochastic
%D = 3-day SMA of %K
When %K crosses above %D, buy signal
When the %K crosses below %D, sell signal
"""
df = dataframe.copy()
# Set minimum low and maximum high of the k stoch
low_min = df[low].rolling( window = k ).min()
high_max = df[high].rolling( window = k ).max()
# Fast Stochastic
df['k_fast'] = 100 * (df[close] - low_min)/(high_max - low_min)
df['k_fast'].ffill(inplace=True)
df['d_fast'] = df['k_fast'].rolling(window = d).mean()
# Slow Stochastic
df['k_slow'] = df["d_fast"]
df['d_slow'] = df['k_slow'].rolling(window = d).mean()
return df
stochs = stochastics( df, 'Low', 'High', 'Close', 14, 3 )
slow_k = stochs['k_slow'].values
fast_k = stochs['k_fast'].values
2 of 3
5
You can do this with the rolling_* family of functions.
E.g., 100[(C - L14)/(H14 - L14)] can be found by:
import pandas as pd
l, h = pd.rolling_min(c, 4), pd.rolling_max(c, 4)
k = 100 * (c - l) / (h - l)
and the rolling mean can be found by:
pd.rolling_mean(k, 3)
Moreover, if you're into this stuff, you can check out pandas & econometrics.
Stack Overflow
stackoverflow.com › questions › tagged › pandas-ta
Newest 'pandas-ta' Questions - Stack Overflow
I need the ADX indicator in my Python code and I am using the pandas-ta library. The values given from the pandas-ta library is the smoothed version of the ADX, I need the 'raw' version.
Pandas-ta
pandas-ta.dev
Pandas TA - Pandas TA
A popular and comprehensive Technical Analysis Library in Python 3 that leverages numba and numpy for accuracy and performance, and pandas for simplicity and bulk processing. The library contains more than 150 indicators and utilities as well as 60 Candlestick Patterns when TA Lib is installed ...