Logo
OFFLINEPIXEL
/ pinescript-strategies / pine-script-volume-price-trend

$ Pinescript Volume Price Trend (VPT)

Master this insightful momentum indicator in TradingView's Pinescript that combines price changes and volume to confirm trends and anticipate price movements by tracking cumulative money flow.

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 Price Trend (VPT)?

The Volume Price Trend (VPT), sometimes referred to as Price-Volume Trend (PVT), is a momentum indicator that essentially measures the money flow into or out of an asset. It is a cumulative indicator that adds or subtracts a portion of daily volume to a running total, based on the percentage change in the security's price. The core idea behind VPT is similar to On-Balance Volume (OBV) but with a nuanced difference: while OBV adds/subtracts *all* volume based on a simple up/down close, VPT adjusts the volume added/subtracted based on the magnitude of the price change.

A rising VPT indicates that trading volume is higher on days when the price increases, suggesting strong buying pressure and accumulation. A falling VPT indicates higher volume on days when the price decreases, suggesting strong selling pressure and distribution. VPT is primarily used to:

  • Confirm price trends: A rising VPT confirms an uptrend, and a falling VPT confirms a downtrend.
  • Identify divergences: When price and VPT move in opposite directions, it can signal an impending trend reversal.
  • Measure money flow: Provides insight into the underlying buying and selling interest proportional to price movement.
02

Components and Calculation

The calculation of the Volume Price Trend is cumulative:

  1. Daily Price Change Ratio: Calculate the percentage change of the current closing price from the previous closing price.
    `Price Change Ratio = (Current Close - Previous Close) / Previous Close`
    * Handle `Previous Close == 0` to avoid division by zero.
  2. Volume Contribution: Multiply the `Price Change Ratio` by the current `Volume`.
    `Volume Contribution = Price Change Ratio * Current Volume`
  3. Volume Price Trend (VPT): This is a running, cumulative total of the `Volume Contribution`.
    `VPT = Previous VPT + Current Volume Contribution`
03

Basic Volume Price Trend (VPT) Implementation in Pinescript

pine-script@terminal
//@version=5
indicator("My Volume Price Trend (VPT)", overlay=false) // overlay=false to plot in a separate pane

// Calculate VPT using the built-in function
// ta.vpt() implicitly uses 'close' for price comparison and 'volume' for calculation
vptValue = ta.vpt(close, volume)

// Plot the VPT line
plot(vptValue, title="VPT", color=color.blue, linewidth=2)

// Optional: Add a Moving Average of VPT to act as a signal line
// Common lengths for VPT MA are 10, 20, or 30
vptMALength = input.int(20, title="VPT MA Length", minval=1)
vptMA = ta.sma(vptValue, vptMALength)

// Plot the VPT Moving Average (signal line)
plot(vptMA, title="VPT MA", color=color.orange, linewidth=1)

// Plot the Zero Line as a key reference point
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted)
$ ✓ Compiled successfully
04

Magnitude Matters

Magnitude Matters

Unlike OBV, VPT considers *how much* price moved. A small price change with high volume will impact VPT less than a large price change with the same volume, reflecting the efficiency of the move.

05

Practical Volume Price Trend (VPT) Trading Strategies

06

1. Divergence (Key Strategy)

pine-script@terminal
//@version=5
strategy("VPT Divergence Strategy", overlay=true)

vptValue = ta.vpt(close, volume)

// Plot VPT in a separate pane
plot(vptValue, "VPT", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Simple divergence detection (conceptual, robust detection requires advanced pivot logic)
// This example looks for recent higher/lower swings in price and VPT.

// Bullish Divergence: Price lower low, VPT higher low
bullishDiv = close < close[1] and close[1] < close[2] and vptValue > vptValue[1] and vptValue[1] > vptValue[2]

// Bearish Divergence: Price higher high, VPT lower high
bearishDiv = close > close[1] and close[1] > close[2] and vptValue < vptValue[1] and vptValue[1] < vptValue[2]

// Plot shapes on the chart to indicate divergence
plotshape(bullishDiv, title="Bullish VPT Divergence", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(bearishDiv, title="Bearish VPT 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)
$ ✓ Compiled successfully
07

2. Trend Confirmation and Strength

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

vptValue = ta.vpt(close, volume)
vptMALength = input.int(20, "VPT MA Length", minval=1)
vptMA = ta.sma(vptValue, vptMALength) // Moving Average of VPT

plot(vptValue, "VPT", color.blue, display=display.pane_only)
plot(vptMA, "VPT MA", color.orange, display=display.pane_only)

// Price trend filter (e.g., using a long-term EMA)
priceMALength = input.int(50, "Price MA Length", minval=1)
priceMA = ta.ema(close, priceMALength)

// Conditions for trend confirmation based on VPT and Price
// Long: Price above MA AND VPT above its MA (or rising)
longConfirm = close > priceMA and vptValue > vptMA and vptValue > vptValue[1]

// Short: Price below MA AND VPT below its MA (or falling)
shortConfirm = close < priceMA and vptValue < vptMA and vptValue < vptValue[1]

if (longConfirm)
    strategy.entry("Long Confirm", strategy.long)

if (shortConfirm)
    strategy.entry("Short Confirm", strategy.short)

// Basic exit: Price crosses back over price MA OR VPT crosses its MA
strategy.close("Long Confirm", when=close < priceMA or vptValue < vptMA)
strategy.close("Short Confirm", when=close > priceMA or vptValue > vptMA)
$ ✓ Compiled successfully
08

3. Zero-Line Crossovers (Bias Shift)

pine-script@terminal
//@version=5
strategy("VPT Zero Line Crossover Strategy", overlay=true)

vptValue = ta.vpt(close, volume)

plot(vptValue, "VPT", color.blue, display=display.pane_only)
hline(0, "Zero Line", color.gray, linestyle=hline.style_dotted, display=display.pane_only)

// Long entry: VPT crosses above zero
longCondition = ta.crossover(vptValue, 0)

// Short entry: VPT crosses below zero
shortCondition = ta.crossunder(vptValue, 0)

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

if (shortCondition)
    strategy.entry("Short VPT Cross", strategy.short)

// Basic exit: opposite signal
strategy.close("Long VPT Cross", when=shortCondition)
strategy.close("Short VPT Cross", when=longCondition)
$ ✓ Compiled successfully
09

Optimizing Volume Price Trend (VPT) Performance

To get the most from the Volume Price Trend in Pinescript:

  • Prioritize Divergence: Like OBV and other volume-based indicators, VPT's most powerful and actionable signals often come from divergences with price. These can provide early warnings of trend reversals.
  • Smooth with Moving Averages: Applying a moving average to the VPT line (as a signal line) can help smooth out noise and make crossovers more reliable for trend confirmation or signal generation. Common lengths for a VPT MA are 10, 20, or 30.
  • Combine with Price Action: Always confirm VPT signals with price action. A strong VPT reading is more significant if accompanied by a strong breakout or a clear reversal candlestick pattern.
  • Trend Context: Use VPT in the context of the larger trend. In an uptrend, look for positive VPT and bullish divergences for long entries. In a downtrend, look for negative VPT and bearish divergences for short entries.
  • Volume Data Quality: VPT relies heavily on accurate and reliable volume data. Ensure the asset you are analyzing has consistent volume reporting.
  • Compare with OBV: Understand the subtle difference between VPT and OBV. VPT's weighting by price change might make it more sensitive to strong price moves, while OBV treats all price changes equally. Experiment to see which works better for your asset/strategy.
10

Money Flow Strength

Money Flow Strength

VPT highlights whether money is flowing into or out of an asset, and critically, how much conviction (proportional to price change) that flow has.

11

Common Volume Price Trend (VPT) Pitfalls

  • Lag: As a cumulative indicator, VPT can exhibit lag, especially during sharp, fast-moving reversals. Divergence helps to address this to some extent.
  • False Signals: Like any indicator, it can generate false signals, particularly in choppy or low-volume markets where price fluctuates without a clear trend.
  • Scalability Issues: The absolute value of VPT varies widely between assets and can be very large. Its absolute level doesn't matter; what matters is its trend, slope, and divergence from price.
  • Dependency on Price Change: If the previous closing price is zero (e.g., for very low-priced assets or certain data issues), it can lead to division by zero in manual calculations. The `ta.vpt()` built-in handles this robustly.
  • Volume Data Quality: The accuracy of VPT is highly dependent on reliable and consistent volume data. Issues with volume data (e.g., OTC markets, highly illiquid assets) can impact its effectiveness.
  • Not a Standalone Indicator: VPT provides crucial insights but should never be used in isolation. It works best as a confirming indicator within a broader trading strategy.
12

Conclusion

Conclusion

The Volume Price Trend (VPT) is an insightful and effective momentum indicator available in Pinescript for TradingView. By uniquely combining price changes with volume, it provides traders with a deeper understanding of the underlying money flow and conviction behind price movements. While its greatest strength lies in identifying powerful divergences with price (signaling potential trend reversals), it also excels at confirming existing trends and validating shifts in market sentiment. By understanding its calculation, thoughtfully utilizing its signals, and integrating it strategically with price action and other technical analysis tools, you can leverage VPT to enhance your Pinescript strategies and gain a clearer understanding of smart money activity.

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