Skip to content
All library documents

Session-Anchored TWAP and Time-Weighted Deviation Bands

Article MQL5 code base

Summary

This document explains an indicator that calculates a time-weighted average price from a selected cash-market open through the end of the broker's server day. Unlike tick-volume-weighted VWAP, each unit of session time receives equal weight. To handle missing bars, the calculation extends the prior close across the unrepresented interval; an unfinished bar contributes only its elapsed duration. The indicator also plots one- and two-standard-deviation bands and reports the latest price's distance from TWAP, position in the session range, and time spent above the average.

Session anchors can be selected for Frankfurt, London, New York, Tokyo, or a manual server time, with daylight-saving conversion for the named markets. The author reports comparisons against independent calculations on several index and other symbols, timeframes, and sessions, with zero maximum difference in those checks. Limits include timeframe sensitivity, no configurable session close or exchange-holiday calendar, and tester clock behavior. It is a display tool, not a trading rule or order system.

Key ideas

  • The indicator gives every second since the selected cash open equal weight in its average price.
  • Missing intervals are represented by carrying the previous bar's close forward for the missing time.
  • The display can include time-weighted standard-deviation bands and session context for the latest close.
  • Named market opens account for daylight-saving changes, while manual mode uses broker server time.
  • Reported calculation checks cover several instruments and timeframes, but the output varies slightly with timeframe.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.