Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-vwma

$ Pinescript VWMA (Volume Weighted MA)

Master this powerful moving average in TradingView's Pinescript that factors in volume for more reliable trend identification and conviction assessment.

500+ Clients Helped
100% Satisfaction
Live Trading Ready
⚠️
Trading financial markets carries risk. All content (PineScript code, indicators, strategies) on this website is for educational purposes only. Past performance is not indicative of future results. By using any code or information from this site, you agree that you are solely responsible for your trading decisions. The author disclaims all liability for any losses incurred. To gain from experts experiences, You can always try our Invite Only Scripts
01

What is the Volume Weighted Moving Average (VWMA)?

The Volume Weighted Moving Average (VWMA) is a technical indicator that gives more weight to prices associated with higher trading volume. Unlike Simple Moving Averages (SMAs) or Exponential Moving Averages (EMAs) which treat all price bars equally, the VWMA places a greater emphasis on prices where significant trading activity occurred. This means that price movements supported by higher volume will have a greater impact on the VWMA's value, reflecting stronger market conviction behind those moves.

In Pinescript, VWMA is an excellent tool for traders who want to confirm trend direction and identify key support/resistance levels based on where the "smart money" might be active.

02

Components and Calculation

The calculation of the VWMA is straightforward, yet powerful:

  1. Sum of (Price * Volume): For each bar in the specified `length`, multiply the `source` price (typically `close`) by the `volume` for that bar. Sum these values over the entire `length`.
  2. Sum of Volume: Sum the `volume` for all bars over the same `length`.
  3. VWMA Formula: `VWMA = Sum of (Price * Volume) / Sum of Volume`
03

Basic VWMA Implementation in Pinescript

pine-script@terminal
//@version=5
indicator("My VWMA Indicator", overlay=true)

// Input for VWMA length
length = input.int(20, title="VWMA Length", minval=1)

// Calculate VWMA using the built-in function
vwmaValue = ta.vwma(close, length)

// Plot the VWMA line
plot(vwmaValue, title="VWMA", color=color.blue, linewidth=2)
$ ✓ Compiled successfully
04

Volume Confirmation

Volume Confirmation

VWMA is unique in that it inherently includes volume in its calculation, making it a "self-confirming" moving average for trend validation.

05

Practical VWMA Strategies

06

1. VWMA as a Trend Confirmation Tool

pine-script@terminal
//@version=5
strategy("VWMA Trend Confirmation", overlay=true)

// Input for VWMA length
length = input.int(20, title="VWMA Length", minval=1)

// Calculate VWMA
vwmaValue = ta.vwma(close, length)

// Plot the VWMA line, coloring it based on its slope for visual trend confirmation
vwmaColor = vwmaValue > vwmaValue[1] ? color.green : color.red
plot(vwmaValue, title="VWMA", color=vwmaColor, linewidth=2)

// Example entry logic based on VWMA direction and price relation
longCondition = close > vwmaValue and vwmaValue > vwmaValue[1]
shortCondition = close < vwmaValue and vwmaValue < vwmaValue[1]

if (longCondition)
    strategy.entry("Long", strategy.long)

if (shortCondition)
    strategy.entry("Short", strategy.short)
$ ✓ Compiled successfully
07

2. Price Crossover with VWMA

pine-script@terminal
//@version=5
strategy("VWMA Price Crossover", overlay=true)

// Input for VWMA length
length = input.int(20, title="VWMA Length", minval=1)

// Calculate VWMA
vwmaValue = ta.vwma(close, length)

// Plot VWMA
plot(vwmaValue, title="VWMA", color=color.blue, linewidth=2)

// Crossover conditions
longCondition = ta.crossover(close, vwmaValue)
shortCondition = ta.crossunder(close, vwmaValue)

// Strategy entries/exits
if (longCondition)
    strategy.entry("Buy", strategy.long)

if (shortCondition)
    strategy.entry("Sell", strategy.short)

// Highlight crossovers
plotshape(longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
$ ✓ Compiled successfully
08

3. VWMA as Dynamic Support and Resistance

pine-script@terminal
//@version=5
indicator("VWMA Dynamic S/R", overlay=true)

length = input.int(20, title="VWMA Length", minval=1)
vwmaValue = ta.vwma(close, length)

plot(vwmaValue, title="VWMA", color=color.blue, linewidth=2)

// Highlight potential support/resistance bounces (conceptual - adjust thresholds)
// This example checks for price being very close to VWMA AND a directional change in price
isSupportBounce = (close > vwmaValue and close[1] <= vwmaValue[1]) and (close > open) // Price crossed above VWMA and current bar is bullish
isResistanceBounce = (close < vwmaValue and close[1] >= vwmaValue[1]) and (close < open) // Price crossed below VWMA and current bar is bearish

plotshape(isSupportBounce, title="Support Bounce", location=location.belowbar, color=color.lime, style=shape.circle, size=size.tiny)
plotshape(isResistanceBounce, title="Resistance Bounce", location=location.abovebar, color=color.fuchsia, style=shape.circle, size=size.tiny)
$ ✓ Compiled successfully
09

Optimizing VWMA Performance

To get the most from the Volume Weighted Moving Average in Pinescript:

  • Parameter Tuning: The `length` parameter influences how responsive the VWMA is. Shorter lengths (e.g., 9-20) are more responsive to short-term volume-weighted moves, while longer lengths (e.g., 50-200) provide a smoother, longer-term view. Experiment to find what fits your trading style and the asset.
  • Multi-Timeframe Analysis: Use VWMA on higher timeframes to determine the dominant trend (e.g., daily VWMA for long-term bias) and then look for signals on lower timeframes for entry/exit timing.
  • Combine with Other Indicators: While VWMA integrates volume, it's beneficial to combine it with other indicators. For instance, using oscillators like RSI or MACD to confirm overbought/oversold conditions or momentum, or incorporating chart patterns for confluence.
  • Context is Key: VWMA is particularly useful in identifying the "true" trend direction, as it filters out low-volume noise. Pay attention to how price interacts with VWMA after significant volume spikes.
10

Trusting Volume

Trusting Volume

VWMA emphasizes conviction. If price breaks a key level on high volume, and VWMA confirms it, the move is often more reliable.

11

Common VWMA Pitfalls

  • Less Effective in Low Volume Periods: In markets with consistently low or erratic volume, the "volume-weighted" aspect might not provide significant additional insight compared to a standard EMA.
  • Lag is Still Present: While it's more responsive to high-volume moves, VWMA is still a lagging indicator. It won't perfectly predict future price action.
  • Not for Ranging Markets: Like most trend-following indicators, VWMA can produce whipsaws in non-trending or highly choppy markets where volume is distributed erratically.
  • Requires Volume Data: Naturally, VWMA requires access to accurate volume data for its calculation, which might not be available for all assets or on all timeframes.
12

Conclusion

Conclusion

The Volume Weighted Moving Average (VWMA) is a valuable and intuitive indicator in Pinescript for TradingView, offering a unique perspective on market trends by factoring in the conviction of volume. Its ability to give greater significance to price movements backed by strong trading activity makes it an excellent tool for confirming trends, identifying dynamic support/resistance, and spotting reliable signals. By understanding its calculation, tuning its parameters, and integrating it thoughtfully into your comprehensive trading strategies, you can leverage the VWMA to gain deeper insights into market dynamics and enhance your trading decisions.

Enhance Your Trading

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