Trend
Trend indicators help identify the direction and strength of market trends. All examples use real market data fetched via OpenAlgo API.
Data Setup
from openalgo import api, ta
import pandas as pd
# Initialize API client
client = api(api_key='your_api_key_here', host='http://127.0.0.1:5000')
# Fetch historical data
df = client.history(symbol="SBIN",
exchange="NSE",
interval="5m",
start_date="2025-04-01",
end_date="2025-04-08")
print(df.head())
# close high low open volume
# timestamp
# 2025-04-01 09:15:00+05:30 772.50 774.00 763.20 766.50 318625
# 2025-04-01 09:20:00+05:30 773.20 774.95 772.10 772.45 197189Simple Moving Average (SMA)
Description: The most basic trend indicator, calculated by averaging closing prices over a specified period.
Parameters
data (array-like): Price data (typically closing prices)
period (int): Number of periods for the moving average
Returns
pandas.Series: SMA values with original index preserved
Usage Example
Exponential Moving Average (EMA)
Description: Gives more weight to recent prices, making it more responsive to new information than SMA.
Parameters
data (array-like): Price data (typically closing prices)
period (int): Number of periods for the moving average
Returns
pandas.Series: EMA values with original index preserved
Usage Example
Weighted Moving Average (WMA)
Description: Assigns greater weight to recent data points using a linear weighting scheme.
Parameters
data (array-like): Price data (typically closing prices)
period (int): Number of periods for the moving average
Returns
numpy.ndarray: WMA values
Usage Example
Hull Moving Average (HMA)
Description: Attempts to minimize lag while improving smoothing using weighted moving averages.
Parameters
data (array-like): Price data (typically closing prices)
period (int): Number of periods for the moving average
Returns
pandas.Series: HMA values with original index preserved
Usage Example
Volume Weighted Moving Average (VWMA)
Description: Gives more weight to periods with higher volume, making it more responsive to volume-driven price movements.
Parameters
data (array-like): Price data (typically closing prices)
volume (array-like): Volume data
period (int): Number of periods for the moving average
Returns
pandas.Series: VWMA values with original index preserved
Usage Example
Kaufman's Adaptive Moving Average (KAMA)
Description: Adjusts its smoothing based on market volatility, becoming more responsive in trending markets and smoother in sideways markets.
Parameters
data (array-like): Price data (typically closing prices)
length (int, default=14): Period for efficiency ratio calculation
fast_length (int, default=2): Fast EMA length
slow_length (int, default=30): Slow EMA length
Returns
pandas.Series: KAMA values with original index preserved
Usage Example
Supertrend
Description: A trend-following indicator that uses ATR to calculate dynamic support and resistance levels.
Parameters
high (array-like): High prices
low (array-like): Low prices
close (array-like): Closing prices
period (int, default=10): ATR period
multiplier (float, default=3.0): ATR multiplier
Returns
tuple: (supertrend_values, direction_values) as pandas.Series
direction: -1 for uptrend (green), 1 for downtrend (red)
Usage Example
Ichimoku Cloud
Description: A comprehensive indicator that defines support and resistance, identifies trend direction, and provides trading signals.
Parameters
high (array-like): High prices
low (array-like): Low prices
close (array-like): Closing prices
conversion_periods (int, default=9): Conversion Line Length
base_periods (int, default=26): Base Line Length
lagging_span2_periods (int, default=52): Leading Span B Length
displacement (int, default=26): Lagging Span displacement
Returns
tuple: (conversion_line, base_line, leading_span_a, leading_span_b, lagging_span) as pandas.Series
Usage Example
Arnaud Legoux Moving Average (ALMA)
Description: Combines the features of SMA and EMA with a configurable phase and smoothing factor.
Parameters
data (array-like): Price data (typically closing prices)
period (int, default=21): Number of periods for the moving average
offset (float, default=0.85): Phase offset (0 to 1)
sigma (float, default=6.0): Smoothing factor
Returns
pandas.Series: ALMA values with original index preserved
Usage Example
Zero Lag Exponential Moving Average (ZLEMA)
Description: Attempts to eliminate lag by using price momentum in its calculation.
Parameters
data (array-like): Price data (typically closing prices)
period (int): Number of periods for the moving average
Returns
pandas.Series: ZLEMA values with original index preserved
Usage Example
Multiple Exponential Moving Average (DEMA & TEMA)
Description: DEMA and TEMA reduce lag by applying exponential smoothing multiple times.
Parameters
data (array-like): Price data (typically closing prices)
period (int): Number of periods for the moving average
Returns
pandas.Series: DEMA/TEMA values with original index preserved
Usage Example
Complete Trading Analysis Example
This documentation demonstrates how to use OpenAlgo trend indicators with real market data fetched via the OpenAlgo API, maintaining pandas DataFrame structure throughout the analysis process.
Last updated
Was this helpful?