TradingView indicator guides

VAMA: EMA Deviation Midpoint and Window Expiry

This VAMA adds the midpoint of the last ten source-minus-EMA deviations to the current EMA. It plots one line. The adjustment is signed and is not the width of a volatility band, a standard deviation, or a probability of support holding. Follow the calculation below before interpreting a price cross.

Inspect the Pine Script

Read the exact adjustment

For a selected source S and length N, compute E = EMA(S, N), then d = S − E. At each bar, take U = highest(d, 10) and L = lowest(d, 10). The output is V = E + (U + L)/2. Each historical deviation uses its own historical EMA; do not subtract today's EMA from every old price.

The default N is 9, so the EMA coefficient is 2/(9+1) = 0.2. That coefficient stays fixed. The ten-bar extrema window is also fixed in this script. Neither ATR, volume, VIX nor standard deviation is read. The names vol_up and vol_down mean maximum and minimum deviations; both can be positive or both negative.

The offset A = (U + L)/2 and span W = U − L answer different questions. Hypothetical extremes +2/−2 give A = 0 and W = 4. Extremes +20/−20 still give A = 0 although W = 40. Thus larger excursions do not necessarily move V farther from E. With U = 5 and L = 2, A = 3.5; no downward deviation is required.

Reproduce a cross while price stays flat

This synthetic example uses N = 3, EMA coefficient 0.5, and the script's fixed ten-bar deviation window. Start with source 100 at bar 1, which seeds the EMA at 100. Set bar 2 to 110, then keep every later source at 100. These are invented inputs, not market observations or a backtest.

BarSourceEMADeviationU / LVAMA
211010555 / 0107.5
3100102.5−2.55 / −2.5103.75
11100100.009766−0.0097665 / −2.5101.259766
12100100.004883−0.004883−0.004883 / −2.598.752441

Bars 2 and 3 use the available initial history; bars 11 and 12 have full ten-bar windows. At bar 12 the old +5 deviation from bar 2 expires. Its replacement maximum is −0.004883, and the line drops below 100. Price crosses above VAMA while price is unchanged and VAMA is falling. A price-above-line condition therefore does not establish a rising line or accelerating price.

For this series, the EMA excess after bar 2 is 5 × 0.5^(bar−2). Use that expression to reproduce the skipped rows. A rolling extreme can disappear abruptly, so a line jump can come from window expiry as well as a new large deviation.

Separate position, slope and events

Source above V means the current deviation d is above the recent deviation midpoint A. It does not say the source increased from the previous bar. A crossover additionally requires the previous source to have been at or below its previous VAMA. Remaining above the line is a state, not a new crossover every bar.

V greater than V three bars ago is a net three-bar rise. It does not require three consecutive rises: hypothetical values 100, 103, 102, 101 satisfy the former and fail the latter. To require three consecutive increases, compare each of the three adjacent pairs explicitly.

The copied script does not calculate any of these conditions, mark pivots, define divergence, create alerts or submit orders. It only plots V. A line is not an executed stop or a protected price zone. An ATR band, pivot rule or strategy would be an additional implementation with separate assumptions.

Inputs, initialization and comparisons

Length is an integer input with default 9 and minimum 1; source defaults to close. The ten-bar extrema lookback is a code constant, not a Settings input. At N = 1 and valid source values, EMA equals source, all deviations are zero and V equals source; strict source/line crosses cannot occur. At other lengths the EMA retains exponentially decaying history beyond N bars.

The code does not enforce a full ten-bar warm-up or a consecutive-valid-data mask. Early extrema use available values, and Pine built-ins have missing-value rules. Compare the same history and source before judging differences. The line updates on the open bar, with no confirmation gate. An external indicator selected as source can add its own data and repainting behavior.

Ten daily bars are ten sessions for a daily stock feed but ten calendar days for a continuous crypto feed. Ten five-minute bars represent fifty minutes of bar durations only when those bars exist; session gaps change elapsed time. No universally best market, timeframe or length follows from this formula.

A fixed-coefficient EMA does not keep a fixed distance from price or have a fixed delay for every event. VAMA adds a nonlinear extrema adjustment to that EMA. HMA combines weighted averages; its definition does not establish a universal lag or whipsaw ranking against VAMA. Test a specified event on identical data rather than assigning unsupported percentages.

Name collisions and a practical comparison

VAMA can also mean Volume Adjusted Moving Average, which uses volume increments. This page's code uses no volume. Match the full name and formula when comparing scripts.

To compare this line with its EMA baseline, expose E, d, U, L and V in a diagnostic version. Check the synthetic expiry example, a constant source, and N = 1. Then define a closed-bar event, entry timing, exits, position size and costs before testing trades. Keep a separate evaluation period. Changing a parameter after seeing a favorable result does not establish better general performance.

Platform references: EMA definition, rolling extrema, and realtime and external-source behavior. The worked values are independently calculated from the source below.

Pine Script v6: implementation and limits

Copy this complete example into Pine Editor. It exposes length and source, keeps the deviation window at ten, and plots a blue line. It has no stop orders, signal labels, alert conditions or bar-close filter. Compare values on the same chart and history; syntax success alone does not verify trading behavior.

Pine Script v6
//@version=6
indicator(title="Volatility Adjusted Moving Average (VAMA)", overlay=true)

length = input.int(9, "VAMA Length", minval=1)
src = input.source(close, "Source")

volatility_lookback = 10
mid = ta.ema(src, length)
dev = src - mid
vol_up = ta.highest(dev, volatility_lookback)
vol_down = ta.lowest(dev, volatility_lookback)
vama = mid + math.avg(vol_up, vol_down)

plot(vama, "VAMA", color.blue, 2)
Existing indicator chart preview
Existing visual preview. Verify exact values against the source; the image is not a performance result.

Specify a checkable adaptation in Pineify

Pineify's Visual Editor exposes VAMA source and length inputs with one VAMA output; the helper uses the same fixed ten-bar deviation window. For a diagnostic or alert version, give the AI Coding Agent this exact formula, request the intermediate series and specify closed-bar timing. Review the generated code, run a syntax check, and compare the synthetic sequence in TradingView. Product access depends on the current plan; this guide does not establish free unlimited use.

Open Pine Script AI Coding Agent

Educational indicator analysis. No measured trading performance is established here. Syntax validation does not prove formula equivalence, execution assumptions or profitability.

Implementation questions

This implementation plots one line. It adds the signed midpoint of recent deviation extremes to an EMA. Symmetric extremes can widen while their midpoint stays zero, so it does not automatically widen a zone.

Yes. An old extreme leaving the ten-bar window can move the line below unchanged price. The worked N=3 example demonstrates this; position and slope are separate observations.

No. This code uses one EMA and the highest and lowest source-minus-EMA deviations over ten bars. It does not calculate standard deviation.

On valid data the EMA equals the source, deviations are zero and VAMA equals the source. There is no strict source/VAMA crossover.

No. It has source and length inputs and a single live plot. A confirmed crossover alert or strategy needs additional code and validation.

No. The same abbreviation is used for a volume-increment average. This volatility adjusted implementation never reads volume.