Python wrapper for TA-LIB providing 175+ technical analysis indicators for financial market data
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Measures of price volatility and range that help assess market conditions, potential breakout scenarios, and risk levels. These indicators quantify the magnitude of price movements regardless of direction.
Measures market volatility by calculating the average of true ranges over a specified period, providing insight into price movement magnitude.
def ATR(high, low, close, timeperiod=14):
"""
Average True Range
Parameters:
- high: array-like, high prices
- low: array-like, low prices
- close: array-like, close prices
- timeperiod: int, number of periods (default: 14)
Returns:
numpy.ndarray: ATR values (absolute price units)
"""ATR normalized as a percentage of the closing price, allowing comparison across different price levels and securities.
def NATR(high, low, close, timeperiod=14):
"""
Normalized Average True Range
Parameters:
- high: array-like, high prices
- low: array-like, low prices
- close: array-like, close prices
- timeperiod: int, number of periods (default: 14)
Returns:
numpy.ndarray: NATR values (percentage format)
"""Single-period true range calculation representing the greatest of three price differences for each period.
def TRANGE(high, low, close):
"""
True Range
Parameters:
- high: array-like, high prices
- low: array-like, low prices
- close: array-like, close prices
Returns:
numpy.ndarray: True Range values for each period
"""Volatility-based bands that use price acceleration to create dynamic support and resistance levels, expanding during volatile periods and contracting during quieter markets.
def ACCBANDS(high, low, close, timeperiod=20):
"""
Acceleration Bands
Volatility-based bands using price acceleration to create dynamic
support and resistance levels.
Parameters:
- high: array-like, high prices
- low: array-like, low prices
- close: array-like, close prices
- timeperiod: int, number of periods (default: 20)
Returns:
tuple: (upper_band, middle_band, lower_band) - Three arrays representing
the acceleration bands
"""import talib
import numpy as np
# Sample OHLC data
high = np.array([102.5, 103.2, 101.8, 104.1, 103.7])
low = np.array([100.1, 101.5, 99.8, 101.2, 102.1])
close = np.array([101.8, 102.9, 100.5, 103.4, 102.8])
# Calculate volatility indicators
atr = talib.ATR(high, low, close, timeperiod=14)
natr = talib.NATR(high, low, close, timeperiod=14)
trange = talib.TRANGE(high, low, close)
print("ATR:", atr[-1])
print("NATR:", natr[-1], "%")
print("Current True Range:", trange[-1])
# ATR can be used for:
# - Position sizing (risk per trade = account_risk / ATR)
# - Stop loss placement (stop = entry ± (ATR * multiplier))
# - Volatility breakout systems
# - Market regime identification (high ATR = volatile, low ATR = quiet)