1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
50 lines of Pine Script v6 from volume/on_balance_volume.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
on_balance_volume.pine
// Copyright (c) 2018-present, Alex Orekhov (everget)
//@version=6
// On Balance Volume script may be freely distributed under the MIT license.
const string INDICATOR_SHORT_TITLE = 'OBV'
indicator('On Balance Volume', shorttitle = INDICATOR_SHORT_TITLE, format = format.volume, timeframe = '')
showSignal = input.bool(true, title = 'Show Signal Line')
enum MovingAverageType
EMA = 'EMA'
SMA = 'SMA'
signalType = input.enum(MovingAverageType.SMA, title = 'Signal Smoothing Type')
signalLength = input.int(21, minval = 1, title = 'Signal Smoothing Length')
highlightCrossovers = input.bool(false, title = 'Highlight Crossovers')
applyFilling = input.bool(true, title = 'Apply OBV/Signal Ribbon Filling')
//---
obv = ta.obv
obvSignalEma = ta.ema(obv, signalLength)
obvSignalSma = ta.sma(obv, signalLength)
signal = signalType == MovingAverageType.EMA ? obvSignalEma : obvSignalSma
const color bullishColor = #0ebb23
const color bearishColor = color.red
trendColor = obv > signal ? bullishColor : bearishColor
obvColor = applyFilling ? trendColor : #0094ff
signalColor = applyFilling ? trendColor : #ff6a00
obvPlot = plot(obv, title = INDICATOR_SHORT_TITLE, linewidth = 2, color = obvColor)
signalPlot = plot(showSignal ? signal : na, title = 'Signal', color = signalColor)
const color bullishFillColor = color.new(bullishColor, 85)
const color bearishFillColor = color.new(bearishColor, 85)
fillColor = applyFilling ? (obv > signal ? bullishFillColor : bearishFillColor) : #ffffff00
fill(obvPlot, signalPlot, color = fillColor)
plotshape(ta.crossover(obv, signal) and highlightCrossovers ? obv : na, title = 'Crossover Mark', location = location.absolute, style = shape.circle, size = size.tiny, color = color.green)
plotshape(ta.crossunder(obv, signal) and highlightCrossovers ? obv : na, title = 'Crossunder Mark', location = location.absolute, style = shape.circle, size = size.tiny, color = color.red)
bullishColorChangeAlert = trendColor[1] != bullishColor and trendColor == bullishColor
bearishColorChangeAlert = trendColor[1] != bearishColor and trendColor == bearishColor
anyColorChangeAlert = trendColor != trendColor[1]
alertcondition(bullishColorChangeAlert, title = 'Bullish Color Change', message = INDICATOR_SHORT_TITLE + ' - Bullish Color Change\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}')
alertcondition(bearishColorChangeAlert, title = 'Bearish Color Change', message = INDICATOR_SHORT_TITLE + ' - Bearish Color Change\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}')
alertcondition(anyColorChangeAlert, title = 'Any Color Change', message = INDICATOR_SHORT_TITLE + ' - Any Color Change\nSymbol: {{exchange}}:{{ticker}}\nPrice: {{close}}')
Overview
On Balance Volume optionally overlays an EMA or SMA signal line and colors both lines by whether OBV is above or below that signal. Users can change the smoothing type and length, hide the signal, fill the space between the lines, and mark crossovers and crossunders. Alert conditions fire when the bullish or bearish color changes. It does not place trades or define exits.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Show Signal Line
bool
true
showSignal
Signal Smoothing Type
enum
MovingAverageType.SMA
signalType
Signal Smoothing Length
int
21
signalLength
Highlight Crossovers
bool
false
highlightCrossovers
Apply OBV/Signal Ribbon Filling
bool
true
applyFilling
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional
Range Volume Change compares volume inside a chosen session window with the same window on the previous day and plots that change as a percentage. It accumulates volume during the window and, when enabled, volume outside it, drawing growing columns in a separa
This indicator builds a footprint of estimated buy and sell volume across price rows and plots it in a separate pane. It fills rows from bar low to high, stores volume per row, and draws buy and sell volume boxes, volume-profile boxes, row labels, and cumulati
This indicator measures directional momentum by evaluating candlestick body proportions and volume over a user-defined lookback window. It computes the ratio of candle body to total range, weights the cumulative value by volume and absolute body size, and dete
This indicator builds an aggregate oscillator in a separate pane. It scales open, high, low, close, and volume into a 0 to 1 range, then averages scaled readings from MACD, a MACD histogram, RSI, stochastic, CCI, momentum, OBV, a directional index, volume-weig
This indicator calculates the Bill Williams Market Facilitation Index as the high-low range divided by volume, or zero when volume is zero. It compares the index and volume with the previous bar and assigns one of four zones: green for both rising, fade for bo