Session VWAP
- Göstergeler
- Sürüm: 1.31
- Etkinleştirmeler: 20
Overview
Session_VWAP is a custom indicator for MetaTrader 5 (version 1.33) that calculates the Volume-Weighted Average Price (VWAP) within a trading session and builds ±1σ and ±2σ deviation bands around it (standard deviations). It also fills the area between the bands, shows a statistics panel, and fires alerts on line crossings. It draws in the main chart window and is designed for intraday timeframes M1–H12.
How it works
1. VWAP calculation (cumulative across session bars)
typical = (High + Low + Close) / 3 // typical price of a bar VWAP = Σ(typical × volume) / Σ(volume) // accumulated over the session σ = sqrt(E[x²] − E[x]²) // standard deviation in a single pass Band1 = VWAP ± n1·σ // first-level bands (default ±1σ) Band2 = VWAP ± n2·σ // second-level bands (default ±2σ)
- Volume source: tick volume (default) or real volume ( InpUseRealVolume ).
- A single pass accumulates V , P·V , P²·V sums — no second pass needed.
2. Session detection
- Session start is configurable: hour:minute ( InpSessionStartHour , InpSessionStartMin ).
- The session lasts 24 hours from the start point.
- A new session begins when either: the "session key" changes (calendar date of session start) or there is a time gap greater than 24 hours (weekends, holidays) — this guarantees a correct recalculation restart.
- The "show only current session" option hides earlier sessions ( EMPTY_VALUE + line break).
3. Lines and fill
6 plots / 7 buffers:
- Plot 0 — ±1σ fill (buffers unused — see below);
- VWAP — solid blue line;
- Upper/Lower Band 1 — red/green dotted (±1σ);
- Upper/Lower Band 2 — dark red / dark green dashed (±2σ).
Fill feature: the standard DRAW_FILLING always draws on top of candles in the main window and repaints them, so the fill is done with background OBJ_RECTANGLE objects ( SVWAP_Fill_* , BACK=true ) behind the price chart:
- rectangles overlap by half a bar — no visible seams;
- "transparency" is emulated by blending the color with the chart background (chart objects ignore the alpha channel);
- the fill window is capped at 800 bars and stays in sync with history (stale objects are deleted).
4. Statistics panel (7 lines)
- Session VWAP (title);
- current VWAP value;
- B1 — upper/lower ±1σ boundary;
- B2 — upper/lower ±2σ boundary;
- 1σ and accumulated session volume;
- Price vs VWAP — price deviation from VWAP in % (line colored green/red);
- Session ends in — time left until session end.
The panel works in any of the 4 chart corners with configurable offsets, font size and colors; the background auto-fits the longest line; it is not created in the Strategy Tester.
5. Alerts (on the closed bar)
The checked bar is rates_total − 2 (already closed — no repainting), maximum 1 alert per bar:
- VWAP cross up — bullish momentum shift;
- VWAP cross down — bearish momentum shift;
- Upper band ±1σ/±2σ breakout — strong upward impulse;
- Back below upper band — momentum weakening (Bearish);
- Lower band ±1σ/±2σ breakout — strong downward impulse;
- Back above lower band — bounce off the band (Bullish).
Notifications: pop-up Alert , Push to phone, sound — all separately switchable; ±1σ and ±2σ alerts use separate flags.
6. Incremental recalculation
- prev_calculated is used properly: only the last bar is recalculated on each tick;
- because VWAP is cumulative, the loop rolls back to the session start to restore the sums; when a new session begins the sums reset and the line breaks.
7. Settings (summary)
Session time & volume, deviation bands (multipliers, fill on/off, color, opacity), notifications, and statistics panel. Inputs are validated in OnInit (negative multipliers or invalid start time → INIT_PARAMETERS_INCORRECT ).
Advantages
- Institutional metric: VWAP is a standard used by large market participants to assess the "fair" price of a session; this indicator puts it on any intraday chart.
- Relative-value context: ±1σ/±2σ bands show how far price has deviated from the volume-weighted average — handy for spotting overbought/oversold conditions within a session.
- Clean fill rendering: bands are highlighted behind the candles without repainting them; "transparency" is emulated by blending with the background, so it looks natural on any chart theme.
- No signal repainting: alerts fire only on closed bars, at most one per bar — signals are stable and suitable for backtesting.
- Configurable session start: can be tied to any trading session (Asian, London, New York, or a custom daily schedule).
- Gap resilience: weekends and holidays correctly end one session and start a new one.
- Volume flexibility: tick or real volume — matches broker data.
- Informative panel: VWAP, bands, σ, volume, price deviation % and time-to-session-end on one screen, with auto-sized background.
- Efficient: single-pass math (E[x²] − E[x]²), incremental updates, fill window capped at 800 bars.
- Clean and resource-friendly: no chart objects in the tester; on removal only indicator-owned objects (prefixes SVWAP_* ) are deleted.
- Safe signal delivery: it is an informational tool, not a trading robot — alerts are for reference only.
Notes and recommendations (from the author's comments)
- On D1/W1 each bar is its own session: σ = 0 and the bands degenerate — the indicator is meant for M1–H12.
- ±2σ breakouts are often followed by a pullback — entering on a breakout needs caution.
- Recommended usage: use VWAP crossings as a direction reference; confirm entries on a higher timeframe; always use a stop loss; verify signals on history/demo.
- Alerts do not guarantee profit — this is an analysis tool, not a ready-made trading solution.
