Volume-Weighted TrendPine Script v6

Volume-Weighted Moving Average Pine Script — Complete TradingView Guide

The Volume-Weighted Moving Average (VWMA) Pine Script indicator is a trend-following moving average that weights each price bar by its trading volume, so high-volume price moves have a larger influence on the average than low-volume bars. In Pine Script v6, the built-in function ta.vwma(source, length) calculates VWMA with a default period of 20 bars applied to the closing price. Because VWMA reacts more strongly to volume-confirmed moves, it acts as a more market-aware alternative to the SMA and can distinguish between genuine breakouts driven by institutional participation and low-volume noise. VWMA is effective across stocks, cryptocurrency, and futures markets on timeframes from 15-minute to daily charts. This guide covers the complete Pine Script code, parameter tuning, and volume-weighted trading strategies.

What Is the Volume-Weighted Moving Average (VWMA)?

The Volume-Weighted Moving Average (VWMA) is a trend indicator that calculates a moving average weighted by trading volume, used to identify trend direction with greater sensitivity to high-conviction price moves. Unlike the Simple Moving Average (SMA), which treats every bar equally, VWMA multiplies each bar's closing price by its volume before averaging, so heavily traded bars carry proportionally more weight. The concept of volume-weighting in moving averages has been widely used in technical analysis since the 1980s alongside the popularization of volume-based indicators by analysts such as Joseph Granville (who introduced On-Balance Volume in 1963) and Marc Chaikin. The VWMA itself is a natural extension of these volume-analysis principles applied directly to moving average calculation.

The core formula for VWMA is:

VWMA = Sum(Close × Volume, N) ÷ Sum(Volume, N)

Where Close is the closing price of each bar, Volume is the number of shares or contracts traded on that bar, and N is the lookback period in bars. Each closing price is multiplied by its corresponding volume to produce a volume-weighted price, then the sum of these weighted prices is divided by total volume over N periods. When volume is constant across all bars, VWMA produces exactly the same result as SMA — the difference only manifests when volume varies, which it does in every real market.

In Pine Script v6, the complete calculation is handled by ta.vwma(source, length), where source is typically close and length is the lookback period (default: 20). The indicator plots directly on the price chart as an overlay (overlay=true) since it operates in price units.

VWMA applies to all asset classes with reliable volume data: stocks (individual equities, ETFs, indices), cryptocurrency (BTC, ETH, and major altcoins on high-liquidity exchanges), and futures (equity index futures, commodity futures, bond futures). VWMA is less effective for forex spot markets, where volume data is decentralized and unreliable — in such cases, a standard EMA or SMA is preferred.

Best timeframes for VWMA: 15M–1H charts work well for day trading, where intraday volume spikes provide strong weighting signals. 4H–Daily is most reliable for swing trading, capturing multi-day volume-confirmed trends. For position trading, a VWMA(50) or VWMA(200) on the daily chart tracks institutional accumulation and distribution phases. On timeframes below 5 minutes, volume data can be inconsistent and VWMA may produce unreliable signals.

VWMA Pine Script Code Example

The following Pine Script v6 code calculates the Volume-Weighted Moving Average using the built-in ta.vwma(close, 20) function and plots it directly on the price chart as a blue overlay line. To use it in TradingView, open the Pine Script Editor from the bottom toolbar, paste the code, click Save, then click Add to chart — the VWMA line will appear immediately on your price panel.

Pine Script v6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify

//@version=6
indicator(title="Volume-Weighted Moving Average", overlay=true, max_labels_count=500)

// VWMA — weights each price bar by its volume over the lookback period
p_ind_1 = ta.vwma(close, 20) // VWMA with default period 20

// Plot the VWMA line
plot(p_ind_1, title="VWMA", color=color.rgb(41, 98, 255, 0), linewidth=1)
Volume-Weighted Moving Average indicator Pine Script code example in TradingView

VWMA Pine Script Parameters

The ta.vwma(source, length) function accepts two parameters. The table below lists each parameter, its default value, description, and recommended ranges for different trading styles.

ParameterDefault ValueDescriptionRecommended Range
sourceclosePrice series used for the VWMA calculation. Common alternatives: hl2, hlc3, ohlc4close (default) for most use cases; hlc3 to smooth wick-driven extremes
length20Number of bars in the lookback window. Shorter values are more reactive to volume spikes; longer values smooth out short-term noise9–14 (day trading), 20 (swing, default), 50–200 (position trading)
linewidth1Thickness of the plotted VWMA line in the plot() call — a visual-only setting that does not affect the indicator values1 (clean overlay), 2 (visibility on busy charts)
colorcolor.rgb(41, 98, 255)Line color of the VWMA plot — blue by default, can be changed to contrast with other overlaysAny color; use distinct colors when plotting VWMA alongside EMA or SMA for comparison
Tuning scenarios:
  • Day trading (5M–15M charts): use length = 9 — captures intraday volume surges with fast response
  • Swing trading (4H–Daily): use the default length = 20 — balances sensitivity and noise reduction
  • Position trading (Daily–Weekly): use length = 50 or length = 200 — tracks institutional accumulation over extended periods

VWMA Trading Strategies

Strategy 1: VWMA Price Crossover with Volume Confirmation

Market environment: Trending / Breakout — best applied when volume is expanding alongside price movement. Pair with an ADX(14) above 20 to confirm trending conditions before entering.

Entry conditions (long):

  1. Price closes above VWMA(20) on the current bar
  2. Current bar volume is above its 20-bar SMA volume average (confirming volume-driven move)
  3. ADX(14) is above 20 (trending market filter)
  4. Enter at the open of the next bar after conditions are confirmed on bar close

Exit conditions:

  1. Price closes below VWMA(20) — trend weakening, exit position
  2. Stop-loss: below the prior swing low before the VWMA crossover

Strategy 2: VWMA + EMA Dual Moving Average Crossover

Market environment: Trending — uses VWMA(20) as the fast line and EMA(50) as the slow trend-direction filter. Best on 1H–4H charts for stocks and crypto.

Entry conditions (long):

  1. VWMA(20) crosses above EMA(50) on the closing bar
  2. Price is above EMA(200) on the daily chart (bull market confirmation)
  3. Volume on the crossover bar is above its 20-bar average
  4. Enter at next bar open after crossover confirms

Exit conditions:

  1. VWMA(20) crosses below EMA(50) — trend reversal, close long position
  2. Stop-loss: close below EMA(50) by more than 1 ATR(14)

Strategy 3: VWMA + RSI Momentum Pullback

Market environment: Trending with pullbacks — enters during temporary dips in an established uptrend. Combines VWMA direction with RSI oversold readings for high-probability re-entry.

Entry conditions (long):

  1. Price is above VWMA(50) on the daily chart (uptrend confirmed)
  2. Price pulls back and RSI(14) drops below 40 on the 4H chart (oversold pullback)
  3. Price touches or briefly closes below VWMA(20) on the 4H chart (pullback to dynamic support)
  4. Enter long when RSI(14) crosses back above 40 (momentum recovery)

Exit conditions:

  1. Target: prior swing high or RSI(14) above 70
  2. Stop-loss: below the VWMA(50) daily level — uptrend invalidated
Disclaimer: The trading strategies described above are for educational purposes only. They do not constitute investment advice or a recommendation to buy or sell any financial instrument. Past performance of any indicator or strategy does not guarantee future results. Always conduct your own research and consult a licensed financial advisor before trading.

How to Generate VWMA Pine Script in Pineify

Pineify generates production-ready Pine Script v6 code for the VWMA indicator in seconds — no coding knowledge required.

  1. 1

    Open Pineify at pineify.app

    Sign up for a free account or log in to access the indicator builder with 235+ built-in indicators.

  2. 2

    Click "Add Indicator" and search for VWMA

    Select "Volume-Weighted Moving Average" from the indicator library. Pineify pre-fills the default settings for you.

  3. 3

    Describe your strategy and configure VWMA settings

    Set the period (default 20), source (close/hl2/hlc3), and optionally add alert conditions, an EMA crossover filter, or RSI confirmation — Pineify handles the code.

  4. 4

    Copy the generated Pine Script v6 code

    Pineify generates a complete, runnable VWMA script with your exact settings. Click "Copy" to copy it to your clipboard.

  5. 5

    Adjust and paste into TradingView Pine Script Editor

    Open the Pine Script Editor on TradingView, paste the code, click Save, then click "Add to chart" to see your VWMA indicator live on the price panel.

Generate VWMA Pine Script for Free

VWMA Pine Script — Frequently Asked Questions

Related Pine Script Indicators

Explore other popular Pine Script indicators available in Pineify:

Ready to Generate Your VWMA Indicator?

Pineify generates production-ready Pine Script v6 code for VWMA and 235+ other indicators. Free to get started.

Get Started Free