Volume Indicators

OBV: On-Balance Volume for Trend

In this page: what OBV is, how it works, when to use it, a practical example with code, and a bonus tip.

๐Ÿ“– 9 min read

๐Ÿ“ 1,654 words

๐Ÿท๏ธ Volume Indicators

OBV on a price chart: illustration of the indicator and how it is used in technical analysis
OBV โ€“ chart illustration

OBV (On-Balance Volume) Indicator Explanation

The On-Balance Volume (OBV) is a cumulative volume indicator that measures buying and selling pressure by tracking volume flow relative to price movements. Developed by Joseph Granville in 1963 and introduced in his book "Granville's New Key to Stock Market Profits," OBV was one of the first volume-based indicators to combine price and volume analysis. The indicator accumulates volume on up days and subtracts volume on down days, creating a running total that reflects the cumulative flow of money into or out of an asset. OBV helps traders identify accumulation (smart money buying) and distribution (smart money selling) phases, providing insights into potential price movements before they occur.

How OBV Works: OBV is calculated by adding volume to a running total when the closing price is higher than the previous closing price, and subtracting volume from the total when the closing price is lower than the previous closing price. If the closing price remains unchanged, the OBV value stays the same. The formula is: If Close > Previous Close, then OBV = Previous OBV + Volume; If Close < Previous Close, then OBV = Previous OBV - Volume; If Close = Previous Close, then OBV = Previous OBV. This cumulative approach creates a line that trends upward during accumulation phases (when volume on up days exceeds volume on down days) and trends downward during distribution phases (when volume on down days exceeds volume on up days). The direction and slope of the OBV line relative to price action provide trading signals.

When to Use OBV:

  • Trend Confirmation: OBV is highly effective at confirming trend direction and strength. When OBV is rising along with price, it confirms an uptrend with strong buying pressure. Conversely, when OBV is falling along with price, it confirms a downtrend with strong selling pressure. OBV divergence (price making new highs while OBV makes lower highs) can signal weakening trends and potential reversals.
  • Accumulation and Distribution Identification: OBV helps identify accumulation phases (when smart money is buying) and distribution phases (when smart money is selling). Rising OBV during price consolidation suggests accumulation and potential upward breakout, while falling OBV during price consolidation suggests distribution and potential downward breakdown.
  • Breakout Confirmation: OBV can confirm the validity of price breakouts. When price breaks above resistance with OBV also breaking to new highs, it indicates strong buying interest and genuine breakout. Conversely, when price breaks below support with OBV also breaking to new lows, it indicates strong selling pressure and genuine breakdown.

Advantages:

  • Provides a cumulative measure of buying and selling pressure, helping traders identify smart money accumulation and distribution before price movements occur. The indicator's ability to detect money flow makes it valuable for anticipating price changes.
  • Works effectively across multiple timeframes and asset classes, including stocks, forex, commodities, and cryptocurrencies, as volume flow analysis is universal. The indicator is particularly useful for identifying trend strength and potential reversals.
  • Helps reduce false signals by confirming price movements with volume flow. OBV divergence often precedes significant price reversals, providing early warning signals for trend changes.

Limitations:

  • OBV can produce false signals during choppy or sideways markets when price oscillates without clear direction, as the cumulative nature of the indicator may not reflect short-term price volatility accurately. The indicator works best in trending markets.
  • The indicator may lag behind price movements during rapid market changes, as it relies on cumulative volume calculations. This lag can result in delayed signals, especially during strong trending markets with sudden reversals.
  • OBV values can vary significantly across different assets and timeframes, making it difficult to compare absolute OBV values. Traders should focus on OBV trends and divergences rather than absolute values.

In summary, OBV is a valuable volume indicator for traders seeking to identify accumulation and distribution phases, confirm trend strength, and anticipate potential price reversals through volume flow analysis. For comprehensive understanding, refer to Granville's original work "Granville's New Key to Stock Market Profits" (1963) (opens in a new tab), Investopedia's OBV guide (opens in a new tab), TradingView's OBV documentation (opens in a new tab), and academic research on volume-price relationships in financial markets published in journals such as the Journal of Finance and the Review of Financial Studies.

Practical Example: Using the OBV Indicator in a Trading Strategy

The On-Balance Volume (OBV) is a cumulative volume indicator used to measure buying and selling pressure by tracking volume flow relative to price movements. In a trading strategy, the OBV indicator helps traders identify accumulation and distribution phases, confirm trend strength, and anticipate potential price reversals through volume flow analysis.

Scenario: You're creating a trend-following strategy for Tesla stock (TSLA) on a daily chart. You want to buy when OBV is rising along with price (indicating accumulation and strong buying pressure), and sell when OBV diverges from price (indicating potential distribution and trend weakness).

Strategy Logic:

  • Calculate the OBV to measure cumulative buying and selling pressure. When OBV is rising, it indicates accumulation (buying pressure), and when OBV is falling, it indicates distribution (selling pressure).
  • Buy signal: When price is in an uptrend and OBV is also rising, confirming strong buying pressure and trend continuation. Additionally, when OBV makes a higher high while price consolidates, it suggests accumulation and potential upward breakout.
  • Sell signal: When OBV diverges from price (price makes new high but OBV makes lower high), indicating weakening buying pressure and potential bearish reversal. Also, when OBV breaks below a previous low while price is still high, it suggests distribution.

Backtrader Example:

python
import backtrader as bt

class OBVTrendStrategy(bt.Strategy):
    params = dict(
        obv_period=20  # Period for OBV smoothing (optional)
    )
    
    def __init__(self):
        self.obv = bt.ind.OBV(self.data)
        self.obv_ma = bt.ind.SMA(self.obv, period=self.p.obv_period)
        
    def next(self):
        if not self.position:
            # Buy when OBV is rising and price is above moving average
            if (self.obv[0] > self.obv[-1] and 
                self.data.close[0] > self.obv_ma[0] and
                self.obv[0] > self.obv[-5]):  # OBV trending up
                self.buy()
        else:
            # Sell when OBV diverges (price up but OBV down)
            if (self.data.close[0] > self.data.close[-5] and 
                self.obv[0] < self.obv[-5]):
                self.sell()

# Usage
cerebro = bt.Cerebro()
cerebro.addstrategy(OBVTrendStrategy)

Expected Outcome: By using the OBV indicator, your strategy identifies accumulation and distribution phases, helping you enter trades when smart money is buying and exit when selling pressure increases. This approach leads to better trend confirmation, improved reversal identification, and enhanced risk management by detecting volume flow changes before price reversals occur.

๐Ÿ’ก Bonus Tip

Consider using OBV divergence as a powerful reversal signal. When price makes a new high but OBV makes a lower high, it suggests that buying pressure is weakening despite higher prices, often preceding bearish reversals. This technique, documented in Granville's original methodology, can significantly improve the accuracy of OBV-based trading strategies by identifying trend exhaustion early.

Using the OBV indicator ensures your strategy trades with strong volume flow confirmation, improving entry and exit timing based on objective accumulation and distribution analysis.

OBV has no fixed zero

On-Balance Volume adds the bar's volume when price closes up and subtracts it when price closes down. It is a running total, and that single property decides how you may and may not use it.

A running total from where? From the first bar the script can see. Which means:

  • OBV has no natural zero and no upper or lower bound
  • its absolute level is an artefact of where your chart's history begins
  • the same symbol on the same timeframe can show wildly different OBV levels to two different people

The part that surprises people

How many historical bars a script can see is set by your TradingView account plan, not by the script (Pine limitations (opens in a new tab)) โ€” from 5,000 bars on lower plans up to 40,000 on the top tier.

So two users running an identical OBV strategy on an identical chart start their cumulative sum at different points in history and therefore see different OBV values. Any condition of the form "OBV above N" is not portable between accounts, and a threshold you tuned is a threshold tuned to your own plan.

This is the same reproducibility problem that makes a quoted backtest uncheckable without its plan, described in running and maintaining a strategy โ€” but with OBV it bites the logic, not just the reported numbers.

So use the shape, never the level

UsableNot usable
OBV rising while price is flat or falling (divergence)OBV above a fixed number
OBV above its own moving averageOBV crossing a hard-coded level
the slope of OBV over n barscomparing your OBV to someone else's

All three usable forms are relative, which makes them independent of where the sum started. That is the test to apply to any OBV condition you build: if the condition would change meaning when the history window changes, it is the wrong condition.

And a caveat about volume itself

OBV is only as meaningful as the volume series feeding it, and volume is not uniformly available or comparable:

  • on centralised markets (equities, futures) volume is traded size
  • on spot FX there is no central exchange, so the feed typically reports a tick count from one broker rather than volume traded

A tick count is a proxy for activity, not for size, and it differs between feeds. So an OBV strategy that works on an index future may be measuring something quite different on a currency pair โ€” which is a specific instance of the general rule that a strategy does not port between instruments: why copied scripts fail.

Building the confirmation version

FieldValue
Primary signalyour entry condition, e.g. a moving-average cross
ConfirmationOBV above its own moving average
Exitthe primary signal's exit, unchanged

Then run the count test: how many trades does the OBV gate remove? If the answer is none, the confirmation is decoration โ€” the reasoning is in the MACD double-count.