Master this powerful moving average in TradingView's Pinescript that factors in volume for more reliable trend identification and conviction assessment.
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.
The calculation of the VWMA is straightforward, yet powerful:
//@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)
VWMA is unique in that it inherently includes volume in its calculation, making it a "self-confirming" moving average for trend validation.
//@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)
//@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)
//@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)
To get the most from the Volume Weighted Moving Average in Pinescript:
VWMA emphasizes conviction. If price breaks a key level on high volume, and VWMA confirms it, the move is often more reliable.
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.
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