TradingView Volatility-Driven VWAP Structure [Zeiierman] Conversion to NinjaTrader 8
Zeiierman’s Volatility-Driven VWAP Structure stitches together two ideas: a rolling VWAP that flips its anchor on detected reversals (so each anchor block represents a clean trend swing) plus a structure-level system whose transitions are gated by a sigmoid-z volatility step.
Two structures stack: a discrete-step structure (StructureMean) that only transitions when volatility crosses a sigmoid threshold, and a continuous reversal-anchored VWAP with running std-dev bands at user-set multiples (Band1 = 1×, Band2 = 2× by default). The chart shows both — the structure mean as a dotted line, the AVWAP as solid, with two pairs of std-dev bands.
This post is the NinjaTrader 8 conversion. The full source compiles standalone in indTradingView/, exposes the structure mean, AVWAP, four band levels, and the direction signal as Series<> outputs for strategy use, and is yours to download as a NinjaScript Archive.
Original Pine Script: Volatility-Driven VWAP Structure by Zeiierman
License: Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
🆚 What Makes Volatility-Driven VWAP Structure Different
Standard VWAP runs continuously from session open. Useful, but the VWAP drifts away from price in long sessions and the deviation bands lose meaning. Reversal-anchored VWAP resets at each detected reversal, so each VWAP block represents a clean trend swing — the bands are meaningfully tight to the swing’s price action.
Sigmoid-z volatility step. The structure-mean transitions are gated by a sigmoid-z calculation on ATR. ATR fast vs ATR slow gives the volatility regime; the sigmoid bounds it in [0..1]; the structure only steps when the sigmoid crosses a threshold. So small volatility wiggles don’t move the structure; only genuine regime changes do.
Live running sum / sum² accumulators. The std-dev bands aren’t a moving-window stddev — they’re computed from the running sum and sum² accumulators since the last anchor. So Band1 / Band2 reflect the actual volatility of the current swing, not a rolling average that includes prior swings.
Six plot outputs. Structure Mean (dotted), Anchored VWAP, AUpper1 / ALower1 (Band1), AUpper2 / ALower2 (Band2). All exposed as Series<double> for strategy use.
⚙️ Settings
Volatility-Driven VWAP Structure exposes its inputs in two property groups: the calculation parameters (VWAP length, structure multiplier, ATR length) and the band toggles + multipliers + colors.
Settings
| Parameter | Default | Description |
|---|---|---|
| VWAP Length | 200 | Lookback for the rolling VWAP base. |
| Structure Multiplier | 1.5 | Multiplier on the sigmoid-z volatility step for structure transitions. |
| ATR Length | 14 | ATR period used in the sigmoid-z volatility calculation. |
Bands
| Parameter | Default | Description |
|---|---|---|
| Show Band 1 | True | Render the inner std-dev band pair (BandMult1). |
| Show Band 2 | True | Render the outer std-dev band pair (BandMult2). |
| Band Multiplier 1 | 1.0 | Std-dev multiplier for Band 1. |
| Band Multiplier 2 | 2.0 | Std-dev multiplier for Band 2. |
🧠 How It Works
Each bar runs the rolling VWAP, the sigmoid-z volatility check, and the structure-level / AVWAP updates.
- Rolling VWAP base. Maintain SUM(hlc3 × volume, VwapLength) and SUM(volume, VwapLength); rolling VWAP = ratio. This is the volatility input source for the sigmoid-z calc.
- Sigmoid-z volatility step. Compute ATR fast / ATR slow ratio, z-score it against its own mean and stddev, run through a sigmoid. Result is in [0..1]. When the sigmoid crosses ± StructureMultiplier × threshold, the structure mean steps to the current price.
- Sticky structure levels. Until the sigmoid threshold is crossed, structureUpper / structureLower hold their prior values. So small volatility wobbles don’t move the structure.
- Reversal detection. When close crosses a sticky structure level, the direction flips and the AVWAP anchor resets — accumulators (anchorSumPV, anchorSumV, anchorSumP2V) are zeroed.
- Anchored VWAP and bands. Each bar adds price × volume to anchorSumPV, volume to anchorSumV, price² × volume to anchorSumP2V. AVWAP = anchorSumPV / anchorSumV. Variance = anchorSumP2V / anchorSumV − AVWAP². StdDev = sqrt(variance). Bands at AVWAP ± BandMult × StdDev.
- Plot routing. StructureMid as a dotted plot. AnchoredVwap as solid. Band1 / Band2 as solid lines toggleable via the Show flags. SharpDX translucent fills between the AVWAP and each band layer when shown.
The indicator is non-repainting — every accumulator update and structure transition uses closed-bar data only.
🛠️ Using It in a Strategy
Volatility-Driven VWAP Structure is a multi-purpose tool. The most natural strategy use is mean-reversion at the outer band — enter when close hits AUpper2 / ALower2 and exit at AnchoredVwap. The example below uses that pattern.
Below is the lifecycle: instantiate in State.DataLoaded, then in OnBarUpdate watch for outer-band penetrations.
private VolatilityDrivenVwapStructure vdv;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "VolatilityDrivenVwapStructureStrategyExample";
}
else if (State == State.DataLoaded)
{
vdv = VolatilityDrivenVwapStructure(
200, // VWAP Length
1.5, // Structure Multiplier
14, // ATR Length
true, // Show Band 1
true, // Show Band 2
1.0, // Band Multiplier 1
2.0 // Band Multiplier 2
);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 220) return;
// Mean-reversion at the outer band
bool stretchedLow = Close[0] < vdv.ALower2[0] && Close[1] >= vdv.ALower2[1];
bool stretchedHigh = Close[0] > vdv.AUpper2[0] && Close[1] <= vdv.AUpper2[1];
if (stretchedLow && Position.MarketPosition != MarketPosition.Long) EnterLong();
if (stretchedHigh && Position.MarketPosition != MarketPosition.Short) EnterShort();
// Take profit at the AVWAP
if (Position.MarketPosition == MarketPosition.Long && Close[0] >= vdv.AnchoredVwap[0]) ExitLong();
if (Position.MarketPosition == MarketPosition.Short && Close[0] <= vdv.AnchoredVwap[0]) ExitShort();
}
Seven Series<> outputs cover the structure mean, the AVWAP, all four bands, and the direction state. Strategies can pick any combination — outer-band mean reversion, AVWAP cross, structure-level break, etc.
Public Outputs
| Output | Type | Description |
|---|---|---|
| StructureMid[0] |
Series | Structure mean — discrete-step center line gated by volatility sigmoid. |
| AnchoredVwap[0] |
Series | Reversal-anchored VWAP — resets at each detected reversal. |
| AUpper1[0] |
Series | AVWAP + BandMult1 × running stddev. |
| ALower1[0] |
Series | AVWAP − BandMult1 × running stddev. |
| AUpper2[0] |
Series | AVWAP + BandMult2 × running stddev. |
| ALower2[0] |
Series | AVWAP − BandMult2 × running stddev. |
| Direction[0] |
Series | 1 in an uptrend, −1 in a downtrend, 0 pre-init. |
🔄 Conversion Notes
A few things changed in the translation from Pine Script to NinjaScript:
Rolling VWAP via SUM primitives. NT8’s SUM primitive wraps the hlc3×volume and volume series, sized by VwapLength. The ratio gives the rolling VWAP base.
Sigmoid-z volatility step. ATR fast / ATR slow ratio is z-scored against its own SMA + StdDev, then run through a sigmoid (1 / (1 + e^−x)). The result gates the structure transitions.
Reversal-anchored VWAP via running accumulators. Pine’s array-based AVWAP becomes three scalar fields (anchorSumPV, anchorSumV, anchorSumP2V) updated each bar. The std-dev bands come from the running sum² over the same window.
SharpDX translucent band fills. Pine’s fill() calls between the AVWAP and each band become per-bar SharpDX trapezoids in the bull / bear tone. Two band-layer brushes per direction.
9 alertconditions stripped. Per the conversion convention. Strategy consumers use Direction + the band levels directly.
Series-based public outputs. Seven outputs cover the full state — six continuous levels and the direction integer.
📦 Download
The full source is available as a free NinjaScript Archive. To install:
- Download the
.zipfile below. - In NinjaTrader 8, go to Tools → Import → NinjaScript Add-On.
- Select the downloaded
.zipfile. - The indicator will appear under Indicators → indTradingView → Volatility-Driven VWAP Structure [Zeiierman] on your chart.
📊 Chart Example

Volatility-Driven VWAP Structure on a 1-minute chart with default settings (VWAP=200, ATR=14, StructMult=1.5, Bands 1× and 2×). The dotted structure-mean line steps in chunks gated by the sigmoid-z volatility step. The AVWAP resets at each reversal, with running std-dev bands at 1× and 2× — the outer band is the canonical mean-reversion entry zone.
The original Pine Script™ code is by Zeiierman and is licensed under the Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0). This NinjaTrader 8 adaptation is by MyDailyTake.com. The use of Zeiierman’s name or adapted code does not imply endorsement by the original author.


