Loading…

Anchored VWAP From Selected Bar

An anchored VWAP is one of the few tools MT4 never shipped natively: a running volume weighted average that starts counting from a specific bar you pick - a session open, a news release, a swing low - rather than from the start of the chart. Traders who want one either eyeball a rough average by hand or install an indicator that repaints every time the chart scrolls. This script draws it once, as chart objects, anchored exactly where you put it. The anchor is not a bar-count input typed blind into a dialog box - it is a vertical line named vwap_anchor that you drag onto the bar you want. Run the script with no line present and it plants a starter line fifty bars back and tells you to move it, the same "show, don't guess" convention this catalogue uses for BracketFromLines' three price lines. Drag the line onto the exact bar, run the script again, and the VWAP is anchored there. The harder problem is that MT4 has no polyline object - there is nothing that draws one continuous curve through N points. This script works around that by chaining one OBJ_TREND segment per consecutive bar pair, each segment's ray switched off so it stops exactly at its own two points instead of extending across the chart. Two thousand bars back means two thousand short segments, drawn once, that read as a single smooth curve. "Volume" in the calculation is MT4 tick volume - the count of price changes per bar, not exchange traded contracts. That is the only volume series most forex feeds expose, and it is a reasonable proxy for where trading activity concentrated, but it is not the same number a futures VWAP is built on. The script does not pretend otherwise; it is stated here and in the source header so nobody mistakes tick count for lot count. Notes and limitations - Draws once. It does not extend the curve as new bars form - move the anchor or simply re-run the script to refresh it with the latest bars. - Built on tick volume, not real traded volume. On symbols where tick volume is a poor proxy for activity - very thin or synthetic instruments - the curve is still mathematically correct but less meaningful. - A zero-volume bar (a feed gap) cannot divide the running average, so its VWAP value is carried forward unchanged from the previous bar rather than breaking the curve. - The anchor resolves to the nearest bar at or before the vertical line's exact time; dragging the line between two bars snaps it to the older one. - Only one VWAP curve is intended per InpPrefix/InpAnchorLineName pair. To compare two anchors on the same chart, run the script twice with different values for both inputs.

Script · MT5 · v1.0 · Free

About Anchored VWAP From Selected Bar

Anchored VWAP From Selected Bar is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Anchor line name, Max bars and Line color. MQL source code included.

Files in the download: AnchoredVwapFromSelectedBar.ex5, AnchoredVwapFromSelectedBar.mq5, AnchoredVwapFromSelectedBar.txt.

Settings

SettingDefaultWhat it does
Anchor line namevwap_anchorName of the vertical line marking the anchor bar
Max bars2000Refuse to draw further back than this many bars
Line colorclrDodgerBlueVWAP line colour
Line width2VWAP line width
Prefixavwap_Prefix for every object this script draws

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: VWAP · Volume · Trading Sessions · News Trading · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria