Indicator · Pine Script v6 · On the chart

VWAP Price Channel Enhanced

by realanthonyc· code credited to Anthony

Calculates an adaptive price channel anchored to Donchian extremes, combining VWAP resets on dynamic highs and lows.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code79
Settings3inputs
LicenceMPL-2.0
Last update1 year ago28 Oct 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

79 lines of Pine Script v6 from vwap-price-channel-enhanced.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

vwap-price-channel-enhanced.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Anthony C. https://x.com/anthonycxc

//@version=6
// -----------------------------------------------------------------------------
//  VWAP Price Channel Enhanced
//  - Adaptive VWAP-based price channel with Donchian high/low anchors
//  - Supports short-term and long-term length selection
//  - Dynamic timeframe input (custom or chart TF fallback)
//  - Trend direction detection (dir / dir2) for coloring and fills
//  Forked from: VWAP Price Channel (VPC) by SamRecio
//  v2.1.6
// -----------------------------------------------------------------------------
indicator("VWAP Price Channel Enhanced", shorttitle="VWAP Price Channel", overlay=true)

// === Inputs ===
tf        = input.timeframe("", title="Timeframe")
len_short = input.int(20, title="Short-Term Length", minval=1)
len_long  = input.int(50, title="Long-Term Length",  minval=1)

// Resolve effective timeframe (if blank, fallback to chart TF)
res_tf = (tf == "" ? timeframe.period : tf)

// Decide whether to use long/short length based on the input TF (not the chart TF)
use_long    = str.contains(str.upper(res_tf), "W")
len_to_use  = use_long ? len_long : len_short

// === VWAP Price Channel Function ===
get_vpc(_len) =>
    // Persistent VWAPs for highs and lows
    var float h_vwap = high
    var float l_vwap = low
    float upper = na
    float lower = na

    // Explicit high/low source for Donchian extremes
    hst = ta.highest(high, _len)
    lst = ta.lowest(low,  _len)

    // Detect new extremes
    new_high = high == hst
    new_low  = low  == lst

    // VWAP reset on new extremes
    h_vwap := ta.vwap(high, new_high)
    l_vwap := ta.vwap(low,  new_low)

    // VWAP changes
    h_change = ta.change(h_vwap)
    l_change = ta.change(l_vwap)

    // Upper/Lower band step logic
    upper := new_high ? hst : (hst == hst[1] ? upper[1] + h_change : math.min(hst, upper[1] + h_change))
    lower := new_low  ? lst : (lst == lst[1] ? lower[1] + l_change : math.max(lst, lower[1] + l_change))

    // Midline
    _avg = math.avg(upper, lower)

    // Trend detection: dir = current bar, dir2 = persistent
    var int dir  = 0
    var int dir2 = 0
    dir  := new_high ? 1 : new_low ? -1 : 0
    dir2 := new_high ? 1 : new_low ? -1 : dir2[1]
    [upper, lower, _avg, hst, lst, dir, dir2]

// Call function on chosen TF (explicit ticker)
[upper, lower, mid, hst, lst, dir, dir2] = request.security(syminfo.tickerid, res_tf, get_vpc(len_to_use))

// === Display ===
u = plot(upper, title="Upper", color = dir == 1 ? color.rgb(0, 0, 0, 100) : color.new(color.rgb(255, 3, 62), 50), style=plot.style_linebr)
plot(mid,   title="Mid",   color = color.new(color.rgb(128, 128, 128), 50), display=display.none)
l = plot(lower, title="Lower", color = dir == -1 ? color.rgb(0, 0, 0, 100) : color.new(color.rgb(61, 170, 69), 50), style=plot.style_linebr)
c = plot(close, display=display.none, editable=false)

fill(u, c, dir2 == 1 ? color.rgb(0, 0, 0, 100) : color.new(color.rgb(255, 3, 62), 95), title="Fill")
fill(l, c, dir2 == -1 ? color.rgb(0, 0, 0, 100) : color.new(color.rgb(61, 170, 69), 95), title="Fill")

plot(hst, title="DC Upper", color=color.new(color.rgb(0, 77, 146), 25), display=display.none)
plot(lst, title="DC Lower", color=color.new(color.rgb(0, 77, 146), 25), display=display.none)

Overview

The indicator automatically toggles between short-term and long-term calculation lengths based on the chosen timeframe. It plots upper and lower channel bands, a mid-line, and trend-directional background fills directly on the price chart. Inputs allow customizing the timeframe and anchor lengths.

Details

Published by

realanthonyc on GitHub

Code credit

Anthony, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend, Volatility & bands, Moving averages, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

indicatorpinescripttradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Timeframetimeframetf
Short-Term Lengthint20len_short
Long-Term Lengthint50len_long
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

MA Envelope (MAE)

by mihakralj
99 stars

The MA Envelope indicator calculates upper and lower channel bands shifted by a user-defined percentage around a baseline moving average. It supports Simple Moving Average, Exponential Moving Average, and Weighted Moving Average calculation types. The script p

Indicator v6 Moving averagesSupport & resistance
Updated 4 weeks ago · Apache-2.0 GitHub repository of MA Envelope (MAE)

Trend Compass 4H

by chris-c-thomas
14 stars

Trend Compass 4H plots a multi-EMA ribbon (10/21/50) along with higher-timeframe reference levels on the price chart. It classifies trend phase into six states and calculates a composite weighted trend score. The script detects RSI and MACD divergences, analyz

Indicator v6 TrendMoving averages
Updated 6 months ago · MIT GitHub repository of Trend Compass 4H
10 stars

My Macro Cycle Indicator plots daily and weekly simple and exponential moving averages on the price chart, plus Pi Cycle and Mayer Multiple levels derived from the 200-day average. Optional toggles add support-band fills, a Keltner channel, CME futures gaps, a

Indicator v4 Moving averagesVolatility & bands
Updated 5 years ago · None stated GitHub repository of My Macro Cycle Indicator

This indicator plots a double-smoothed Supertrend baseline on the price chart, combining a Supertrend midline with WMA and EMA smoothing to show trend direction. Direction uses an ATR-scaled baseline slope with hysteresis, while percentile-ranked slope magnitu

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of Smooth Trend Radar [WavesUnchained]

SRI Indicator ft. MSB

by kingmalitha
7 stars

This indicator overlays an all-in-one technical analysis toolkit on the price chart. It plots multiple moving averages, including standard EMAs, SMAs, and a Trend Regularity Adaptive Moving Average, alongside Bollinger Bands, Supertrend, Nadaraya-Watson envelo

Indicator v5 Moving averagesTrend Repaints
Updated 3 years ago · None stated GitHub repository of SRI Indicator ft. MSB

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers