DynamicSwing vwap
- Indicadores
- Versão: 1.0
- Ativações: 5
An adaptive Volume-Weighted Average Price (VWAP) indicator that eliminates the guesswork of manual anchor selection. Instead of anchoring to a fixed session or calendar reset, it automatically anchors whenever the market forms a confirmed swing pivot (Higher High, Lower Low, Lower High, or Higher Low) and re-anchors with every new structural swing.
The indicator maintains two simultaneous VWAP lines on your chart:
- Active Segment (DS-VWAP): The VWAP running from the most recent swing anchor forward, color-coded in lime (bullish) or red (bearish) according to the current trend direction.
- Previous Segment (DS-VWAP prev): The VWAP from the recently retired segment, which continues to advance forward until price closes beyond its outer ATR band. This line helps you identify if the previous structure is still acting as support or resistance.
Each line includes optional ATR-scaled bands that define dynamic support and resistance zones. Graphical swing pivot labels (LL, HH, HL, LH, etc.) are placed directly on the chart at each pivot bar. An on-chart dashboard panel displays the current trend bias, live VWAP value, and last swing type.
HOW TO USE IT IN TRADING
1. Trend Identification: Trade in the direction of the Active Segment color (Lime for Buys, Red for Sells).
2. Dynamic Support and Resistance: Look for price retests on the Previous Segment line ("ghost line") for potential pullback entries.
3. Volatility Breaks: The ATR bands act as volatility channels. A candle closing outside the bands often signals momentum acceleration.
4. Timeframe Tuning:
- Scalping (M1 to M5): Recommended InpSwingPeriod = 21, InpBaseAPT = 10.
- Intraday (M15 to H1): Recommended InpSwingPeriod = 55, InpBaseAPT = 21.
- Swing (H4 to D1): Recommended InpSwingPeriod = 89 to 144, InpBaseAPT = 34 to 55.
CORE FORMULA AND DETECTION LOGIC
The VWAP computation uses an Exponential Weighted Moving Average (EWMA) formulation rather than a simple cumulative sum. The smoothing factor is derived from an Adaptive Period Time (APT) parameter.
Price used is the HLC3 typical price: (High + Low + Close) / 3. Volume is capped at 3x the 20-bar SMA of volume, with a fallback to the 50-bar rolling median when real volume is unavailable. Tick volume is used automatically on instruments without real volume data.
- ATR Bands: Band = VWAP +/- (EWMA_ATR x BandMultiplier), where EWMA_ATR is a parallel exponential-smoothed ATR computed over 50 bars.
- Adaptive APT: When enabled, APT is inversely scaled by the ratio of current ATR to its 50-bar average. High-volatility environments tighten the APT for faster response; low-volatility environments widen it.
- Swing Detection: A bar is classified as a swing high or low if it is the highest high or lowest low within the preceding InpSwingPeriod bars, evaluated on bar close.
- Previous Segment Invalidation: The previous VWAP stops drawing when the closing price crosses beyond the previous segment's outer band.
KEY PARAMETERS
- InpSwingPeriod (Default: 55): Lookback bars for swing high/low detection. Larger values mean fewer but more significant pivots. Range 5 to 200 recommended.
- InpBaseAPT (Default: 21.0): Base Adaptive Period Time. Controls EWMA smoothing speed. Lower values mean faster response. Range 5 to 300 recommended.
- InpUseAdapt (Default: false): Enable adaptive APT scaling by ATR ratio to tighten in high-volatility environments.
- InpVolBias (Default: 10.0): Exponent applied to ATR ratio in adaptive mode. Active only when InpUseAdapt is true.
- InpVolCap (Default: true): Cap volume at 3x 20-bar SMA to suppress volume-spike distortion.
- InpSmoothAnchor (Default: true): Apply 5-bar ramp-up when seeding a new anchor to reduce the visible VWAP discontinuity.
- InpOnlyLLHH (Default: false): Restrict re-anchoring to confirmed LL and HH pivots only, filtering out internal retracements.
- InpShowBands (Default: true): Show ATR-scaled upper and lower deviation bands as dotted lines.
- InpBandMult (Default: 0.618): ATR multiplier for band width. Use 0.618 for tight zones or 1.0 to 1.5 for wider standard deviation style bands.
- InpShowPivots (Default: true): Display swing pivot labels (LL, HH, HL, LH, EL, EH, IL, IH) on the chart.
- InpBullColor (Default: Lime): Color for bullish uptrend VWAP and bands.
- InpBearColor (Default: Red): Color for bearish downtrend VWAP and bands.
- InpLineWidth (Default: 2): Width of the main VWAP line (1 to 5). Bands always draw at width 1.
- InpShowDash (Default: true): Show the on-chart info dashboard panel.
- InpDashPos (Default: Top Right): Dashboard position on chart (Top Right, Top Left, Bottom Right, Bottom Left).
- InpLookbackBars (Default: 2000): Maximum bars to process on full recalculation. Set to 0 for unlimited.
COMPATIBILITY
- Platform: MetaTrader 5 (build 2755 and higher)
- Instruments: All markets (Forex, Indices, Commodities, Crypto, Stocks)
- Timeframes: All charts (M1 through MN)
- Buffers used: 12 (6 data buffers and 6 color-index buffers for DRAW_COLOR_LINE)
- Chart type: Main window overlay
