Pine Script Volume: Using Volume Data in TradingView
Some traders swear by volume. Others ignore it completely. I've been on both sides, and here's what I've learned — volume is the closest thing we have to X-ray vision into market psychology. It shows you not just where price went, but how many people cared enough to act.
Volume is the total number of shares, contracts, or units traded during a specific time period. Think of it as the market's heartbeat. When volume spikes, something important is happening. When it dries up, participants are either bored or uncertain.
I still remember watching AAPL in January 2024. Volume hit 120 million shares on that earnings gap — nearly 3x its 20-day average. That kind of conviction told me the move was real before price ever confirmed it.
Getting Started with Volume in Pine Script
Pine Script gives you a built-in variable called volume that automatically pulls trading activity for each bar. No complex functions, no extra data feeds. It's just there.
Want to see volume as histogram bars at the bottom of your chart?
//@version=5
indicator("Basic Volume Chart", shorttitle="Vol")
plot(volume, title="Volume", style=plot.style_histogram, color=color.blue)
That's it. The data comes straight from TradingView's feed — the same numbers institutional traders see.
You can customize this easily. Want different colors for rising and falling volume?
//@version=5
indicator("Colored Volume", shorttitle="CVol")
vol_color = volume > volume[1] ? color.green : color.red
plot(volume, title="Volume", style=plot.style_histogram, color=vol_color)
Green bars when volume picks up, red when it drops off. You'll spot trends at a glance.
The Volume Profile Limitation (And Why It Matters)
Here's something that still frustrates me about Pine Script. Professional volume profile charts show exactly how much traded at each price level — revealing where institutions accumulated or where retail got trapped. Pine Script doesn't give you tick-by-tick, price-level volume data directly.
I haven't found a perfect workaround. Community developers approximate volume profiles using price-range bucketing, but it's not the same. For serious volume profile work, I prefer dedicated third-party tools.
Advanced Volume Analysis Techniques
The real value comes from combining volume with price action. Here's what I actually use:
Volume-Price Confirmation
When volume and price move together, the signal is stronger. Rising prices with climbing volume suggest real buying pressure. Heavy volume on the way down? That's serious selling.
//@version=5
indicator("Volume-Price Analysis", shorttitle="VPA")
price_up = close > close[1]
vol_up = volume > ta.sma(volume, 20)
bullish_signal = price_up and vol_up
bearish_signal = not price_up and vol_up
plotshape(bullish_signal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(bearish_signal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
Volume Moving Averages
A moving average filters out noise so you can spot when volume is genuinely significant.
Formula: volume > ta.sma(volume, N) where N depends on your timeframe.
I prefer a 20-period SMA on daily charts. For 15-minute charts, 50 periods works better.
| Timeframe | MA Period | Spike Threshold |
|---|---|---|
| 1m-15m | 50 | 2.0x average |
| 1H-4H | 20 | 1.5x average |
| Daily | 20 | 1.5x average |
| Weekly | 10 | 1.3x average |
//@version=5
indicator("Volume with MA", shorttitle="Vol+MA")
vol_ma = ta.sma(volume, 20)
above_average = volume > vol_ma
vol_color = above_average ? color.yellow : color.gray
plot(volume, title="Volume", style=plot.style_histogram, color=vol_color)
plot(vol_ma, title="Volume MA", color=color.white, linewidth=2)
Yellow bars mean volume is above average — worth a closer look.
Real-World Volume Trading Strategies
Theory is one thing. Here's what I've actually traded and what I've seen blow up accounts.
Breakout Confirmation
A price breakout on light volume is often a trap. Heavy volume breakouts tend to follow through. I learned this the hard way trading SPY in late 2023 — false breakouts on low volume cost me before I added a volume filter. Check out our guide on crafting breakout strategies for more setups.
Divergence Detection
When price makes new highs but volume shrinks, momentum is fading. I flagged this on NVDA in June 2024 when it hit $135 on declining volume — the pullback to $118 came within two weeks.
Volume Spikes
Unusual volume spikes often precede big moves. The trick is catching them before the crowd does.
Combining Volume with Other Indicators
Volume rarely works alone. I've had better luck combining it with other tools. For example, MACD crossovers become more reliable when volume confirms the signal. Our Pine Script tutorial covers how to layer these together.
Don't get me wrong — I've blown up more than one backtest by trusting a volume-only signal. Always pair volume with price structure or momentum indicators.
Common Volume Analysis Mistakes
After a few years working with volume data, I keep seeing the same errors:
Overcomplicating things. Don't analyze every bar. Focus on significant spikes and sustained patterns.
Ignoring market context. Volume patterns in a trending market behave differently than in a sideways one. TSLA's daily volume averaged 120 million shares during its 2020 rally. By mid-2024, it averaged under 60 million. The same spike threshold would fire constantly in one regime and rarely in the other.
Forgetting timeframes. Volume on a 5-minute chart tells a different story than daily volume. Adjust your baseline accordingly.
Building Your First Volume Indicator
Let's put it all together into something practical:
//@version=5
indicator("Smart Volume Analyzer", shorttitle="SVA")
// Calculate volume moving average
vol_ma = ta.sma(volume, 20)
// Identify volume spikes
vol_spike = volume > vol_ma * 1.5
// Determine price direction
price_direction = close > open ? 1 : -1
// Color coding
vol_color = vol_spike ? (price_direction > 0 ? color.lime : color.red) : color.gray
// Plot volume
plot(volume, title="Volume", style=plot.style_histogram, color=vol_color)
plot(vol_ma, title="Volume MA", color=color.white, linewidth=2)
// Alert on significant volume
alertcondition(vol_spike, title="Volume Spike", message="Significant volume detected")
Lime bars mean a bullish spike. Red means a bearish one. Gray is business as usual.
Advanced Pine Script Volume Techniques
Pine Script offers more advanced functions worth knowing:
ta.vwma()for volume-weighted moving averages — it weighs price data by volume, so high-activity bars count moreta.pvt()for price-volume trend — tracks cumulative money flow- Custom arrays for tracking volume distribution across price buckets
The Pine Script quick-start guide covers these functions in more depth.
▶What is the built-in volume variable in Pine Script?
It's just volume — a built-in variable that Pine Script fills automatically. Every bar has one, no configuration needed. I reference it directly without any data feed setup.
▶How do I plot a volume histogram in Pine Script?
Use plot(volume, style=plot.style_histogram) and you've got your histogram. Add a color argument to highlight direction or relative size. Pair it with ta.sma(volume, 20) and you'll see above-average bars instantly.
▶How do I detect a volume spike in Pine Script?
Set a baseline: vol_ma = ta.sma(volume, 20). Then check volume > vol_ma * 1.5 for spikes 50% above average. Throw in alertcondition() and you'll get a TradingView alert the moment it fires.
▶Can Pine Script access price-level (volume profile) data?
No, and I wish it did. Pine Script only gives you bar-level aggregate volume through the volume variable. Tick-by-tick, price-level volume profile data isn't accessible. Community workarounds using price-range bucketing exist, but they're approximations — dedicated volume profile tools are more precise.
▶What is ta.vwma() and when should I use it?
ta.vwma(source, length) computes a Volume-Weighted Moving Average. It gives more weight to bars with higher trading activity. I use it instead of a simple moving average when I want trends to reflect conviction, not just time.
▶How does volume confirm a breakout signal?
A breakout with volume well above the 20-period average is a confirmed move — it suggests institutions are participating. A breakout on low volume is usually a fakeout. My rule: require close > resistance AND volume > vol_ma * 1.5 before I enter.
▶What is volume divergence and how do I code it?
Volume divergence happens when price hits a new high or low but volume shrinks — momentum is dying. In code: check ta.highest(close, 20) == close (new high) while volume < volume[1] to flag bearish divergence. Reverse the logic for bullish.

