CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-ta

Technical Analysis Library in Python for financial time series datasets with 43 indicators across Volume, Volatility, Trend, Momentum, and Others categories

Overview
Eval results
Files

trend-indicators.mddocs/

Trend Indicators

Trend-based technical indicators that identify the direction and strength of market trends, helping traders determine whether an asset is trending up, down, or moving sideways. These indicators smooth out price action to reveal underlying directional bias and provide entry/exit signals based on trend momentum.

Capabilities

Aroon Indicator

Identifies when trends are likely to change direction by measuring how long it has been since the highest high and lowest low occurred within a given period.

class AroonIndicator:
    def __init__(self, high, low, window=25, fillna=False):
        """
        Aroon Indicator.
        
        Parameters:
        - high (Series): Dataset 'High' column
        - low (Series): Dataset 'Low' column
        - window (int): Period for calculation (default: 25)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def aroon_up(self):
        """Returns: Series with Aroon Up Channel values (0-100 scale)"""
    
    def aroon_down(self):
        """Returns: Series with Aroon Down Channel values (0-100 scale)"""
    
    def aroon_indicator(self):
        """Returns: Series with Aroon Indicator values (-100 to 100 scale)"""

def aroon_up(high, low, window=25, fillna=False):
    """Functional interface for Aroon Up Channel"""

def aroon_down(high, low, window=25, fillna=False):
    """Functional interface for Aroon Down Channel"""

def aroon_indicator(high, low, window=25, fillna=False):
    """Functional interface for Aroon Indicator"""

Moving Average Convergence Divergence (MACD)

Trend-following momentum indicator that shows the relationship between two moving averages of a security's price.

class MACD:
    def __init__(self, close, window_slow=26, window_fast=12, window_sign=9, fillna=False):
        """
        Moving Average Convergence Divergence (MACD).
        
        Parameters:
        - close (Series): Dataset 'Close' column
        - window_slow (int): Long-term period (default: 26)
        - window_fast (int): Short-term period (default: 12)
        - window_sign (int): Signal period (default: 9)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def macd(self):
        """Returns: Series with MACD Line values"""
    
    def macd_signal(self):
        """Returns: Series with MACD Signal Line values"""
    
    def macd_diff(self):
        """Returns: Series with MACD Histogram values"""

def macd(close, window_slow=26, window_fast=12, window_sign=9, fillna=False):
    """Functional interface for MACD Line"""

def macd_signal(close, window_slow=26, window_fast=12, window_sign=9, fillna=False):
    """Functional interface for MACD Signal Line"""

def macd_diff(close, window_slow=26, window_fast=12, window_sign=9, fillna=False):
    """Functional interface for MACD Histogram"""

Exponential Moving Average (EMA)

Exponential Moving Average that gives more weight to recent prices, making it more responsive to new information.

class EMAIndicator:
    def __init__(self, close, window=14, fillna=False):
        """
        Exponential Moving Average (EMA).
        
        Parameters:
        - close (Series): Dataset 'Close' column
        - window (int): Period for calculation (default: 14)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def ema_indicator(self):
        """Returns: Series with EMA values"""

def ema_indicator(close, window=14, fillna=False):
    """Functional interface for EMA"""

Simple Moving Average (SMA)

Simple Moving Average that calculates the arithmetic mean of prices over a specified period.

class SMAIndicator:
    def __init__(self, close, window, fillna=False):
        """
        Simple Moving Average (SMA).
        
        Parameters:
        - close (Series): Dataset 'Close' column
        - window (int): Period for calculation (required)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def sma_indicator(self):
        """Returns: Series with SMA values"""

def sma_indicator(close, window, fillna=False):
    """Functional interface for SMA"""

Weighted Moving Average (WMA)

Weighted Moving Average that assigns greater weight to more recent data points within the period.

class WMAIndicator:
    def __init__(self, close, window=9, fillna=False):
        """
        Weighted Moving Average (WMA).
        
        Parameters:
        - close (Series): Dataset 'Close' column
        - window (int): Period for calculation (default: 9)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def wma(self):
        """Returns: Series with WMA values"""

def wma(close, window=9, fillna=False):
    """Functional interface for WMA"""

TRIX Indicator

Shows the percent rate of change of a triple exponentially smoothed moving average, designed to filter out insignificant price movements.

class TRIXIndicator:
    def __init__(self, close, window=15, fillna=False):
        """
        Trix (TRIX).
        
        Parameters:
        - close (Series): Dataset 'Close' column
        - window (int): Period for calculation (default: 15)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def trix(self):
        """Returns: Series with TRIX values (percentage)"""

def trix(close, window=15, fillna=False):
    """Functional interface for TRIX"""

Mass Index

Uses the high-low range to identify trend reversals based on range expansions. Values above 27 typically indicate reversal conditions.

class MassIndex:
    def __init__(self, high, low, window_fast=9, window_slow=25, fillna=False):
        """
        Mass Index (MI).
        
        Parameters:
        - high (Series): Dataset 'High' column
        - low (Series): Dataset 'Low' column
        - window_fast (int): Fast period value (default: 9)
        - window_slow (int): Slow period value (default: 25)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def mass_index(self):
        """Returns: Series with Mass Index values"""

def mass_index(high, low, window_fast=9, window_slow=25, fillna=False):
    """Functional interface for Mass Index"""

Ichimoku Indicator

Ichimoku Kinko Hyo (Ichimoku Cloud) - A comprehensive indicator that defines support/resistance, trend direction, and momentum.

class IchimokuIndicator:
    def __init__(self, high, low, window1=9, window2=26, window3=52, visual=False, fillna=False):
        """
        Ichimoku Kinkō Hyō (Ichimoku).
        
        Parameters:
        - high (Series): Dataset 'High' column
        - low (Series): Dataset 'Low' column
        - window1 (int): Short period (default: 9)
        - window2 (int): Medium period (default: 26)
        - window3 (int): Long period (default: 52)
        - visual (bool): If True, shift period 2 values (default: False)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def ichimoku_conversion_line(self):
        """Returns: Series with Tenkan-sen (Conversion Line) values"""
    
    def ichimoku_base_line(self):
        """Returns: Series with Kijun-sen (Base Line) values"""
    
    def ichimoku_a(self):
        """Returns: Series with Senkou Span A values"""
    
    def ichimoku_b(self):
        """Returns: Series with Senkou Span B values"""

def ichimoku_conversion_line(high, low, window1=9, window2=26, window3=52, visual=False, fillna=False):
    """Functional interface for Tenkan-sen"""

def ichimoku_base_line(high, low, window1=9, window2=26, window3=52, visual=False, fillna=False):
    """Functional interface for Kijun-sen"""

def ichimoku_a(high, low, window1=9, window2=26, window3=52, visual=False, fillna=False):
    """Functional interface for Senkou Span A"""

def ichimoku_b(high, low, window1=9, window2=26, window3=52, visual=False, fillna=False):
    """Functional interface for Senkou Span B"""

KST Indicator (Know Sure Thing)

Momentum oscillator that combines four different rate of change values to identify market cycles and trend changes.

class KSTIndicator:
    def __init__(self, close, roc1=10, roc2=15, roc3=20, roc4=30, 
                 window1=10, window2=10, window3=10, window4=15, nsig=9, fillna=False):
        """
        KST Indicator (Know Sure Thing).
        
        Parameters:
        - close (Series): Dataset 'Close' column
        - roc1 (int): Period for 1st ROC (default: 10)
        - roc2 (int): Period for 2nd ROC (default: 15)
        - roc3 (int): Period for 3rd ROC (default: 20)
        - roc4 (int): Period for 4th ROC (default: 30)
        - window1 (int): Period for 1st SMA (default: 10)
        - window2 (int): Period for 2nd SMA (default: 10)
        - window3 (int): Period for 3rd SMA (default: 10)
        - window4 (int): Period for 4th SMA (default: 15)
        - nsig (int): Signal period (default: 9)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def kst(self):
        """Returns: Series with KST values"""
    
    def kst_sig(self):
        """Returns: Series with KST Signal values"""
    
    def kst_diff(self):
        """Returns: Series with KST Difference values"""

def kst(close, roc1=10, roc2=15, roc3=20, roc4=30, window1=10, window2=10, window3=10, window4=15, nsig=9, fillna=False):
    """Functional interface for KST"""

def kst_sig(close, roc1=10, roc2=15, roc3=20, roc4=30, window1=10, window2=10, window3=10, window4=15, nsig=9, fillna=False):
    """Functional interface for KST Signal"""

def kst_diff(close, roc1=10, roc2=15, roc3=20, roc4=30, window1=10, window2=10, window3=10, window4=15, nsig=9, fillna=False):
    """Functional interface for KST Difference"""

Detrended Price Oscillator (DPO)

Designed to remove trend from price and make it easier to identify cycles by comparing past prices to a displaced moving average.

class DPOIndicator:
    def __init__(self, close, window=20, fillna=False):
        """
        Detrended Price Oscillator (DPO).
        
        Parameters:
        - close (Series): Dataset 'Close' column
        - window (int): Period for calculation (default: 20)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def dpo(self):
        """Returns: Series with DPO values"""

def dpo(close, window=20, fillna=False):
    """Functional interface for DPO"""

Commodity Channel Index (CCI)

Measures the difference between a security's price change and its average price change to identify cyclical turns in commodities.

class CCIIndicator:
    def __init__(self, high, low, close, window=20, constant=0.015, fillna=False):
        """
        Commodity Channel Index (CCI).
        
        Parameters:
        - high (Series): Dataset 'High' column
        - low (Series): Dataset 'Low' column
        - close (Series): Dataset 'Close' column
        - window (int): Period for calculation (default: 20)
        - constant (float): Constant for calculation (default: 0.015)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def cci(self):
        """Returns: Series with CCI values"""

def cci(high, low, close, window=20, constant=0.015, fillna=False):
    """Functional interface for CCI"""

Average Directional Movement Index (ADX)

Designed to quantify trend strength by measuring the strength of price movement in a single direction.

class ADXIndicator:
    def __init__(self, high, low, close, window=14, fillna=False):
        """
        Average Directional Movement Index (ADX).
        
        Parameters:
        - high (Series): Dataset 'High' column
        - low (Series): Dataset 'Low' column
        - close (Series): Dataset 'Close' column
        - window (int): Period for calculation (default: 14)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def adx(self):
        """Returns: Series with ADX values (0-100 scale)"""
    
    def adx_pos(self):
        """Returns: Series with Plus Directional Indicator (+DI) values"""
    
    def adx_neg(self):
        """Returns: Series with Minus Directional Indicator (-DI) values"""

def adx(high, low, close, window=14, fillna=False):
    """Functional interface for ADX"""

def adx_pos(high, low, close, window=14, fillna=False):
    """Functional interface for +DI"""

def adx_neg(high, low, close, window=14, fillna=False):
    """Functional interface for -DI"""

Vortex Indicator

Identifies the start of a new trend or the continuation of an existing trend by measuring positive and negative vortex movements.

class VortexIndicator:
    def __init__(self, high, low, close, window=14, fillna=False):
        """
        Vortex Indicator (VI).
        
        Parameters:
        - high (Series): Dataset 'High' column
        - low (Series): Dataset 'Low' column
        - close (Series): Dataset 'Close' column
        - window (int): Period for calculation (default: 14)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def vortex_indicator_pos(self):
        """Returns: Series with Positive Vortex Indicator values"""
    
    def vortex_indicator_neg(self):
        """Returns: Series with Negative Vortex Indicator values"""
    
    def vortex_indicator_diff(self):
        """Returns: Series with Vortex Indicators difference values"""

def vortex_indicator_pos(high, low, close, window=14, fillna=False):
    """Functional interface for Positive Vortex Indicator"""

def vortex_indicator_neg(high, low, close, window=14, fillna=False):
    """Functional interface for Negative Vortex Indicator"""

def vortex_indicator_diff(high, low, close, window=14, fillna=False):
    """Functional interface for Vortex Indicators difference"""

Parabolic SAR

Trend following indicator that provides exit points for long or short positions by trailing price with accelerating steps.

class PSARIndicator:
    def __init__(self, high, low, close, step=0.02, max_step=0.2, fillna=False):
        """
        Parabolic SAR.
        
        Parameters:
        - high (Series): Dataset 'High' column
        - low (Series): Dataset 'Low' column
        - close (Series): Dataset 'Close' column
        - step (float): Acceleration Factor (default: 0.02)
        - max_step (float): Maximum Acceleration Factor (default: 0.2)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def psar(self):
        """Returns: Series with Parabolic SAR values"""
    
    def psar_up(self):
        """Returns: Series with Parabolic SAR up trend values"""
    
    def psar_down(self):
        """Returns: Series with Parabolic SAR down trend values"""
    
    def psar_up_indicator(self):
        """Returns: Series with Parabolic SAR up trend binary indicator"""
    
    def psar_down_indicator(self):
        """Returns: Series with Parabolic SAR down trend binary indicator"""

def psar(high, low, close, step=0.02, max_step=0.2, fillna=False):
    """Functional interface for Parabolic SAR"""

def psar_up(high, low, close, step=0.02, max_step=0.2, fillna=False):
    """Functional interface for Parabolic SAR up trend"""

def psar_down(high, low, close, step=0.02, max_step=0.2, fillna=False):
    """Functional interface for Parabolic SAR down trend"""

def psar_up_indicator(high, low, close, step=0.02, max_step=0.2, fillna=False):
    """Functional interface for Parabolic SAR up trend indicator"""

def psar_down_indicator(high, low, close, step=0.02, max_step=0.2, fillna=False):
    """Functional interface for Parabolic SAR down trend indicator"""

Schaff Trend Cycle (STC)

Combines slow stochastic oscillator with MACD to create a more sensitive indicator that provides earlier signals.

class STCIndicator:
    def __init__(self, close, window_slow=50, window_fast=23, cycle=10, smooth1=3, smooth2=3, fillna=False):
        """
        Schaff Trend Cycle (STC).
        
        Parameters:
        - close (Series): Dataset 'Close' column
        - window_slow (int): Long-term period (default: 50)
        - window_fast (int): Short-term period (default: 23)
        - cycle (int): Cycle period (default: 10)
        - smooth1 (int): First smoothing period (default: 3)
        - smooth2 (int): Second smoothing period (default: 3)
        - fillna (bool): If True, fill NaN values (default: False)
        """
    
    def stc(self):
        """Returns: Series with STC values (0-100 scale)"""

def stc(close, window_slow=50, window_fast=23, cycle=10, smooth1=3, smooth2=3, fillna=False):
    """Functional interface for STC"""

Usage Examples

Trend Direction Analysis

from ta.trend import *
import pandas as pd

def analyze_trend_direction(df):
    # Moving averages for trend identification
    df['SMA_20'] = sma_indicator(df['Close'], window=20)
    df['SMA_50'] = sma_indicator(df['Close'], window=50)
    df['EMA_12'] = ema_indicator(df['Close'], window=12)
    df['EMA_26'] = ema_indicator(df['Close'], window=26)
    
    # MACD for trend momentum
    df['MACD_Line'] = macd(df['Close'])
    df['MACD_Signal'] = macd_signal(df['Close'])
    df['MACD_Hist'] = macd_diff(df['Close'])
    
    # ADX for trend strength
    df['ADX'] = adx(df['High'], df['Low'], df['Close'])
    df['DI_Plus'] = adx_pos(df['High'], df['Low'], df['Close'])
    df['DI_Minus'] = adx_neg(df['High'], df['Low'], df['Close'])
    
    return df

# Apply trend analysis
df_trend = analyze_trend_direction(df)

Multi-Timeframe Trend Analysis

from ta.trend import SMAIndicator, EMAIndicator, MACD, ADXIndicator

# Create trend indicators for different timeframes
def multi_timeframe_trend(df):
    # Short-term trend (fast settings)
    df['SMA_10'] = sma_indicator(df['Close'], window=10)
    df['EMA_8'] = ema_indicator(df['Close'], window=8)
    df['MACD_Fast'] = macd(df['Close'], window_slow=12, window_fast=6, window_sign=4)
    
    # Medium-term trend (standard settings)
    df['SMA_20'] = sma_indicator(df['Close'], window=20)
    df['EMA_21'] = ema_indicator(df['Close'], window=21)
    df['MACD_Standard'] = macd(df['Close'])
    
    # Long-term trend (slow settings)
    df['SMA_50'] = sma_indicator(df['Close'], window=50)
    df['SMA_200'] = sma_indicator(df['Close'], window=200)
    df['EMA_55'] = ema_indicator(df['Close'], window=55)
    
    return df

df_multi_tf = multi_timeframe_trend(df)

Trend Reversal Detection

from ta.trend import AroonIndicator, PSARIndicator, VortexIndicator

# Create indicators for reversal detection
aroon = AroonIndicator(high=df['High'], low=df['Low'], window=25)
psar = PSARIndicator(high=df['High'], low=df['Low'], close=df['Close'])
vortex = VortexIndicator(high=df['High'], low=df['Low'], close=df['Close'])

# Calculate reversal indicators
df['Aroon_Up'] = aroon.aroon_up()
df['Aroon_Down'] = aroon.aroon_down()
df['Aroon_Indicator'] = aroon.aroon_indicator()
df['PSAR'] = psar.psar()
df['PSAR_Up_Signal'] = psar.psar_up_indicator()
df['PSAR_Down_Signal'] = psar.psar_down_indicator()
df['Vortex_Pos'] = vortex.vortex_indicator_pos()
df['Vortex_Neg'] = vortex.vortex_indicator_neg()

# Generate reversal signals
df['Trend_Reversal_Up'] = (
    (df['Aroon_Up'] > df['Aroon_Down']) & 
    (df['Aroon_Up'] > 70) &
    df['PSAR_Up_Signal'] &
    (df['Vortex_Pos'] > df['Vortex_Neg'])
)

df['Trend_Reversal_Down'] = (
    (df['Aroon_Down'] > df['Aroon_Up']) & 
    (df['Aroon_Down'] > 70) &
    df['PSAR_Down_Signal'] &
    (df['Vortex_Neg'] > df['Vortex_Pos'])
)

Comprehensive Trend System

from ta.trend import *

def comprehensive_trend_system(df):
    """Complete trend analysis system combining multiple indicators"""
    
    # Trend direction indicators
    df['SMA_20'] = sma_indicator(df['Close'], window=20)
    df['EMA_20'] = ema_indicator(df['Close'], window=20) 
    df['WMA_20'] = wma(df['Close'], window=20)
    
    # Momentum and convergence
    df['MACD_Line'] = macd(df['Close'])
    df['MACD_Signal'] = macd_signal(df['Close'])
    df['MACD_Hist'] = macd_diff(df['Close'])
    
    # Trend strength and direction
    df['ADX'] = adx(df['High'], df['Low'], df['Close'])
    df['DI_Plus'] = adx_pos(df['High'], df['Low'], df['Close'])
    df['DI_Minus'] = adx_neg(df['High'], df['Low'], df['Close'])
    
    # Cycle and oscillator analysis  
    df['CCI'] = cci(df['High'], df['Low'], df['Close'])
    df['DPO'] = dpo(df['Close'])
    df['TRIX'] = trix(df['Close'])
    
    # Advanced trend analysis
    df['Mass_Index'] = mass_index(df['High'], df['Low'])
    df['KST'] = kst(df['Close'])
    df['KST_Signal'] = kst_sig(df['Close'])
    
    # Ichimoku cloud components
    df['Tenkan_Sen'] = ichimoku_conversion_line(df['High'], df['Low'])
    df['Kijun_Sen'] = ichimoku_base_line(df['High'], df['Low'])
    df['Senkou_A'] = ichimoku_a(df['High'], df['Low'])
    df['Senkou_B'] = ichimoku_b(df['High'], df['Low'])
    
    # Parabolic SAR for stop-loss levels
    df['PSAR'] = psar(df['High'], df['Low'], df['Close'])
    
    # Schaff Trend Cycle for early signals
    df['STC'] = stc(df['Close'])
    
    # Composite trend score
    trend_signals = []
    
    # Price vs moving averages
    trend_signals.append((df['Close'] > df['SMA_20']).astype(int))
    trend_signals.append((df['Close'] > df['EMA_20']).astype(int))
    
    # MACD signals
    trend_signals.append((df['MACD_Line'] > df['MACD_Signal']).astype(int))
    trend_signals.append((df['MACD_Hist'] > 0).astype(int))
    
    # ADX directional signals
    trend_signals.append(((df['DI_Plus'] > df['DI_Minus']) & (df['ADX'] > 25)).astype(int))
    
    # Ichimoku signals
    trend_signals.append((df['Tenkan_Sen'] > df['Kijun_Sen']).astype(int))
    trend_signals.append((df['Close'] > df['Senkou_A']).astype(int))
    
    # Calculate composite trend score
    df['Trend_Score'] = sum(trend_signals) / len(trend_signals) * 100
    
    # Trend classification
    df['Trend_Direction'] = pd.cut(
        df['Trend_Score'], 
        bins=[0, 30, 70, 100], 
        labels=['Bearish', 'Neutral', 'Bullish']
    )
    
    return df

# Apply comprehensive trend system
df_complete = comprehensive_trend_system(df)

Trend Breakout Detection

from ta.trend import AroonIndicator, CCIIndicator, VortexIndicator

def detect_trend_breakouts(df, lookback=20):
    """Detect potential trend breakouts using multiple indicators"""
    
    # Aroon for trend change detection
    aroon = AroonIndicator(df['High'], df['Low'], window=25)
    df['Aroon_Up'] = aroon.aroon_up()
    df['Aroon_Down'] = aroon.aroon_down()
    
    # CCI for cyclical breakouts
    df['CCI'] = cci(df['High'], df['Low'], df['Close'], window=20)
    
    # Vortex for directional breakouts
    vortex = VortexIndicator(df['High'], df['Low'], df['Close'])
    df['VI_Plus'] = vortex.vortex_indicator_pos()
    df['VI_Minus'] = vortex.vortex_indicator_neg()
    
    # Breakout conditions
    df['Bullish_Breakout'] = (
        (df['Aroon_Up'] > 70) & 
        (df['Aroon_Up'] > df['Aroon_Down']) &
        (df['CCI'] > 100) &
        (df['VI_Plus'] > df['VI_Minus']) &
        (df['VI_Plus'] > 1.1)  # Strong positive vortex
    )
    
    df['Bearish_Breakout'] = (
        (df['Aroon_Down'] > 70) & 
        (df['Aroon_Down'] > df['Aroon_Up']) &
        (df['CCI'] < -100) &
        (df['VI_Minus'] > df['VI_Plus']) &
        (df['VI_Minus'] > 1.1)  # Strong negative vortex
    )
    
    return df

df_breakouts = detect_trend_breakouts(df)

Install with Tessl CLI

npx tessl i tessl/pypi-ta

docs

index.md

momentum-indicators.md

others-indicators.md

trend-indicators.md

utilities.md

volatility-indicators.md

volume-indicators.md

wrapper-functions.md

tile.json