Volume Indicators¶
Volume indicators analyze trading volume to identify buying and selling pressure.
OBV - On Balance Volume¶
OBV
¶
On Balance Volume (OBV)
OBV is a momentum indicator that uses volume flow to predict changes in stock price. Developed by Joe Granville in 1963, it measures buying and selling pressure as a cumulative indicator by adding volume on up days and subtracting volume on down days.
The theory is that volume precedes price movement. If a security is seeing an increasing OBV, it shows that buyers are willing to step in and push the price higher.
Parameters¶
close : array-like Close prices array volume : array-like Volume array
Returns¶
np.ndarray Array of OBV values (cumulative volume)
Notes¶
- Compatible with TA-Lib OBV signature
- Uses Numba JIT compilation for performance
- No lookback period (starts from first bar)
- Values are cumulative (running total)
- Absolute OBV value is not important
Formula¶
If Close[i] > Close[i-1]: OBV[i] = OBV[i-1] + Volume[i] If Close[i] < Close[i-1]: OBV[i] = OBV[i-1] - Volume[i] If Close[i] = Close[i-1]: OBV[i] = OBV[i-1]
Starting value: OBV[0] = 0
Interpretation: - Rising OBV: Buying pressure (bullish) - Falling OBV: Selling pressure (bearish) - OBV confirms price trend when moving same direction - Divergence signals potential reversal - Focus on direction, not absolute value
Advantages: - Simple and intuitive - Leading indicator (volume leads price) - Confirms price trends - Identifies divergences - Works across timeframes - No parameters to optimize
Common Uses: - Trend confirmation - Divergence detection - Breakout confirmation - Support/resistance levels - Accumulation/distribution - Volume analysis
Trading Signals: 1. Trend Confirmation: - Price up + OBV up = Strong uptrend - Price down + OBV down = Strong downtrend
- Divergence (Reversal Signal):
- Price makes new high but OBV doesn't = Bearish divergence
-
Price makes new low but OBV doesn't = Bullish divergence
-
Breakout Confirmation:
- OBV breaks resistance before price = Bullish
-
OBV breaks support before price = Bearish
-
Trendline Analysis:
- Draw trendlines on OBV
- OBV trendline break signals price reversal
Trading Applications: - Enter long when OBV breaks above resistance - Exit long when OBV shows divergence - Enter short when OBV breaks below support - Use OBV trendlines for entry/exit signals
Limitations: - Can give false signals in choppy markets - Large volume spikes can distort OBV - Doesn't account for volume quality - Works best with other indicators
Comparison with Related Indicators: - AD Line: Uses high-low range, not just close - Money Flow Index: Bounded version (0-100) - Volume: OBV is cumulative volume - Chaikin Money Flow: Weighted by price location
Examples¶
import numpy as np from numta import OBV close = np.array([100, 102, 101, 103, 105, 104, 106]) volume = np.array([1000, 1500, 1200, 1800, 2000, 1100, 1900]) obv = OBV(close, volume) print(obv) [0, 1500, 300, 2100, 4100, 3000, 4900]
Rising OBV indicates accumulation¶
See Also¶
AD : Accumulation/Distribution Line ADOSC : Chaikin A/D Oscillator MFI : Money Flow Index
Source code in src/numta/api/volume_indicators.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
AD - Chaikin A/D Line¶
AD
¶
AD(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], volume: Union[ndarray, list]) -> np.ndarray
Chaikin A/D Line (Accumulation/Distribution Line)
The Chaikin Accumulation/Distribution Line is a volume-based indicator designed to measure the cumulative flow of money into and out of a security. It relates the closing price to the high-low range and multiplies this by volume.
The indicator attempts to determine whether a security is being accumulated (bought) or distributed (sold) by comparing the close price position within the period's range, weighted by volume.
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array volume : array-like Volume array
Returns¶
np.ndarray Array of Chaikin A/D Line values
Notes¶
- Compatible with TA-Lib AD signature
- Uses Numba JIT compilation for maximum performance
- When high == low, the money flow multiplier is 0 (no change to AD line)
Formula¶
Money Flow Multiplier = ((Close - Low) - (High - Close)) / (High - Low) = (2 * Close - High - Low) / (High - Low) Money Flow Volume = Money Flow Multiplier * Volume AD Line[i] = AD Line[i-1] + Money Flow Volume[i]
The multiplier ranges from -1 to +1: - +1: Close = High (strong buying pressure) - 0: Close = Mid-point of range (neutral) - -1: Close = Low (strong selling pressure)
Examples¶
import numpy as np from numta import AD high = np.array([10, 11, 12, 11, 13]) low = np.array([9, 10, 10, 9, 11]) close = np.array([9.5, 10.5, 11, 10, 12]) volume = np.array([1000, 1100, 1200, 900, 1300]) ad = AD(high, low, close, volume) print(ad)
Source code in src/numta/api/volume_indicators.py
ADOSC - Chaikin A/D Oscillator¶
ADOSC
¶
ADOSC(high: Union[ndarray, list], low: Union[ndarray, list], close: Union[ndarray, list], volume: Union[ndarray, list], fastperiod: int = 3, slowperiod: int = 10) -> np.ndarray
Chaikin A/D Oscillator
The Chaikin A/D Oscillator is a momentum indicator that measures the accumulation-distribution line of a moving average convergence-divergence (MACD). It takes the difference between a 3-day and 10-day exponential moving average of the Accumulation/Distribution Line.
The oscillator is designed to anticipate directional changes in the A/D Line by measuring the momentum behind the movements. A positive value indicates that the security is being accumulated (buying pressure), while a negative value indicates distribution (selling pressure).
Parameters¶
high : array-like High prices array low : array-like Low prices array close : array-like Close prices array volume : array-like Volume array fastperiod : int, optional Number of periods for the fast EMA (default: 3) slowperiod : int, optional Number of periods for the slow EMA (default: 10)
Returns¶
np.ndarray Array of Chaikin A/D Oscillator values with NaN for the lookback period
Notes¶
- Compatible with TA-Lib ADOSC signature
- Uses Numba JIT compilation for maximum performance
- The first (slowperiod - 1) values will be NaN
- fastperiod should be less than slowperiod for meaningful results
Formula¶
AD Line = Cumulative sum of Money Flow Volume Fast EMA = EMA(AD Line, fastperiod) Slow EMA = EMA(AD Line, slowperiod) ADOSC = Fast EMA - Slow EMA
Interpretation: - Positive ADOSC: Accumulation (buying pressure) - Negative ADOSC: Distribution (selling pressure) - Rising ADOSC: Increasing buying pressure - Falling ADOSC: Increasing selling pressure
Examples¶
import numpy as np from numta import ADOSC high = np.array([10, 11, 12, 11, 13, 14, 15]) low = np.array([9, 10, 10, 9, 11, 12, 13]) close = np.array([9.5, 10.5, 11, 10, 12, 13, 14]) volume = np.array([1000, 1100, 1200, 900, 1300, 1400, 1500]) adosc = ADOSC(high, low, close, volume) print(adosc)
Source code in src/numta/api/volume_indicators.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |