Master volume-based trading with this advanced guide to Volume Oscillators in TradingView's Pinescript
The Volume Oscillator is a powerful technical indicator that measures the difference between two volume moving averages, helping traders identify volume trends and confirm price movements. Key applications include:
//@version=5
indicator("Volume Oscillator", shorttitle="VolOsc", overlay=false)
// User inputs
fastLength = input(10, "Fast MA Length")
slowLength = input(30, "Slow MA Length")
// Calculate moving averages of volume
fastMA = ta.sma(volume, fastLength)
slowMA = ta.sma(volume, slowLength)
// Calculate oscillator
oscillator = fastMA - slowMA
// Plot oscillator
plot(oscillator, "Volume Oscillator", color=color.blue, style=plot.style_columns)
The Volume Oscillator shows whether volume is expanding or contracting relative to recent history, helping confirm the strength behind price movements.
The Volume Oscillator provides several advantages over raw volume:
//@version=5
strategy("Volume-Price Confirmation Strategy", overlay=true)
// Volume Oscillator inputs
fastVol = input(10, "Fast Volume MA")
slowVol = input(30, "Slow Volume MA")
// Price MA inputs
priceLength = input(20, "Price MA Length")
// Calculate indicators
volOsc = ta.sma(volume, fastVol) - ta.sma(volume, slowVol)
priceMA = ta.sma(close, priceLength)
// Strategy logic
longCondition = close > priceMA and volOsc > 0
shortCondition = close < priceMA and volOsc < 0
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
//@version=5
indicator("Volume Divergence Detector", overlay=true)
// Volume Oscillator calculation
fastVol = input(14, "Fast Volume MA")
slowVol = input(28, "Slow Volume MA")
volOsc = ta.ema(volume, fastVol) - ta.ema(volume, slowVol)
// Price highs/lows
priceHigh = ta.highest(high, 14)
priceLow = ta.lowest(low, 14)
// Volume highs/lows
volHigh = ta.highest(volOsc, 14)
volLow = ta.lowest(volOsc, 14)
// Bearish divergence (price higher highs, volume lower highs)
bearishDiv = high > high[1] and volOsc < volOsc[1] and volOsc < 0
// Bullish divergence (price lower lows, volume higher lows)
bullishDiv = low < low[1] and volOsc > volOsc[1] and volOsc > 0
// Plot divergences
plotshape(bearishDiv, "Bearish Div", shape.triangledown, location.top, color.red)
plotshape(bullishDiv, "Bullish Div", shape.triangleup, location.bottom, color.green)
To get the most from Volume Oscillators in Pinescript:
//@version=5
indicator("Dynamic Volume Oscillator", overlay=false)
// Base inputs
fastLen = input(10, "Fast Length")
slowLen = input(30, "Slow Length")
lookback = input(50, "Threshold Lookback Period")
// Calculate oscillator
volOsc = ta.ema(volume, fastLen) - ta.ema(volume, slowLen)
// Dynamic thresholds based on recent volatility
upperBand = ta.percentile(volOsc, lookback, 75)
lowerBand = ta.percentile(volOsc, lookback, 25)
zeroLine = 0
// Plot
plot(volOsc, "Volume Oscillator", color.blue)
hline(upperBand, "Upper Band", color.red)
hline(lowerBand, "Lower Band", color.green)
hline(zeroLine, "Zero Line", color.gray)
The Volume Oscillator is a versatile Pinescript tool that provides unique insights into market dynamics. By combining volume trend analysis with price action, traders can develop more robust strategies with better confirmation signals. The key is to use the oscillator as part of a comprehensive trading system rather than in isolation.
Get a high-performance Pinescript analysis tool for actionable market insights, designed for traders on the move.
This strategy runs in live mode on TradingView, helping you identify potential opportunities.
Get Pinescript Strategy