Volume indicator
OBV Calculator
Compute the next On Balance Volume value from the previous OBV, the two most recent closes, and the current volume. The idea behind it, using volume direction as a running tally, is what matters.
What OBV is
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 the current close is higher than the previous close, the full volume of the bar is added to the running total. If it is lower, the volume is subtracted. If the close is unchanged, the total stays the same. Because it is cumulative, OBV has no fixed range and no lookback period, and its starting value is arbitrary, so it is read by the direction and slope of the line rather than its absolute number.
Why 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.
What are TradingView and Pine Script?
TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.
People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.
The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.
Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.
Turn this into Pine Script
This tool computes one OBV step. 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.
Related free calculators
From the blog
PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.