Volume indicator
OBV Calculator
Paste your close and volume data to compute On Balance Volume, Joe Granville's running total that adds volume on up days and subtracts it on down days.
| Bar | Close | Volume | OBV |
|---|---|---|---|
| 25 | 111.00 | 1,850 | 12,570 |
| 26 | 110.40 | 1,550 | 11,020 |
| 27 | 111.70 | 1,750 | 12,770 |
| 28 | 112.50 | 1,900 | 14,670 |
| 29 | 111.90 | 1,600 | 13,070 |
| 30 | 113.20 | 2,050 | 15,120 |
The math behind OBV
On Balance Volume, introduced by Joe Granville in 1963, is a running total of volume that uses the direction of the close to decide whether each bar's volume is added or subtracted. The idea is that volume tends to move ahead of price, so a rising volume total can reflect accumulation and a falling one distribution.
The rule is simple. If today's close is higher than the previous close, the full volume of the bar is added to the running total. If today's close is lower, the volume is subtracted. If the close is unchanged, the total stays the same. The starting value is arbitrary, so OBV is read by its direction and slope rather than its absolute number.
Because it is cumulative, OBV has no fixed range and no lookback period. Its value on any bar depends on the entire history before it, which is why the line trends over long stretches rather than oscillating.
Where OBV is used
OBV is used to study the flow of volume relative to price. Analysts often compare the direction of OBV with the direction of price, watching for agreement that confirms a move or divergence where the two disagree. Because the absolute level is meaningless, the slope and trend of the line are what matter.
What any given pattern in OBV implies is a matter of your own interpretation. It is one lens on participation, not a signal by itself.
Turn this into Pine Script
This tool computes the OBV running total across the bars you pasted. On a chart it updates every bar and trends over the full history. Pine Script exposes it as the built-in variable ta.obv, but comparing it against price, adding a moving average of it, or building divergence logic is where the real indicator comes together.
//@version=6
indicator("OBV", overlay=false)
obvValue = ta.obv
plot(obvValue, "OBV", color=color.purple)PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v5 or v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.
This calculator is a developer and educational tool, not financial advice. Results are computed only from the values you enter and are provided for informational and educational purposes. See our full disclaimer.