Volume
Volume indicators analyze trading volume to assess the strength of price movements and identify potential trend changes. These indicators help determine whether price movements are supported by volume activity.
Import Statement
from openalgo import ta, apiGetting Sample Data
# 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")
# Extract OHLCV data
high = df['high']
low = df['low']
close = df['close']
open_price = df['open']
volume = df['volume']On Balance Volume (OBV)
OBV is a momentum indicator that uses volume flow to predict changes in stock price by adding volume on up days and subtracting volume on down days.
Usage
Parameters
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
Returns
pandas.Series: OBV values with same index as input
Example
On Balance Volume with Smoothing (OBV Smoothed)
Enhanced OBV with various smoothing options including moving averages and Bollinger Bands support.
Usage
Parameters
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
ma_type (str, default="None"): Smoothing type - "None", "SMA", "SMA + Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"
ma_length (int, default=20): Moving average length
bb_length (int, default=20): Bollinger Bands length
bb_mult (float, default=2.0): Bollinger Bands multiplier
Returns
pandas.Series: Smoothed OBV values (for most ma_types)
tuple: (middle, upper, lower) for "SMA + Bollinger Bands"
Example
Volume Weighted Average Price (VWAP)
VWAP is the average price a security has traded at throughout the day, based on both volume and price, giving more weight to prices with higher volume.
Usage
Parameters
high (pandas.Series): High prices
low (pandas.Series): Low prices
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
source (str, default="hlc3"): Price source - "hlc3", "hl2", "ohlc4", "close"
anchor (str, default="Session"): Anchor period - "Session", "Week", "Month", etc.
Returns
pandas.Series: VWAP values
Example
Money Flow Index (MFI)
MFI is a momentum indicator that uses both price and volume to measure buying and selling pressure. Also known as Volume-Weighted RSI.
Usage
Parameters
high (pandas.Series): High prices
low (pandas.Series): Low prices
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
period (int, default=14): Number of periods for MFI calculation
Returns
pandas.Series: MFI values (range: 0 to 100)
Example
Accumulation/Distribution Line (ADL)
ADL is a volume-based indicator designed to measure the cumulative flow of money into and out of a security.
Usage
Parameters
high (pandas.Series): High prices
low (pandas.Series): Low prices
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
Returns
pandas.Series: ADL values
Example
Chaikin Money Flow (CMF)
CMF is the sum of Money Flow Volume over a period divided by the sum of volume over the same period.
Usage
Parameters
high (pandas.Series): High prices
low (pandas.Series): Low prices
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
period (int, default=20): Number of periods for CMF calculation
Returns
pandas.Series: CMF values
Example
Ease of Movement (EMV)
EMV relates price change to volume and is particularly useful for assessing the strength of a trend.
Usage
Parameters
high (pandas.Series): High prices
low (pandas.Series): Low prices
volume (pandas.Series): Volume data
length (int, default=14): Period for SMA smoothing
divisor (int, default=10000): Divisor for scaling EMV values
Returns
pandas.Series: EMV values
Example
Elder Force Index (FI)
Force Index combines price and volume to assess the power used to move the price of an asset.
Usage
Parameters
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
length (int, default=13): Period for EMA smoothing
Returns
pandas.Series: Elder Force Index values
Example
Negative Volume Index (NVI)
NVI focuses on days when volume decreases from the previous day, using cumulative rate of change.
Usage
Parameters
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
ema_length (int, default=255): EMA period for signal line
Returns
pandas.Series: NVI values
tuple: (nvi, nvi_ema) for nvi_with_ema method
Example
Positive Volume Index (PVI)
PVI focuses on days when volume increases from the previous day.
Usage
Parameters
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
initial_value (float, default=100.0): Initial PVI value
signal_type (str, default="EMA"): Signal smoothing type ("EMA" or "SMA")
signal_length (int, default=255): Signal line period
Returns
pandas.Series: PVI values
tuple: (pvi, signal) for pvi_with_signal method
Example
Volume Oscillator (VOLOSC)
Volume Oscillator shows the relationship between two exponential moving averages of volume.
Usage
Parameters
volume (pandas.Series): Volume data
short_length (int, default=5): Short EMA length
long_length (int, default=10): Long EMA length
check_volume_validity (bool, default=True): Check for valid volume data
Returns
pandas.Series: Volume Oscillator values
Example
Volume Rate of Change (VROC)
VROC measures the rate of change in volume over a specified period.
Usage
Parameters
volume (pandas.Series): Volume data
period (int, default=25): Number of periods to look back
Returns
pandas.Series: VROC values
Example
Klinger Volume Oscillator (KVO)
KVO is designed to predict price reversals by comparing volume to price movement.
Usage
Parameters
high (pandas.Series): High prices
low (pandas.Series): Low prices
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
trig_len (int, default=13): Trigger line EMA period
fast_x (int, default=34): Fast EMA period
slow_x (int, default=55): Slow EMA period
Returns
tuple: (kvo, trigger) pandas.Series
Example
Price Volume Trend (PVT)
PVT combines price and volume to show cumulative volume based on price changes.
Usage
Parameters
close (pandas.Series): Closing prices
volume (pandas.Series): Volume data
Returns
pandas.Series: PVT values
Example
Relative Volume (RVOL)
RVOL compares current volume to average volume over a specified period.
Usage
Parameters
volume (pandas.Series): Volume data
period (int, default=20): Period for average volume calculation
Returns
pandas.Series: RVOL values
Example
Complete Volume Analysis Example
Volume Analysis Interpretation
OBV: Rising OBV confirms uptrend, falling OBV confirms downtrend
VWAP: Price above VWAP suggests bullish momentum, below suggests bearish
MFI: Values above 80 indicate overbought, below 20 indicate oversold
ADL: Rising ADL confirms price uptrend with strong accumulation
CMF: Positive values indicate buying pressure, negative indicate selling
Volume Oscillator: Positive values show increasing volume momentum
Relative Volume: Values above 1.0 indicate higher than average volume
Last updated
Was this helpful?