VWAP Band Fills with Anchored VWAP
- Indicators
-
Kazuma Uezono
MQL5 / MQL4 / Pine Script v6 developer and active trader.
Seller on the MQL5 Market (indicators for MT4/MT5).
Services:
- TradingView Pine Script to MT5/MT4 conversion (bar-by-bar matching, with tester report)
- MT4 to MT5 migration - Version: 1.2
VWAP Band Fills with Anchored VWAP is a TV-compatible VWAP for MetaTrader 5. It uses the same formula as the built-in "VWAP" indicator of TradingView (Pine ta.vwap), offers the same inputs - anchor period, source, offset, standard deviation or percentage bands #1 to #3 - and draws it the same way: a blue VWAP line, green / olive / teal bands and light fills between them. An optional anchored VWAP starts from a vertical line that you drag to any bar.
HOW IT IS CALCULATED
For every bar of the current anchor period:
- VWAP = sum(source x volume) / sum(volume)
- standard deviation = square root of ( sum(volume x source^2) / sum(volume) - VWAP^2 )
- Band #n = VWAP +/- deviation x multiplier #n; in Percentage mode the distance is VWAP x 1% x multiplier.
The sums restart at the first bar of each new anchor period.
ANCHOR PERIODS AND SOURCE
- Anchor Period: Session (default), Week, Month, Quarter, Year, Decade, Century.
- Session and week boundaries follow the server time of your account (server 00:00). The week starts on Monday.
- Sunday bars: on symbols that have a short Sunday session but no Saturday bars, Sunday is counted as part of Monday (Auto). You can also choose "merge" or "separate".
- Source: open, high, low, close, hl2, hlc3 (default), ohlc4, hlcc4. Offset 0-500 bars.
- Hide VWAP on 1D or Above (off by default), as on TradingView.
BANDS AND FILLS
- Standard Deviation (default) or Percentage mode. Band #1 is shown by default (x1); #2 (x2) and #3 (x3) can be turned on. Multipliers 0-100.
- The space between the bands is filled with each band's color at 5% opacity, like TradingView. MT5 fills that overlap would cancel each other out, so the indicator splits them into separate strips and mixes the colors with your chart background. If you change the background color, the fill colors follow.
- So that the fills do not cover the candles, "Chart on foreground" is switched on automatically while the fills are shown. When you remove the last copy of this indicator from the chart, the original setting is restored. Another fill-using tool of the same series shares this setting, so it is restored only when none of them is left on the chart. You can turn this off with "Keep candles in front of the fills".
ANCHORED VWAP (OPTIONAL)
- Turn on "Show anchored VWAP". A dotted vertical line appears 100 bars back (adjustable).
- Drag the vertical line to the bar you want the anchored VWAP to start from (for example a swing high or a news bar). The line is recalculated from the new bar when you release it.
- It uses the same source and volume as the main VWAP, without bands.
- All copies of this indicator on one chart share the same vertical line. It is deleted when the last copy is removed.
VOLUME AND DIFFERENCES FROM TRADINGVIEW
- Volume: tick volume (default). On symbols with real exchange volume you can choose Real or Auto. If you choose Real on a symbol without it, the indicator uses tick volume and says so in the lower-left corner.
- Forex and CFD brokers supply tick volume, and TradingView's data feed has its own volume. The formula is identical, but the volume numbers are not, so the VWAP values will not match TradingView exactly.
- Forex and gold: on servers whose midnight is 17:00 New York time (the common GMT+2 / GMT+3 setup), the session starts at the same time as on TradingView.
- 24-hour symbols such as BTC: TradingView starts the session at 00:00 UTC. If your server runs on another time zone, the session (and week) starts a few hours earlier or later, so the Session VWAP has different values from TradingView.
FOR EA AND iCUSTOM USERS
Buffers 10 to 17: 10 = VWAP, 11 = Upper Band #1, 12 = Lower Band #1, 13 = Upper Band #2, 14 = Lower Band #2, 15 = Upper Band #3, 16 = Lower Band #3, 17 = Anchored VWAP. Buffers 0 to 9 are the fills; do not use them.
Band values are calculated even for bands that are not shown. Bars without a value return EMPTY_VALUE.
When called through iCustom, nothing is drawn on any chart and no chart setting is changed; the anchored VWAP then starts "First anchor: bars back" bars before the newest bar. If an EA attaches it to another chart with ChartIndicatorAdd, it may draw nothing there; attach it by hand or with a template to see the lines.
PLEASE READ BEFORE USE
- The values of the bar that is still forming change with every tick, as on TradingView. Closed bars do not change, except the anchored VWAP after you move the vertical line.
- During the first 15 seconds or so after attaching, the short name in the indicator list can briefly change to "probe#...". This is how the indicator checks whether it runs on a chart or inside iCustom. It changes back by itself.
- In the Strategy Tester it draws no objects and prints nothing.
- No DLLs, no external files, no internet connection.
- A charting aid only. It has no alerts and no signals, does not trade, and does not guarantee any trading result.
INPUTS
VWAP Settings: Hide VWAP on 1D or Above (false), Anchor Period (Session), Source (hlc3), Offset (0), Volume (Tick volume), Sunday bars (Auto)
Bands Settings: Bands Calculation Mode (Standard Deviation), Show Band #1 (true) / Multiplier #1 (1), Show Band #2 (false) / Multiplier #2 (2), Show Band #3 (false) / Multiplier #3 (3)
Style: VWAP color (#2962FF), VWAP width (1), Band #1 / #2 / #3 color (#4CAF50 / #808000 / #089981), Band line width (1), Fill bands (true), Fill opacity % per band (5), Keep candles in front of the fills (true)
Anchored VWAP: Show anchored VWAP (false), First anchor: bars back (100), Anchored VWAP color (#FF9800), Anchored VWAP width (2), Language (Auto)
If an input is out of range, the indicator does not load and writes the reason to the Experts log.
SUPPORT
Questions about installation, settings and bugs are welcome through MQL5 messages. Questions about market direction or individual trades are outside the support scope.
This is part of a series of free TV-style tools. An MT4 edition is also available as a separate product. Other tools by the same author are listed on my seller profile.
TradingView is a trademark of TradingView, Inc. This product is not affiliated with, sponsored by or endorsed by TradingView, Inc.
