OBV (On-Balance Volume) Indicator
On-Balance Volume (OBV) is a cumulative indicator that relates volume to price change, designed to reveal whether volume is flowing into or out of a security ahead of the price itself moving.
What is the OBV Indicator?​
Developed by Joseph Granville in the early 1960s and introduced in Granville's New Key to Stock Market Profits, OBV runs on a simple premise: volume often leads price. As a stock's price rises on increasing volume, that's read as confirmation of the trend; if volume and price start disagreeing, it's a warning sign.
How OBV is built: on each candle, the full volume is added to a running total if the close is higher than the previous close, and subtracted if the close is lower.
How to Read OBV​
- OBV rising with price: the trend is confirmed by volume
- OBV falling while price rises: a warning sign; the rally may lack real buying support
- OBV rising sharply without a matching price move: often read as a sign that a breakout could be coming
- Divergence between OBV and price: a lack of confirmation, and a common early warning of reversal
Best Use Cases​
- Trend Confirmation: use OBV to check whether a price trend has genuine volume support.
- Breakout Anticipation: a rapidly rising OBV ahead of a price move can hint that a breakout is building.
- Divergence: spotting when OBV and price disagree is one of OBV's most useful applications.
OBV PineScript for TradingView​
Here's a ready-to-use OBV strategy template. Paste it into the Pine Editor, adjust the smoothing length, target, and stop loss to your preference, and backtest it.
To learn how to add this pinescript in TradingView, click here.
This strategy is for demonstration purposes only and is not intended for actual trading. AlgoTest is not responsible for any profit or loss arising from the use of this sample strategy.
//@version=5
strategy("OBV Strategy", overlay=true)
// Input parameters
length = input.int(14, title="Length")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")
// Initialize OBV variable
var float obv_value = na
// Calculate OBV
obv_value := nz(obv_value[1]) + (close - close[1]) * (volume > volume[1] ? 1 : volume < volume[1] ? -1 : 0)
// Strategy logic
long_condition = ta.crossover(obv_value, ta.sma(obv_value, length))
short_condition = ta.crossunder(obv_value, ta.sma(obv_value, length))
// Plot OBV
plot(obv_value, color=color.blue, title="OBV")
// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)
// Calculate target and stop loss levels
long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points
// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)
Once you've backtested it, you can connect the alert to AlgoTest to automate live execution without manually watching the chart.
FAQ​
How do I use the OBV indicator?​
Track the cumulative total volume, which adds when the price finishes higher and subtracts when the price finishes lower. Watch for OBV trend direction and divergence against price.
What is the best time frame for the OBV indicator?​
OBV can be effective on any time frame, but it is most useful on daily charts for identifying longer-term trends.
Is OBV good for day trading?​
While OBV can be used for day trading, its effectiveness might be limited compared to its use in identifying longer-term trends, since it's sensitive to sudden shifts in volume.
What is the trading strategy of OBV?​
A common OBV trading strategy is to buy when OBV starts rising while price is still stable or starting to rise, suggesting incoming buying pressure. Conversely, sell when OBV starts falling and price begins to follow or has already started to fall.
For more insights and detailed analysis tools, visit AlgoTest Signals.