Bentrix Docs
HomePricingDashboard

Volume-Weighted Average Price VWAP

Volumeoverlay3 linesin every package

The running total of price times volume divided by the running total of volume, restarted at the anchor you choose, with bands at plus and minus k volume-weighted deviations.

It measures the average price each unit of volume actually traded at since the anchor, which a moving average does not. Readings: price above or below VWAP since the anchor, and distance in band units. On a feed whose volume is tick count and not traded size, it is weighted by activity rather than by size — which is what these feeds carry.

01The study, live

Live figureScroll to zoom, drag the bars to pan.
bar —O — H — L — C —VWAP —band —band —first value at —
Show where:

Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.

What this figure shows

The figure is computed over 300 sample bars, and VWAP has a value from the first. Counting the conditions the study declares on these bars: price crosses above the line 25 times; price crosses below the line 24 times; price crosses above the upper band 23 times; price crosses below the lower band 22 times; price comes back inside the bands 46 times. Press a condition under the figure to see each place marked. As states rather than moments: price is above the line on 150 bars; price is below the line on 150 bars.

02Its parts, named

The lower bandthe same distance below the middleThe upper banda set distance above the middleThe linethe study's value, one for each barThe bars it readseach bar's open, high, low and close
Computed by Bentrix’s own code over the sample bars. It is drawn on once, as you reach the figure.

03What you see

A line that is the average price of everything traded since an anchor — the start of the day by default — each price weighted by its volume, with optional bands.

04Where it comes from

VWAP became a benchmark for institutional execution in the 1980s: a large order filled at better than the day's VWAP was considered well executed. Berkowitz, Logue and Noser's 1988 study is the classic early account.

05The formula

VWAPt=∑i=atTPiVi∑i=atVi,TP=H+L+C3
H, L, Cthe bar's high, low and close
Vieach bar's volume
athe anchor bar: the start of the session, week or month, or of the rolling window

from the anchor bar a. Bentrix's anchors: the session, the week, the month, or a rolling window, with bands at a multiple of the volume-weighted deviation.

06A worked example

The sample bars used here are eight: closes 20, 21, 23, 22, 24, 25, 24, 26; highs 21, 22, 24, 24, 25, 26, 26, 27; lows 18, 19, 20, 21, 21, 23, 23, 23; opens 19, 20, 21, 23, 22, 24, 25, 24; volumes 100, 120, 150, 90, 140, 160, 80, 170.

Treat the eight bars as one session. The typical price of the first bar is (21 + 18 + 20) / 3 = 19.67, on a volume of 100: after one bar VWAP is simply 19.67.

After two bars: (19.67 × 100 + 20.67 × 120) / (100 + 120) = 20.21

After all eight, the sum of price × volume is 23273 and the volume 1010: VWAP = 23.04.

The plain average of the eight typical prices is 22.83. VWAP is higher because the later, higher-priced bars were also the heavier ones.

07Built in Assay

The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.

THE SCRIPT’S GRAPH
//@version=6
indicator("Volume Weighted Average Price", overlay = true)
multiplier = input.float(1.0, "Band deviations")
// The sums start over at the beginning of each day.
day = math.floor(time / 86400000)
newDay = bar_index == 0 or day != day[1]
var float priceVolume = 0.0
var float squareVolume = 0.0
var float totalVolume = 0.0
if newDay
    priceVolume := 0.0
    squareVolume := 0.0
    totalVolume := 0.0
typical = (high + low + close) / 3
priceVolume := priceVolume + typical * volume
squareVolume := squareVolume + typical * typical * volume
totalVolume := totalVolume + volume
// The day's average typical price, each bar weighted by its volume.
vwap = totalVolume > 0 ? priceVolume / totalVolume : na
// How far the typical prices spread around it, weighted alike.
deviation = math.sqrt(math.max(squareVolume / totalVolume - vwap * vwap, 0.0))
plot(vwap, "VWAP")
plot(vwap + multiplier * deviation, "Upper band")
plot(vwap - multiplier * deviation, "Lower band")

Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.

08Readings — what traders look for

Price above or below VWAP is read as the market trading above or below the average price paid since the anchor.

Returns to VWAP during the day are read as price returning to that average.

How "price above VWAP" fails. It says price is above the session's volume-weighted average — that the average participant of the session is, on paper, ahead. Early in a session the line is made of a few bars and moves with every one; late in a session it is so heavy that price can be far from it without the line reacting.

How the bands fail. They are deviations around a cumulative average, so they widen through the session whatever happens; a touch late in the day is not the same event as a touch in the first hour.

09In different markets and timeframes

VWAP is an intraday study: it accumulates from the session's first bar, moves a great deal early and hardly at all late. On daily bars with a session anchor it is only the typical price. On markets without a central tape its volume is a count of ticks on one feed, and it should be read as activity rather than size.

10With other studies

Read with its deviation bands, and beside the volume-weighted moving average (its rolling relative).

11What it does not tell you

!

On currency markets volume is tick volume, so the weighting is by activity. A VWAP restarts at each anchor; early in the session it rests on few bars.

12Inputs and defaults

VWAP (session, 1)settings card
1Anchorsession
2Multiplier1
3Window20
4Second multiplier0
5Third multiplier0
6TimeframeChart
7Wait for the candle to closeOn
  1. 1
    Anchor — sessionWhere the accumulation starts again: each session, each week, each month, or a rolling window of bars. It decides what the line is an average of.
  2. 2
    Multiplier — 1How many volume-weighted standard deviations the bands stand from the line; 0 hides them.
  3. 3
    Window — 20For the rolling anchor only: how many bars the average covers.
  4. 4
    Second multiplier — 0A second pair of bands at this many deviations. 0 draws none.
  5. 5
    Third multiplier — 0A third pair of bands at this many deviations. 0 draws none.
  6. 6
    Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
  7. 7
    Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.

What each input changes

  • Second multiplierA second pair of bands at this many deviations from the line. 0 draws none.
  • Third multiplierA third pair of bands at this many deviations. 0 draws none. With all three set — 1, 2 and 3, for example — the bands divide the distance from the line into steps.
  • In useAnchored to the session by default; the week, the month or a rolling window are the other anchors. Bands at 1 to 3 deviations.

13Limits and common misreadings

It resets. At each anchor the line starts from nothing; the first values of a session are not comparable with the last of the one before.

Tick volume. On markets without a central tape (spot forex, most CFDs) the volume is one broker's count of price changes, not traded size. The study then measures activity on that feed; two brokers give two lines.

Intraday by nature. On daily bars with a session anchor every bar is its own session and the line is just the typical price.

14Conditions an alert or a strategy can watch

price crosses above the line eventprice crosses below the line eventprice is above the line stateprice is below the line stateprice crosses above the upper band eventprice crosses below the lower band eventprice comes back inside the bands event

Event: the bar it happens on an event happens on one barState: every bar while it holds a state holds on every bar while it lasts

These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.

15Practise it in the laboratory

Put a session VWAP on a 5-minute chart and replay one whole day; note how much the line moves in the first half hour and how little in the last.

Open the laboratory

17In Bentrix

  • From the menu: a chart's Indicators button › Volume › VWAP, or type VWAP in its search.
  • Its settings: the settings card opens when it is added; its legend's name opens it again.

18From an agent or a program

Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "vwap"}).

The study, as a chart files it

This is a new VWAP’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.

{
  "applied": "close",
  "convention": "custom",
  "kind": "vwap",
  "settings": {
    "anchor": "session",
    "mult": 1.0,
    "shape": "vwap",
    "window": 20
  }
}

An agent

An agent calls the MCP tool with it:

{
  "name": "study_values",
  "arguments": {
    "bench": "bentrix://lab/\u2026/bench/\u2026",
    "symbol": "EURUSD",
    "timeframe": "H1",
    "limit": 5,
    "study": {
      "applied": "close",
      "convention": "custom",
      "kind": "vwap",
      "settings": {
        "anchor": "session",
        "mult": 1.0,
        "shape": "vwap",
        "window": 20
      }
    }
  }
}

A program

A program does the same in its language — bench and market as in the built-in indicators guide:

Python

values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "custom", "kind": "vwap", "settings": {"anchor": "session", "mult": 1.0, "shape": "vwap", "window": 20}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
    print("line:", line["line"])
    print("  newest values:", line["values"])

JSJavaScript

const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "custom", "kind": "vwap", "settings": { "anchor": "session", "mult": 1.0, "shape": "vwap", "window": 20 } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
  console.log("line:", line.line);
  console.log("  newest values:", line.values);
}

C#C#

var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "custom", ["kind"] = "vwap", ["settings"] = new Dictionary<string, object?> { ["anchor"] = "session", ["mult"] = 1.0, ["shape"] = "vwap", ["window"] = 20 } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
    Console.WriteLine($"line: {line!["line"]!}");
    Console.WriteLine($"  newest values: {line!["values"]!}");
}

GOGo

values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "custom", "kind": "vwap", "settings": map[string]any{"anchor": "session", "mult": 1.0, "shape": "vwap", "window": 20}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
	fmt.Println("line:", at(line, "line"))
	fmt.Println("  newest values:", at(line, "values"))
}

Java

Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "custom", "kind", "vwap", "settings", obj("anchor", "session", "mult", 1.0, "shape", "vwap", "window", 20))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
    System.out.println("line:" + " " + at(line, "line"));
    System.out.println("  newest values:" + " " + at(line, "values"));
}

C++C++

auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "custom"}, {"kind", "vwap"}, {"settings", Json::Object{{"anchor", "session"}, {"mult", 1.0}, {"shape", "vwap"}, {"window", 20}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
    std::cout << "line:" << " " << line["line"].dump() << std::endl;
    std::cout << "  newest values:" << " " << line["values"].dump() << std::endl;
}

Julia

values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "custom", "kind" => "vwap", "settings" => Dict{String,Any}("anchor" => "session", "mult" => 1.0, "shape" => "vwap", "window" => 20)); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
    println("line:", " ", line["line"])
    println("  newest values:", " ", line["values"])
end

RR

values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "custom", kind = "vwap", settings = list(anchor = "session", mult = 1.0, shape = "vwap", window = 20)), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
  cat("line:", format(line$line), "\n")
  cat("  newest values:", format(line$values), "\n")
}

RRust

let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "custom", "kind": "vwap", "settings": {"anchor": "session", "mult": 1.0, "shape": "vwap", "window": 20}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
    println!("line: {}", line["line"]);
    println!("  newest values: {}", line["values"]);
}

Reading the answer

  • times — the candles’ open times, in milliseconds since 1970 (UTC), oldest first.
  • lines — one entry per line, in this order, each with its line name and its values; values[i] belongs to the candle at times[i].
  • The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
  • null is a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
lineWhat it is
Mainline
BandEdgeband
BandEdgeband

In a strategy

Filed under a key of your choice in a strategy document’s studies — here vwap: {"vwap": {"applied": "close", "convention": "custom", "kind": "vwap", "settings": {"anchor": "session", "mult": 1.0, "shape": "vwap", "window": 20}}} — its rules can name:

WriteWhat it is
vwapits main line, as a value in a compare
{"cond": "vwap:price.cross_up"}a condition it declares itself
{"cond": "vwap:price.cross_down"}a condition it declares itself
{"cond": "vwap:price.above"}a condition it declares itself
{"cond": "vwap:price.below"}a condition it declares itself
{"cond": "vwap:band.cross_above_upper"}a condition it declares itself
{"cond": "vwap:band.cross_below_lower"}a condition it declares itself
{"cond": "vwap:band.back_inside"}a condition it declares itself

Its lines named band_edge are more than one line of that name, so a strategy reaches them through the conditions above rather than by name.

19Sources

  1. Berkowitz, Stephen A., Logue, Dennis E. & Noser, Eugene A. Jr. "The Total Cost of Transactions on the NYSE." Journal of Finance, vol. 43, no. 1, 1988.

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed