Volatility Adjusted Moving Average Pine Script — Complete TradingView Guide
The Volatility Adjusted Moving Average (VAMA) is a trend-following overlay indicator for Pine Script v6 that enhances a standard EMA by self-correcting for recent price volatility. VAMA computes an EMA baseline, measures how far price deviates above and below that baseline over a 10-bar volatility window, and shifts the moving average by the average of those extremes — making it more adaptive to volatility regimes than a plain EMA. The default configuration uses source = close, length = 9 and a hardcoded volatility lookback of 10 bars. VAMA is most effective in trending markets across stocks, crypto, and forex on timeframes from 15 minutes to the daily chart. This guide covers the complete Pine Script v6 implementation, all parameters with recommended ranges, three concrete VAMA trading strategies with specific entry and exit conditions, and a five-step guide to generating VAMA scripts instantly with Pineify.
What Is the Volatility Adjusted Moving Average?
The Volatility Adjusted Moving Average (VAMA) is a trend-following overlay indicator that shifts an EMA by the midpoint of recent price deviations, used to track trend direction with automatic adaptation to changes in market volatility. Unlike the Exponential Moving Average, which applies only exponential weighting to price history, VAMA adds a second layer: it measures how much price oscillates above and below the EMA baseline and corrects the average accordingly — pulling the line toward where price actually clusters during volatile conditions.
VAMA builds on the concept of volatility-aware moving averages that gained traction in the late 1990s and 2000s as algorithmic traders sought alternatives to fixed-weight averages. The core insight is that a moving average tuned for low volatility lags too far behind during high-volatility periods, while one tuned for high volatility whipsaws in calm markets. VAMA resolves this by dynamically embedding a volatility correction term directly into the average calculation rather than adjusting the length parameter.
Core formula: VAMA = EMA(source, len) + avg(highest(dev, 10), lowest(dev, 10)), where dev = source − EMA(source, len). Each variable explained:
source— the price series, typically closelen— EMA lookback period, default 9 barsdev— per-bar deviation of price from the EMA baselinevol_up— highest deviation over the last 10 bars (captures upside extremes)vol_down— lowest deviation over the last 10 bars (captures downside extremes)math.avg(vol_up, vol_down)— the midpoint correction term added back to the EMA
VAMA applies to all liquid asset classes: stocks, crypto, forex, and futures. It is most effective in trending markets where volatility is elevated and direction is clear. Best timeframes are 15-minute to Daily charts — shorter timeframes (1m, 5m) produce too much noise for the 10-bar deviation window to be meaningful, while weekly and monthly charts see little benefit over a standard EMA.
Best Markets
Stocks · Crypto · Forex · Futures
Best Timeframes
15m, 1H, 4H, Daily
Overlay
Yes — plots directly on price chart
VAMA Pine Script Code Example
The code below defines the complete VAMA calculation function and plots a 9-period Volatility Adjusted Moving Average as a blue line overlaid on the price chart using Pine Script v6. To add it to TradingView, open the Pine Script editor with Alt+P, paste the code, and click Add to chart. Change the 9 in p_ta_vama(close, 9) to adjust the EMA length to your trading style.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//@version=6
indicator(title="Volatility Adjusted Moving Average", overlay=true, max_labels_count=500)
// VAMA — adjusts EMA by the midpoint of recent price deviations
p_ta_vama(series float source, simple int len) =>
volatility_lookback = 10
mid = ta.ema(source, len)
dev = source - mid
vol_up = ta.highest(dev, volatility_lookback)
vol_down = ta.lowest(dev, volatility_lookback)
vama = mid + math.avg(vol_up, vol_down)
vama
p_ind_1 = p_ta_vama(close, 9) // VAMA with length 9
// Plot the VAMA line on the price chart
plot(p_ind_1, "VAMA", color.rgb(41, 98, 255, 0), 1)Chart Preview

VAMA Parameters
| Parameter | Default Value | Description | Recommended Range |
|---|---|---|---|
| source | close | The price series used as input for the EMA baseline and deviation calculation. Typically close, but can be hl2, hlc3, or any numeric series. | Any numeric series |
| len | 9 | Number of bars for the EMA baseline. Controls the smoothing multiplier k = 2 ÷ (len + 1). Smaller values react faster to price changes; larger values produce a smoother, slower-reacting VAMA line. | 5–50 depending on style |
| volatility_lookback | 10 | Number of bars used to measure the highest and lowest deviation from the EMA. Hardcoded in the reference implementation. Shorter lookbacks make VAMA more volatile-sensitive; longer lookbacks smooth the correction term. | 5–20 (advanced tuning) |
Tuning Guide by Trading Style
- Scalping (5m–15m charts): len 5–9 — fast EMA base with tight volatility correction for quick momentum signals
- Day trading (1H charts): len 9–14 — standard short-term VAMA configuration used by intraday traders
- Swing trading (4H–Daily charts): len 20–34 — medium-term trend tracking with meaningful volatility adjustment
- Position trading (Daily–Weekly charts): len 50 — slow VAMA as a macro trend reference; volatility correction adds little at this scale
VAMA Trading Strategies
The VAMA is most effective as a volatility-aware trend filter and dynamic support/resistance reference. Below are three concrete strategies with specific entry and exit conditions.
Strategy 1 — VAMA Price Crossover (Trend Momentum)
Market environment: trending markets · Best timeframe: 1H, 4H
The simplest VAMA strategy enters long when price crosses above the VAMA line and exits when price crosses back below. The volatility adjustment reduces the number of false crossovers compared to a plain EMA of the same length. Confirm with ADX(14) above 20 to avoid entering in sideways markets.
- Calculate VAMA:
vama = p_ta_vama(close, 9) - Calculate trend strength filter:
adx = ta.adx(14) - Long entry:
ta.crossover(close, vama)AND adx > 20 - Filter: only enter longs when close is above VAMA(20) to confirm the higher-timeframe trend
- Exit:
ta.crossunder(close, vama)— price crosses back below VAMA
Strategy 2 — Dual VAMA Ribbon (Fast/Slow Crossover)
Market environment: trending bull and bear markets · Best timeframe: 4H, Daily
Using two VAMA lines (fast length 9, slow length 21) creates a volatility-adjusted ribbon. When the fast VAMA crosses above the slow VAMA, it signals bullish momentum with less lag than an equivalent EMA cross. The volatility correction in both lines prevents premature crossover signals during high-volatility consolidations.
- Calculate fast VAMA:
vama_fast = p_ta_vama(close, 9) - Calculate slow VAMA:
vama_slow = p_ta_vama(close, 21) - Long entry:
ta.crossover(vama_fast, vama_slow)— fast crosses above slow - Confirm: close must be above both VAMA lines at entry to avoid buying into a bearish consolidation
- Exit:
ta.crossunder(vama_fast, vama_slow)— fast drops below slow
Strategy 3 — VAMA + ATR Volatility Stop (Trend Following)
Market environment: strongly trending markets · Best timeframe: Daily
Pairing VAMA with ATR(14) creates a complete trend-following system: VAMA identifies trend direction while ATR sets a dynamic stop distance that expands in volatile conditions and contracts in calm periods, reducing premature stop-outs.
- Calculate VAMA trend line:
vama = p_ta_vama(close, 9) - Calculate stop distance:
atr14 = ta.atr(14) - Long entry: close crosses above vama AND close > vama from the prior bar
- Stop loss: set at vama − (1.5 × atr14) — dynamic stop that widens during volatile expansions
- Exit: close falls below vama OR trailing stop is hit; do not hold through VAMA crossunder
Disclaimer: The strategies above are for educational purposes only and do not constitute investment advice. Past performance does not guarantee future results. Always apply proper risk management and position sizing.
How to Generate the VAMA Indicator in Pineify
- 1
Open Pineify
Go to pineify.app and sign in — a free account is sufficient to generate VAMA indicators in Pine Script v6.
- 2
Click "New Indicator"
Select "Indicator" as the script type from the creation menu on the dashboard.
- 3
Describe the VAMA you want
Type a prompt such as: "Plot a Volatility Adjusted Moving Average with length 9 on close prices as a blue overlay line." Pineify's AI Coding Agent generates the complete Pine Script v6 code including the VAMA formula in seconds.
- 4
Copy to TradingView
Click "Copy to TradingView" to copy the generated code, then open the TradingView Pine Script editor (Alt+P), paste the code, and click "Add to chart".
- 5
Adjust the length parameter
Modify the EMA length argument in p_ta_vama(close, 9) — for example change 9 to 14 for 1H charts or 21 for swing trading on 4H — to match your trading style without rewriting the formula.
Frequently Asked Questions
Related Pine Script Indicators
Build Your VAMA Indicator in Seconds
Skip the manual coding. Pineify's AI Coding Agent generates complete, ready-to-use Pine Script indicators — including the full Volatility Adjusted Moving Average formula with ATR-based stop strategies — instantly for free.
Try Pineify Free