Volume-Weighted Average Price VWAP
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
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
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
VWAPₜ = (Σ[i=a..t] TPᵢ Vᵢ)/(Σ[i=a..t] Vᵢ), TP = (H+L+C)/3
from the anchor bar . 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.
//@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
- 1Anchor — 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.
- 2Multiplier — 1How many volume-weighted standard deviations the bands stand from the line; 0 hides them.
- 3Window — 20For the rolling anchor only: how many bars the average covers.
- 4Second multiplier — 0A second pair of bands at this many deviations. 0 draws none.
- 5Third multiplier — 0A third pair of bands at this many deviations. 0 draws none.
- 6Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
- 7Wait 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
an event happens on one bar 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 laboratory17In 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"])JavaScript
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#
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"]!}");
}Go
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++
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"])
endR
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")
}Rust
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 itslinename and itsvalues;values[i]belongs to the candle attimes[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.
nullis a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
line | What it is |
|---|---|
Main | line |
BandEdge | band |
BandEdge | band |
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:
| Write | What it is |
|---|---|
vwap | its 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
- 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