Master this advanced momentum indicator in TradingView's Pinescript that integrates volume into its core calculation, providing more robust trend and momentum signals for enhanced trading strategies.
Volume-Weighted Moving Average Convergence Divergence (VW-MACD) is an advanced variation of the traditional MACD indicator. While the standard MACD uses Exponential Moving Averages (EMAs) of price, the VW-MACD replaces these with Volume-Weighted Moving Averages (VWMAs). By incorporating volume into the calculation of its underlying moving averages, VW-MACD aims to provide more reliable and conviction-based signals.
The core philosophy behind VW-MACD is that significant price movements should be accompanied by significant volume. If volume is low, a price move might lack conviction. By weighting price averages by volume, VW-MACD prioritizes price action that occurs on higher trading activity, theoretically filtering out "noise" that happens on lower volume.
VW-MACD is primarily used to:
The calculation of Volume-Weighted MACD closely mirrors that of the standard MACD, but with a critical difference: the use of Volume-Weighted Moving Averages (VWMAs) instead of Exponential Moving Averages (EMAs) for the main MACD line components.
//@version=5
indicator("My Volume-Weighted MACD", overlay=false) // overlay=false to plot in a separate pane
// Inputs for VW-MACD lengths
fastLength = input.int(12, title="Fast Length", minval=1)
slowLength = input.int(26, title="Slow Length", minval=1)
signalLength = input.int(9, title="Signal Length", minval=1)
// Calculate Volume-Weighted Fast and Slow Moving Averages
vwmaFast = ta.vwma(close, fastLength)
vwmaSlow = ta.vwma(close, slowLength)
// Calculate VW-MACD Line
vwMacdLine = vwmaFast - vwmaSlow
// Calculate VW-MACD Signal Line (EMA of VW-MACD Line)
vwSignalLine = ta.ema(vwMacdLine, signalLength)
// Calculate VW-MACD Histogram
vwHistogram = vwMacdLine - vwSignalLine
// Plotting the VW-MACD components
plot(vwMacdLine, title="VW-MACD Line", color=color.blue, linewidth=2)
plot(vwSignalLine, title="VW-MACD Signal", color=color.orange, linewidth=1)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)
// Plotting the Histogram with color logic
// Colors for histogram: green for rising, red for falling
histColor = vwHistogram >= 0 ? (vwHistogram > vwHistogram[1] ? color.new(color.teal, 20) : color.new(color.blue, 20)) : (vwHistogram < vwHistogram[1] ? color.new(color.red, 20) : color.new(color.maroon, 20))
plot(vwHistogram, title="VW-MACD Histogram", style=plot.style_columns, color=histColor)
VW-MACD implicitly filters out weak price moves that aren't supported by significant volume, making its signals potentially more reliable than standard MACD.
//@version=5
strategy("VW-MACD Crossover Strategy", overlay=true)
fastLength = input.int(12, title="Fast Length", minval=1)
slowLength = input.int(26, title="Slow Length", minval=1)
signalLength = input.int(9, title="Signal Length", minval=1)
vwmaFast = ta.vwma(close, fastLength)
vwmaSlow = ta.vwma(close, slowLength)
vwMacdLine = vwmaFast - vwmaSlow
vwSignalLine = ta.ema(vwMacdLine, signalLength)
vwHistogram = vwMacdLine - vwSignalLine
// Plot for visualization (display=display.pane_only plots in a separate sub-window)
plot(vwMacdLine, "VW-MACD Line", color.blue, display=display.pane_only)
plot(vwSignalLine, "VW-MACD Signal", color.orange, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)
histColor = vwHistogram >= 0 ? (vwHistogram > vwHistogram[1] ? color.new(color.teal, 20) : color.new(color.blue, 20)) : (vwHistogram < vwHistogram[1] ? color.new(color.red, 20) : color.new(color.maroon, 20))
plot(vwHistogram, "VW-MACD Histogram", style=plot.style_columns, color=histColor, display=display.pane_only)
// Long entry: VW-MACD Line crosses above Signal Line
longCondition = ta.crossover(vwMacdLine, vwSignalLine)
// Short entry: VW-MACD Line crosses below Signal Line
shortCondition = ta.crossunder(vwMacdLine, vwSignalLine)
if (longCondition)
strategy.entry("Long VW-MACD", strategy.long)
if (shortCondition)
strategy.entry("Short VW-MACD", strategy.short)
// Basic exit: opposite signal
strategy.close("Long VW-MACD", when=shortCondition)
strategy.close("Short VW-MACD", when=longCondition)
//@version=5
strategy("VW-MACD Divergence Strategy", overlay=true)
fastLength = input.int(12, title="Fast Length", minval=1)
slowLength = input.int(26, title="Slow Length", minval=1)
signalLength = input.int(9, title="Signal Length", minval=1)
vwmaFast = ta.vwma(close, fastLength)
vwmaSlow = ta.vwma(close, slowLength)
vwMacdLine = vwmaFast - vwmaSlow
vwSignalLine = ta.ema(vwMacdLine, signalLength)
vwHistogram = vwMacdLine - vwSignalLine
// Plot for visualization
plot(vwMacdLine, "VW-MACD Line", color.blue, display=display.pane_only)
plot(vwSignalLine, "VW-MACD Signal", color.orange, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)
histColor = vwHistogram >= 0
? (vwHistogram > vwHistogram[1]
? color.new(color.teal, 20)
: color.new(color.blue, 20))
: (vwHistogram < vwHistogram[1]
? color.new(color.red, 20)
: color.new(color.maroon, 20))
plot(vwHistogram, "VW-MACD Histogram", style=plot.style_columns, color=histColor, display=display.pane_only)
// Simple divergence detection (conceptual)
// Bullish Divergence: Price lower low, VW-MACD higher low
bullishDiv = close < close[1] and close[1] < close[2]
and vwMacdLine > vwMacdLine[1] and vwMacdLine[1] > vwMacdLine[2]
// Bearish Divergence: Price higher high, VW-MACD lower high
bearishDiv = close > close[1] and close[1] > close[2]
and vwMacdLine < vwMacdLine[1] and vwMacdLine[1] < vwMacdLine[2]
plotshape(bullishDiv, title="Bullish VW-MACD Divergence", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(bearishDiv, title="Bearish VW-MACD Divergence", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
if (bullishDiv)
strategy.entry("Long Divergence", strategy.long)
if (bearishDiv)
strategy.entry("Short Divergence", strategy.short)
// Basic exit after a few bars or on opposite signal
strategy.exit("Long Divergence Exit", from_entry="Long Divergence", profit=close*0.02, loss=close*0.01)
strategy.exit("Short Divergence Exit", from_entry="Short Divergence", profit=close*0.02, loss=close*0.01)
//@version=5
strategy("VW-MACD Histogram Analysis", overlay=true)
fastLength = input.int(12, title="Fast Length", minval=1)
slowLength = input.int(26, title="Slow Length", minval=1)
signalLength = input.int(9, title="Signal Length", minval=1)
vwmaFast = ta.vwma(close, fastLength)
vwmaSlow = ta.vwma(close, slowLength)
vwMacdLine = vwmaFast - vwmaSlow
vwSignalLine = ta.ema(vwMacdLine, signalLength)
vwHistogram = vwMacdLine - vwSignalLine
// Plot for visualization
plot(vwMacdLine, "VW-MACD Line", color.blue, display=display.pane_only)
plot(vwSignalLine, "VW-MACD Signal", color.orange, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)
histColor = vwHistogram >= 0
? (vwHistogram > vwHistogram[1]
? color.new(color.teal, 20)
: color.new(color.blue, 20))
: (vwHistogram < vwHistogram[1]
? color.new(color.red, 20)
: color.new(color.maroon, 20))
plot(vwHistogram, "VW-MACD Histogram", style=plot.style_columns, color=histColor, display=display.pane_only)
// Conditions for histogram momentum
increasingBullishMomentum = vwHistogram > 0 and vwHistogram > vwHistogram[1]
decreasingBullishMomentum = vwHistogram > 0 and vwHistogram < vwHistogram[1]
increasingBearishMomentum = vwHistogram < 0 and vwHistogram < vwHistogram[1]
decreasingBearishMomentum = vwHistogram < 0 and vwHistogram > vwHistogram[1]
// Example strategy using histogram signals
// Entry on increasing momentum, exit on decreasing momentum
if (increasingBullishMomentum)
strategy.entry("Long Hist Inc", strategy.long)
if (increasingBearishMomentum)
strategy.entry("Short Hist Inc", strategy.short)
if (decreasingBullishMomentum)
strategy.close("Long Hist Inc")
if (decreasingBearishMomentum)
strategy.close("Short Hist Inc")
To get the most from Volume-Weighted MACD in Pinescript:
By factoring in volume, VW-MACD aims to reduce false signals and provide more robust indications of momentum and trend shifts compared to its price-only counterpart.
The Volume-Weighted MACD is an enhanced and insightful momentum indicator available in Pinescript for TradingView. By integrating Volume-Weighted Moving Averages into its core calculation, it aims to provide more robust and conviction-based signals compared to the traditional MACD. While it still operates as a lagging indicator, its ability to filter out price moves not supported by significant volume makes its crossovers, divergences, and histogram analysis potentially more reliable. By understanding its calculation, thoughtfully tuning its parameters, and integrating it strategically with price action and other technical analysis tools, you can leverage Volume-Weighted MACD to enhance your Pinescript strategies and gain a clearer understanding of market momentum backed by underlying volume conviction.
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