Volume
OBV (On-Balance Volume) Trading Signals: TradingView Guide
Read OBV accumulation arithmetic, confirmed-pivot divergence and prior-window breakout rules. Inspect a Pine Script example and volume-data limits.
OBV Signal Interpretation
Quick-reference guide to 7 signal types you will see on the chart.
| Signal Type | Indicator Condition | Market Meaning | Interpretation limits |
|---|---|---|---|
| Regular bullish divergence | New confirmed price low is lower; smoothed OBV sampled there is higher than at the preceding low. | Price and sampled signed-volume total disagree. | Not proof of institutional buying. |
| Regular bearish divergence | New confirmed price high is higher; sampled smoothed OBV is lower. | A different shape in the two sampled series. | No validated prediction horizon. |
| Upward alignment | Close above EMA 50 and SMA-smoothed OBV rising from its prior value. | Price position and smoothed OBV slope agree. | Not a higher-high/higher-low structure test. |
| Downward alignment | Close below EMA 50 and SMA-smoothed OBV falling. | The two explicitly defined conditions agree. | Does not prescribe shorting or position size. |
| Joint prior-window breakout | Close above the highest high of the prior 20 bars; smoothed OBV above its own prior 20-bar maximum. | Both exceed separate historical reference levels. | Current bar is excluded from both reference windows. |
| Hidden bullish divergence | New price pivot low is higher; sampled smoothed OBV is lower. | A higher-price-low/lower-OBV comparison. | The code does not require a pre-existing uptrend. |
| Hidden bearish divergence | New price pivot high is lower; sampled smoothed OBV is higher. | A lower-price-high/higher-OBV comparison. | The code does not require a pre-existing downtrend. |
OBV Pine Script Signal Code
Educational indicator example. Review its exact rules and compare its plots with your intended calculation in TradingView. It does not place orders or establish profitability.
Pine Script v6
//@version=6
indicator("OBV Pivot and Breakout Conditions", overlay=false)
smoothLength = input.int(14, "OBV SMA Length", minval=1)
pivotBars = input.int(2, "Pivot Bars Each Side", minval=1, maxval=20)
breakoutLength = input.int(20, "Prior Breakout Window", minval=2)
showDivergence = input.bool(true, "Show Divergence Labels")
rawObv = ta.obv
obvSmooth = ta.sma(rawObv, smoothLength)
usable = not na(volume) and volume >= 0 and not na(obvSmooth)
priceLow = ta.pivotlow(low, pivotBars, pivotBars)
priceHigh = ta.pivothigh(high, pivotBars, pivotBars)
newLow = not na(priceLow)
newHigh = not na(priceHigh)
priorLow = ta.valuewhen(newLow, priceLow, 1)
priorLowObv = ta.valuewhen(newLow, obvSmooth[pivotBars], 1)
priorHigh = ta.valuewhen(newHigh, priceHigh, 1)
priorHighObv = ta.valuewhen(newHigh, obvSmooth[pivotBars], 1)
lowPair = barstate.isconfirmed and usable and newLow and not na(priorLowObv)
highPair = barstate.isconfirmed and usable and newHigh and not na(priorHighObv)
bullDiv = lowPair and priceLow < priorLow and obvSmooth[pivotBars] > priorLowObv
bearDiv = highPair and priceHigh > priorHigh and obvSmooth[pivotBars] < priorHighObv
hiddenBull = lowPair and priceLow > priorLow and obvSmooth[pivotBars] < priorLowObv
hiddenBear = highPair and priceHigh < priorHigh and obvSmooth[pivotBars] > priorHighObv
ema50 = ta.ema(close, 50)
upAlignment = barstate.isconfirmed and usable and close > ema50 and obvSmooth > obvSmooth[1]
downAlignment = barstate.isconfirmed and usable and close < ema50 and obvSmooth < obvSmooth[1]
priorPriceHigh = ta.highest(high, breakoutLength)[1]
priorObvHigh = ta.highest(obvSmooth, breakoutLength)[1]
jointBreakout = barstate.isconfirmed and usable and close > priorPriceHigh and obvSmooth > priorObvHigh
plot(rawObv, "Raw OBV", color=color.gray)
plot(obvSmooth, "Smoothed OBV", color=color.blue, linewidth=2)
// Draw on confirmation bars, with no negative offset.
plotshape(showDivergence and bullDiv, "Regular bullish", shape.labelup, location.bottom, color=color.green, text="RB", size=size.tiny)
plotshape(showDivergence and bearDiv, "Regular bearish", shape.labeldown, location.top, color=color.red, text="RB", size=size.tiny)
plotshape(showDivergence and hiddenBull, "Hidden bullish", shape.labelup, location.bottom, color=color.teal, text="HB", size=size.tiny)
plotshape(showDivergence and hiddenBear, "Hidden bearish", shape.labeldown, location.top, color=color.orange, text="HB", size=size.tiny)
plotshape(jointBreakout, "Joint breakout", shape.diamond, location.bottom, color=color.purple, size=size.tiny)
bgcolor(upAlignment ? color.new(color.green, 90) : downAlignment ? color.new(color.red, 90) : na)
alertcondition(bullDiv, "OBV regular bullish divergence", "Confirmed price low and sampled OBV form regular bullish divergence")
alertcondition(bearDiv, "OBV regular bearish divergence", "Confirmed price high and sampled OBV form regular bearish divergence")
alertcondition(hiddenBull, "OBV hidden bullish divergence", "Confirmed price low and sampled OBV form hidden bullish divergence")
alertcondition(hiddenBear, "OBV hidden bearish divergence", "Confirmed price high and sampled OBV form hidden bearish divergence")
alertcondition(jointBreakout, "OBV joint breakout", "Close and smoothed OBV exceed their separate prior-window highs")Example settings for OBV
Record the inputs used by the example. These settings are not an optimized trading recommendation.
| Parameter | Default | Description |
|---|---|---|
| OBV SMA Length | 14 | Smoothing applied to the cumulative OBV. Divergence and breakout use this smoothed series; the raw series is also plotted. |
| Pivot Bars Each Side | 2 | Price pivots require this many bars to the left and right. A larger right-side length delays confirmation. |
| Prior Breakout Window | 20 | Reference maxima exclude the current bar. Price uses highs; the oscillator uses smoothed OBV values. |
| Show Divergence Labels | true | Controls divergence labels only. Alert calculations remain active when labels are hidden. |
Turn the condition into an explicit rule
Specify the calculation, confirmation time, entry and exit rules before asking Pineify to draft or revise Pine Script. Review the code and simulate realistic costs before evaluating a strategy.
Explore Pine Script codingRelated Resources
Official calculation and usage references
FAQ
OBV Signals FAQ
What volume does OBV add or subtract?
When close rises, OBV adds the entire reported bar volume; when close falls, it subtracts it; an unchanged close adds zero. This is a classification convention. It cannot distinguish aggressive buyers, passive sellers, institutional ownership or money entering long versus short positions.
Can a Pine input switch tick volume into real volume?
No. This example uses the chart feed volume series. An input cannot create a different volume dataset. Check the exchange and data provider: crypto feeds may report traded volume, while some other instruments use tick volume or have no usable volume. Do not assume volume type from the asset label alone.
Why are percentage thresholds on OBV problematic?
The cumulative starting level depends on loaded history and may be negative or near zero. Dividing changes by that arbitrary level can produce unstable comparisons. The example uses ordering of values and prior maxima; it does not apply a percentage divergence threshold.
How is pivot divergence confirmed?
The script waits for two right-side bars by default, then samples smoothed OBV at the price pivot. It compares that pair with the previous confirmed pivot of the same type. Markers appear on the confirmation bar. These are aligned price-pivot samples, not independently located OBV swing points.
What does the breakout condition require?
As a hypothetical example, if the prior 20-bar price high is 105 and the smoothed OBV maximum is 1,000, a close of 106 with smoothed OBV 1,020 satisfies both tests. A close of 104 fails even if OBV exceeds 1,000. The current bar is excluded from both maxima, and continued new highs can satisfy the rule on consecutive bars.
Does divergence prove a reversal or accumulation?
No. It describes a mismatch under a specified pivot and smoothing rule. Regular and hidden patterns are often discussed as reversal or continuation candidates, but this page supplies no tested success rates or timing forecasts. Price can continue against either pattern.
How should alerts and data gaps be handled?
Create a named TradingView alert with Once Per Bar Close and recreate it after changing the script or inputs. The example gates events at bar close and requires current usable volume, but it does not repair missing historical volume. Review gaps and chart history before comparing cumulative values. It places no orders and reports no backtest.