What is on-balance volume (OBV)? Formula, meaning and a backtest
On this page
Key takeaways
- On-balance volume keeps a running score of trading volume: up days add their volume, down days subtract it, unchanged days leave it alone.
- The idea, from Joseph Granville, is that volume moves before price: a total that keeps rising while the price goes sideways is read as quiet buying.
- Only the direction of each day counts, not its size: a day that closes up by a cent adds as much volume as a day that closes up sharply.
- The running total has no natural level, so MarketHeist compares it with its own recent average; above that average is read as volume-confirmed strength.
- That comparison reads as intended only while the running total is above zero. When heavy selling has pushed the total below zero, the indicator's high and low readings swap meaning.
Definition
On-balance volume (OBV) is a running total of trading volume that adds a day's volume when the price closes up and subtracts it when the price closes down, introduced by Joseph Granville in 1963 to show whether volume is flowing into or out of a security. MarketHeist's OBV indicator divides that running total by its own moving average, so with a positive total the signal reads above 1 when the total has been rising faster than its recent average.
Also known as: OBV, OBV indicator, on balance volume, OBV momentum, OBV ratio, Granville OBV, volume divergence.
How it works
Start with a number and walk forward one day at a time. If the fund closed higher than the day before, add that day's volume; if it closed lower, subtract it; if the close was unchanged, carry the total forward. After a few months the total has climbed if most of the heavy trading happened on up days and fallen if it happened on down days. That is all OBV is: a signed tally of volume.
Granville's argument, set out in 1963, was that volume leads price. Large investors building a position buy over many days, and their buying shows up as volume on up days before the price breaks out; distribution shows up the other way. Chartists therefore look for divergences: a price making a new high while OBV does not, or a price going sideways while OBV climbs. Academic work has found that volume carries information, mostly about how large price moves are and how much traders disagree, rather than a dependable signal about direction.
The raw total is hard to use in a rule. Its level depends on the day the count started, and for a heavily traded fund it reaches billions of shares. MarketHeist's indicator divides the total by its simple moving average over the last 20 days, by default. When the total is positive, a ratio above 1 means it is above its recent average, which is the usual reading of volume-confirmed strength.
OBV is like a doorman counting people: everyone who comes in on a good day counts as an arrival and everyone on a bad day as a departure, without asking how much anyone bought.
The ratio has a trap. The running total can be negative, and for a fund that has seen heavier volume on its down days it can stay negative for years. When both the total and its average are below zero, dividing one by the other flips the reading: a total that is climbing back toward zero, above its average, gives a ratio below 1. Near a zero crossing the average is close to zero and the ratio can jump to very large values of either sign. A rule that reads the ratio inherits all of this.
Formula
- Vₜ
- shares traded on day t
- Cₜ
- the dividend-adjusted close of day t
- OBV₀
- the starting value: the volume of the first bar in the data
- mₜ
- the OBV ratio: OBV over its simple moving average, today included
- n
- the averaging period: 20 by default
- θ
- the threshold: 1 by default
- sₜ
- the position decided at the close of day t: 1 = hold, 0 = cash
- rₜ₊₁
- the fund's total return on the next day
With OBV and its average both positive, mₜ > 1 means OBV is above its average. With both negative, mₜ > 1 means OBV is below its average: the reading is reversed. The ratio is undefined while the average is not yet available or is exactly 0.
Worked example
SPY daily bars from Oct 2006 to Sep 2026, about 20 years. Rule: hold SPY for the next day while the OBV ratio (OBV over its 20-day average) closed above 1, otherwise cash; no trading costs. For comparison, the same kind of rule on price alone: hold SPY while it closed above its 20-day average.
The OBV ratio's median over the window was 1.00, it ranged from 0.97 at the 10th percentile to 1.06 at the 90th, and it closed above 1 on 58.2% of days. After the one-day delay the rule was invested 58.2% of the time and made 373 round trips, 18.7 a year, holding for 7.8 days on average.
It grew 4.1% a year, less than the 11.1% of holding SPY throughout. Its worst decline from a peak was -43.8% against -55.2%, and its volatility 11.5% against 19.4%. 35.1% of its trades closed at a gain, with an average gain of 2.6% and an average loss of -1.0%.
The price-only rule, which needs no volume at all, was invested 66.7% of the time and grew 4.8% a year with a worst decline of -37.1%. If volume added information beyond the price, the OBV row is where it would show; read the two rows side by side, and the 50-day version, which grew 3.1% a year, as a check on how much the averaging length moves the answer.
Short rules like these trade often. With 18.7 round trips a year, even a few basis points per trade add up; set a cost in the lab to see it. And before reading anything into the OBV rule, check the sign of SPY's running total over the window in the lab's indicator panel: where it sits below zero, the rule is long when volume has been running out of the fund, not into it.
Data through Sep 2026. Reproduce id 7b3d79354e97d31b (this guide, its lab setup and the data month).
Interactive lab
SPY's price with the days the rule held it shaded, the OBV ratio underneath with its threshold, and the results of the OBV rule, the price-only rule, the 50-day OBV rule and buy-and-hold over the same days. Change the averaging period, the threshold, the delay, the cost or the fund.
| Measure | Base | Price above its 20-day average | OBV ratio, 50-day average | Buy and hold |
|---|---|---|---|---|
| CAGR | 4.1% | 4.8% | 3.1% | 11.1% |
| Volatility (annualized) | 11.5% | 11.3% | 11.0% | 19.4% |
| Maximum drawdown | -43.8% | -37.1% | -49.0% | -55.2% |
| Sharpe ratio | 0.40 | 0.47 | 0.34 | 0.64 |
| Sortino ratio | 0.55 | 0.64 | 0.45 | n/a |
| Growth of $10,000 | $22,162 | $25,370 | $18,566 | $82,292 |
| Time in the market | 58.2% | 66.7% | 60.2% | 100.0% |
| Round trips | 373 | 285 | 246 | n/a |
| Round trips per year | 18.7 | 14.3 | 12.3 | n/a |
| Win rate | 35.1% | 35.1% | 28.9% | n/a |
| Average win | 2.6% | 3.5% | 3.7% | n/a |
| Average loss | -1.0% | -1.3% | -1.1% | n/a |
| Payoff ratio | 2.52 | 2.69 | 3.46 | n/a |
| Average days held | 7.8 | 11.7 | 12.3 | n/a |
| Expectancy per trade | 0.2% | 0.4% | 0.3% | n/a |
| Profit factor, per day | 1.11 | 1.11 | 1.08 | 1.13 |
| Profit factor, per trade | 1.37 | 1.46 | 1.41 | n/a |
| Indicator, last day | 0.99 | 0.998 | 0.986 | n/a |
| Indicator, 10th / 50th / 90th percentile | 0.969 / 1.004 / 1.055 | 0.973 / 1.008 / 1.029 | 0.954 / 1.007 / 1.104 | n/a |
| Days the rule alone is long | 58.2% | 66.6% | 60.2% | n/a |
S&P 500, Oct 2006 to Sep 2026, 5030 trading days. Every setup is measured over the same days, with the indicator warmed up on earlier ones; cash earns 0. Base: OBV Momentum (period 20); long while the OBV ratio is above 1; execution delay 1; cost 0 bps one way. Price above its 20-day average: MA Crossover (short window 1, long window 20, ma type SMA); long while the Short / long average ratio is above 1; execution delay 1; cost 0 bps one way. OBV ratio, 50-day average: OBV Momentum (period 50); long while the OBV ratio is above 1; execution delay 1; cost 0 bps one way.
| Buy and hold, same days | Value |
|---|---|
| Largest one-day gain | 14.5% on 13 Oct 2008 |
| Largest one-day loss | -10.9% on 16 Mar 2020 |
| CAGR without the 10 largest gains | 6.6% |
| CAGR without the 30 largest gains | 1.8% |
| CAGR without the 10 largest losses | 16.0% |
| CAGR without the 30 largest losses | 22.1% |
The days replaced by 0 are the largest daily gains (or losses) of the window.
How MarketHeist computes it
Every choice an implementation has to make, as the code makes it today. The page is checked against the code each time it is built.
| Choice | How it is computed | In the code |
|---|---|---|
| Data | Daily bars (open, high, low, close, volume) of the fund as the MarketHeist data service serves them to the backtester: prices adjusted for splits and dividends, so a dividend counts as reinvested. They come from a snapshot taken each month and cut at the data month of this page, and are not rounded. The fund's own history, not an extension: a fund younger than the window is measured over the years it has. | |
| Window | The worked example and the lab measure the last 20 years of trading days, Oct 2006 to Sep 2026 (5030 days), ending at the data month of this page. Every setup, and buy and hold, is measured over exactly these days; an indicator is warmed up on the days before them, so changing a setting never moves the window, and a setting that needs more history than exists before the window is refused rather than measured over fewer days. | |
| Backtest | The backtester's own engine, in the order it runs it: the indicator, the position rule (or entry and exit triggers) and the optional regime filter produce a position for every day of the fund's whole history; the position is then shifted forward by the execution delay and applied to each day's return over the window. Cash earns 0, there is no leverage, and a one-way cost in basis points is charged on the size of every change of position. Round trips are the closed entries of the trade log (a trade still open on the last day is not counted); the win rate is the share of them with a gain; the payoff ratio is the average win over the size of the average loss; expectancy is the average return per trade; the per-trade profit factor is the sum of the winning trades' returns over the size of the sum of the losing ones, while the per-day profit factor sums days. | |
| Years and volatility | A year is 252 trading days, the engine's convention: trades per year is round trips over days divided by 252, the CAGR is the growth multiple to the power 252 over the days, and volatility is the sample standard deviation of the daily returns times the square root of 252. | |
| Indicator statistics | The indicator's main output over the window: its last value, its 10th, 50th and 90th percentile (linear interpolation between ranks), and the share of days the rule alone says long, before the delay and any regime filter. Every output of the indicator is also summarized by its median and the share of days below 0. | |
| Buy and hold | The fund held every day of the window with dividends reinvested. The largest one-day gain and loss are the highest and lowest daily returns; the CAGR without the 10 or 30 largest gains (or losses) replaces those days' returns with 0 and recompounds. | |
| Running total | Starts at the first bar's volume; adds the bar's volume when the close is above the previous close, subtracts it when below, and carries the total unchanged on an equal close. The comparison uses the dividend-adjusted close, so an ex-dividend day is judged on its total return. | computepackages/shared/engine/indicators/obv.ts |
| Starting point | The total is accumulated from the first bar the backtester loads for the fund (its first day in the data), not from the start of the test window, so its level and its sign depend on the fund's whole trading history. | |
| Ratio (the signal) | OBV divided by its simple moving average over <code>period</code> bars, today included (default 20, from 5 to 300). No value while the average is not yet available or is exactly 0. This is the primary output the position rule reads. | SPECpackages/shared/engine/indicators/obv.ts |
| Sign of the ratio | No adjustment is made for a negative total. When OBV and its average are both below zero, a ratio above 1 means OBV is below its average; near a zero crossing the ratio can take very large values of either sign. | computepackages/shared/engine/indicators/obv.ts |
| Default rule | Long while the ratio is strictly above 1.0, otherwise flat. | generatePositionpackages/shared/engine/positions.ts |
| Volume data | Daily share volume as the data source reports it for the fund; volume is not adjusted for dividends. | yahooResultToRowspackages/platform/ohlcv.ts |
| Timing, costs and cash | The position decided at a bar's close is applied to the next bar's return (execution delay 1); no trading costs unless set; cash earns 0. | runBacktestpackages/shared/engine/backtest.ts |
| Engine functions | The functions the portfolio app and the MarketHeist MCP tools run, called here on the same monthly returns. | computePositionpackages/shared/engine/run_basic.tsgeneratePositionpackages/shared/engine/positions.tsapplyRegimeFilterpackages/shared/engine/regime_filter.tsgenerateTriggeredPositionpackages/shared/engine/triggered_position.tsrunBacktestpackages/shared/engine/backtest.tsgetIndicatorpackages/shared/engine/indicators/registry.ts |
On-balance volume (OBV) compared with its neighbours
| Measure | How volume is used | Direction from | Level meaningful on its own |
|---|---|---|---|
| On-balance volume | Added on up closes, subtracted on down closes, cumulated | Sign of the daily close change | No: depends on the start date |
| OBV ratio (MarketHeist) | OBV over its moving average | Same as OBV | Only while OBV is positive |
| Accumulation/distribution (Chaikin) | Weighted by where the close sits in the day's range | Close location within the range | No: cumulative |
| Volume ratio | Today's volume over its average | None | Yes: 1 is an average day |
| Rolling VWAP deviation | Volume weights in an average price | Close against that average | Yes: 0 is at the average |
Limitations
- The ratio's reading reverses when the running total is negative, and it becomes unstable near zero. Check the sign of the total before interpreting a result.
- Each day counts only by direction. A tiny gain on huge volume adds as much as a large gain on the same volume, so OBV can be moved by days that changed little.
- The running total depends on where the data begin. Two charts of the same fund that start on different dates show different OBV levels and can cross zero at different times.
- Fund volume includes trading for hedging, arbitrage and index rebalancing that carries no view on the fund, and heavy days around index events or option expiries can dominate the tally.
- The test ignores trading costs, spreads and taxes, earns nothing on cash and describes one historical path of one fund.
Frequently asked questions
- What does an OBV divergence mean?
- That price and volume disagree: the price makes a new high while OBV does not, or the price falls while OBV holds up. Chartists read it as a warning that the price move lacks support. It is a pattern to look for, not a tested signal, and the backtester's single-indicator rule does not test divergences directly.
- Why is OBV negative?
- Because more volume traded on down days than on up days over the history counted. For a fund with heavy selling days, such as stock funds in crashes, the total can fall below zero and stay there for long stretches even while the price rises.
- Does OBV work on an index?
- An index level has no volume, so OBV needs a traded instrument such as an index fund or futures contract. The worked example uses SPY, an S&P 500 fund, whose volume includes a great deal of trading that is not a view on the market.
- What is the difference between OBV and the volume ratio?
- OBV signs each day's volume by the day's direction and adds it up, so it carries direction. The volume ratio compares one day's volume with its recent average and carries no direction at all.
References
- Granville, J. E. (1963) Granville's New Key to Stock Market Profits. Prentice-Hall. Introduces on-balance volume.
- Karpoff, J. M. (1987) The Relation Between Price Changes and Trading Volume: A Survey. Journal of Financial and Quantitative Analysis 22(1).
- Blume, L., Easley, D. and O'Hara, M. (1994) Market Statistics and Technical Analysis: The Role of Volume. Journal of Finance 49(1). Why volume can carry information that prices alone do not.
- Gervais, S., Kaniel, R. and Mingelgrin, D. H. (2001) The High-Volume Return Premium. Journal of Finance 56(3). Stocks with unusually high volume tended to rise over the following month.
Try it on your own holdings
Run the OBV rule on SPY in the backtester →
Or ask an assistant connected to the MarketHeist MCP server (https://marketheist.io/mcp), which computes the same figures:
Using MarketHeist.io, backtest SPY on daily bars with the OBV indicator (20-day average): hold SPY while the OBV ratio is above 1, otherwise cash, one-bar delay, no costs, over the last 20 years. Compare it with holding SPY while its price is above its 20-day moving average, and with buy-and-hold.
Ask an AI assistant
The prompt opens in a new tab, already filled in. An assistant without the MarketHeist connector answers from its own knowledge, not from the figures on this page.
Historical simulation, not advice. Computed by the MarketHeist portfolio engine from monthly total returns, data through Sep 2026. Markdown version of this page: on-balance-volume.md.