Indicator · Pine Script v6 · On the chart

Chart VWAP

by regalouisei· code credited to TradingView

Chart VWAP calculates and plots an anchored volume-weighted average price across the visible chart window directly on the price chart.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv6current
Lines of code142
Settings4inputs
LicenceNone statedfile: MPL-2.0
Last update8 months ago25 Feb 2026

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

142 lines of Pine Script v6 from pinescript/editors_picks/chart-vwap.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

chart-vwap.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradingView

//@version=6
indicator("Chart VWAP", overlay = true)

// Chart VWAP
// v3 2026.01.09

// This code's style is based on the recommendations from the Pine Script User Manual's Style guide:
//    https://www.tradingview.com/pine-script-docs/writing/style-guide/



import PineCoders/VisibleChart/5 as PCvc



//#region ———————————————————— Constants and inputs


// Tooltips
string AVG_TT = "Select to display the cumulative average close price across the visible chart range."
string OHLC_TT = (
    "Select 'Show chart OHLC levels' to display horizontal lines at the open, high, low, and close of the visible "
    + "chart range.\n\nSelect 'Show HL and % to close values' to view the highest and lowest values and the percentage"
    + "distance from those values to the visible close."
)
string TT_STD = (
    "The standard deviation multiplier for calculating the bands. For example, with a multiplier of 1, the distance "
    + "from the VWAP to the bands is 100% of the standard deviation."
    + "\n\nTo hide the bands, use a value of 0."
)

// Inputs
bool   showAvgInput   = input.bool(true,   "Show bar average",              tooltip = AVG_TT)
bool   showOhlcInput  = input.bool(false,  "Show chart OHLC levels ",       inline = "11")
bool   showLevelInput = input.bool(true,   "Show HL and % to close values", inline = "11", tooltip = OHLC_TT)
float  stdMultInput   = input.float(0.0,   "Standard deviation multiplier", inline = "12", minval = 0.0, step = 0.5, tooltip = TT_STD)
//#endregion



//#region ———————————————————— Functions


// @function            Sets the coordinates of a horizontal line using the leftmost and rightmost visible chart times
//                      and a specified level.
// @param lineId        (line) The ID of the `line` object to update.
// @param level         (series float) The price level of the horizontal line.
// @returns             (void) The function does not return a usable value.
setChartLine(line lineId, series float level) =>
    line.set_xy1(lineId, chart.left_visible_bar_time,  level)
    line.set_xy2(lineId, chart.right_visible_bar_time, level)


// @function            Calculates the difference between two prices as a percentage of the end price.
// @param startPrice    (series float) The initial price value.
// @param endPrice      (series float) The final price value.
// @returns             (float) The distance from `startPrice` to `endPrice`, as a percentage of `endPrice`.
percent(series float startPrice, series float endPrice) =>
    float result = (startPrice - endPrice) / endPrice * 100


// @function            Calculates the volume-weighted average price (VWAP) and upper and lower standard deviation bands
//                      across the chart's visible bar range.
// @param source        (series float) Optional. The series of values to process. The default is `hlc3`.
// @param stDev         (simple float) Optional. The standard deviation multiplier, which controls the width of the
//                      bands. The default is 1.
// @returns             ([float, float, float]) A tuple containing the visible VWAP, upper band, and lower band values.
vVwap(series float source = hlc3, simple float stDev = 1) =>
    bool startTime = time == chart.left_visible_bar_time
    [vwap, upper, lower] = ta.vwap(source, startTime, stDev)
//#endregion



//#region ———————————————————— Calculations


// VWAP anchored on the leftmost visible bar.
[chartVwap, upperBand, lowerBand] = vVwap(hlc3, stdMultInput)

// Average `close` of all visible bars.
float barAvg = PCvc.avg()

// OHLC values for the visible chart time range.
[chartOpen, chartHigh, chartLow, chartClose, _] = PCvc.ohlcv()
//#endregion



//#region ———————————————————— Visuals


// Plot the visible VWAP, average bar price, and the standard deviation bands, depending on the specified inputs.
plot(chartVwap, "Chart VWAP", color.orange, 2)
plot(PCvc.barIsVisible() and showAvgInput ? barAvg : na, "Visible avg.", color.new(color.gray, 50))
p1 = plot(stdMultInput != 0 ? upperBand : na, "Upper band", color.green)
p2 = plot(stdMultInput != 0 ? lowerBand : na, "Lower band", color.green)
fill(p1, p2, color.new(color.green, 95), "Bands fill")

// @variable The UNIX timestamp for placing the price/percent labels 25% into the visible range, starting from the left.
int labelTime = PCvc.chartXTimePct(25)

// Logic to draw the OHLC lines and price/percent labels
if showOhlcInput and barstate.islast
    // Initialize persistent variables to reference drawing objects.
    var line  chartHighLine  = line.new(na, na, na, na, xloc.bar_time, extend.right, #4CAF5075,  line.style_solid,  1)
    var line  chartLowLine   = line.new(na, na, na, na, xloc.bar_time, extend.right, #f2364580,  line.style_solid,  1)
    var line  chartOpenLine  = line.new(na, na, na, na, xloc.bar_time, extend.right, color.gray, line.style_dotted, 1)
    var line  chartCloseLine = line.new(na, na, na, na, xloc.bar_time, extend.right, #787B8675,  line.style_solid,  1)
    var label chartHighLabel = label.new(
        na, na, "", xloc.bar_time, yloc.price, color(na), label.style_label_down, #4CAF5075
    )
    var label chartLowLabel  = label.new(
        na, na, "", xloc.bar_time, yloc.price, color(na), label.style_label_up, #f2364580
    )

    // Update the coordinates of the OHLC lines.
    setChartLine(chartOpenLine,  chartOpen)
    setChartLine(chartHighLine,  chartHigh)
    setChartLine(chartLowLine,   chartLow)
    setChartLine(chartCloseLine, chartClose)

    // Update the labels to display price and percentage at the current levels if the `showLevelInput` value is `true`.
    if showLevelInput
        string labelFormat = "{0} ({1, number, #.##}%)"
        label.set_xy(chartHighLabel, labelTime, chartHigh)
        label.set_xy(chartLowLabel,  labelTime, chartLow)
        // Update label values with each chart update.
        label.set_text(
            chartHighLabel, str.format(
                labelFormat, str.tostring(chartHigh, format.mintick), percent(chartHigh, chartClose)
            )
        )
        label.set_text(
            chartLowLabel, str.format(
                labelFormat, str.tostring(chartLow,  format.mintick), percent(chartLow,  chartClose)
            )
        )
//#endregion

Overview

Chart VWAP supports optional upper and lower standard deviation bands adjusted by a multiplier. Additional settings allow users to display the cumulative average close price and horizontal lines for the visible range open, high, low, and close, complete with percentage distance labels to the visible close. Plotted values recalculate dynamically whenever the chart is zoomed or panned.

Details

Published by

regalouisei on GitHub

Code credit

TradingView, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
Show bar averagebooltrueshowAvgInput
Show chart OHLC levels boolfalseshowOhlcInput
Show HL and % to close valuesbooltrueshowLevelInput
Standard deviation multiplierfloat0.0stdMultInput
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

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

MGIC-tracker

by Allen1212
303 stars

The MGIC-tracker is a TradingView indicator that overlays ARK Invest trade records onto stock price charts. It plots buy and sell labels at the exact timestamp of each transaction, showing share volume and ETF weight. Users select a specific ETF type via setti

Indicator v4 Support & resistanceVolume
Updated 2 years ago · None stated GitHub repository of MGIC-tracker
228 stars

Comprehensive Volume Profile is an overlay indicator that calculates and plots volume distribution across specified time ranges such as daily sessions, weekly, monthly, or custom bar lengths. It identifies key structural price levels including the Point of Con

Indicator v6 VolumeSupport & resistance
Updated 3 months ago · None stated GitHub repository of Comprehensive Volume Profile

Moon Dev GEX Arrows

by moondevonyt
92 stars

This overlay indicator plots option strike walls and an optional session VWAP on the price chart for SPY or ES. It spaces major strikes by the selected instrument, draws a set number of strikes on each side, and marks wall-trap and sweep events after a cooldow

Indicator v5 Support & resistanceSessions & time
Updated 2 months ago · Custom licence GitHub repository of Moon Dev GEX Arrows

More Volume scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers