Indicator · Pine Script v5 · On the chart

Adaptive Volatility-Adjusted Momentum Score

by TamaraKGreen· code credited to notprofessorgreen

This indicator builds a momentum score from the rate of change of close, using a lookback that expands or contracts with ATR relative to its standard deviation.

View on GitHub

Repaints

GitHub stars46on the repository
Pine versionv5runs as is
Lines of code140
Settings22inputs
LicenceNone statedfile: MPL-2.0
Last update7 weeks ago4 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

140 lines of Pine Script v5 from Adaptive Volatility Adjusted Momentum Score.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Adaptive Volatility Adjusted Momentum Score.txt
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © notprofessorgreen

//@version=5
indicator("Adaptive Volatility-Adjusted Momentum Score", overlay=true, max_bars_back=5000)

// Inputs
// Indicator Settings
baseLookback = input.int(14, "Base Lookback Period", minval=5, group="Indicator Settings")
volThreshold = input.float(1.5, "Volatility Threshold", step=0.1, group="Indicator Settings")
scaleFactor = input.float(500, "Momentum Scale Factor", minval=100, step=50, group="Indicator Settings")
volumeCap = input.float(3.0, "Volume Weight Cap", minval=1.0, step=0.5, group="Indicator Settings")

// Overbought/Oversold Levels
overboughtLevel = input.float(25, "Overbought Level", minval=5, step=5, group="Overbought/Oversold Levels")
oversoldLevel = input.float(-25, "Oversold Level", maxval=-5, step=5, group="Overbought/Oversold Levels")

// Divergence Detection
lbR = input.int(5, "Pivot Lookback Right", minval=2, group="Divergence Detection")
lbL = input.int(5, "Pivot Lookback Left", minval=2, group="Divergence Detection")
rangeUpper = input.int(60, "Max of Lookback Range", minval=10, group="Divergence Detection")
rangeLower = input.int(5, "Min of Lookback Range", minval=1, group="Divergence Detection")

// Divergence Display
plotBull = input.bool(false, "Plot Regular Bullish", group="Divergence Display")
plotHiddenBull = input.bool(false, "Plot Hidden Bullish", group="Divergence Display")
plotBear = input.bool(false, "Plot Regular Bearish", group="Divergence Display")
plotHiddenBear = input.bool(false, "Plot Hidden Bearish", group="Divergence Display")

// Plotting Options
overlay_main = input.bool(false, "Plot Divergences on Price Chart", group="Plotting Options")
delay_plot_til_closed = input.bool(false, "Delay Plot Until Candle Closes (No Repaint)", group="Plotting Options")

// Alerts
alertZeroCrossUp = input.bool(true, "Alert on Zero Cross Up", group="Alerts")
alertZeroCrossDown = input.bool(true, "Alert on Zero Cross Down", group="Alerts")
alertBullDiv = input.bool(true, "Alert on Regular Bullish Divergence", group="Alerts")
alertHiddenBullDiv = input.bool(false, "Alert on Hidden Bullish Divergence", group="Alerts")
alertBearDiv = input.bool(true, "Alert on Regular Bearish Divergence", group="Alerts")
alertHiddenBearDiv = input.bool(false, "Alert on Hidden Bearish Divergence", group="Alerts")

// Colors
bearColor = color.purple
bullColor = color.teal
hiddenBullColor = color.new(color.teal, 80)
hiddenBearColor = color.new(color.purple, 80)
textColor = color.white
noneColor = color.new(color.white, 100)

// Calculate ATR and its statistics
atr = ta.atr(14)
avgAtr = ta.sma(atr, 14)
atrStd = ta.stdev(atr, 14)

// Safeguard against NaN or zero values
atrStdSafe = na(atrStd) or atrStd == 0 ? 0.0001 : atrStd
avgAtrSafe = na(avgAtr) ? 0.0001 : avgAtr

// Calculate dynamic lookback with bounds
dynamicLookbackRaw = baseLookback * (avgAtrSafe / atrStdSafe)
dynamicLookback = math.max(1, math.min(100, math.round(dynamicLookbackRaw)))

// Calculate momentum (rate of change)
roc = na(dynamicLookback) ? 0 : ta.roc(close, dynamicLookback)

// Normalize momentum by volatility (z-score)
priceStd = ta.stdev(close, dynamicLookback)
priceStdSafe = na(priceStd) or priceStd == 0 ? 0.0001 : priceStd
momentumScore = roc / priceStdSafe * scaleFactor

// Weight by volume
avgVolume = ta.sma(volume, dynamicLookback)
volumeWeight = na(avgVolume) or avgVolume == 0 ? 1.0 : volume / avgVolume
weightedScore = momentumScore * math.min(volumeWeight, volumeCap)

// Detect pivots for divergence
osc = weightedScore
plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true

// Range filter function
_inRange(cond) =>
    bars = ta.barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper

// Non-repainting condition
repaint = not delay_plot_til_closed or barstate.ishistory or barstate.isconfirmed

// Regular Bullish Divergence: Osc Higher Low, Price Lower Low
oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound and repaint

// Hidden Bullish Divergence: Osc Lower Low, Price Higher Low
oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])
priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound and repaint

// Regular Bearish Divergence: Osc Lower High, Price Higher High
oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
bearCond = plotBear and priceHH and oscLH and phFound and repaint

// Hidden Bearish Divergence: Osc Higher High, Price Lower High
oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])
priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)
hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound and repaint

// Plot divergence labels
plot(plFound ? overlay_main ? low[lbR] : osc[lbR] : na, offset=-lbR, title="Regular Bullish", linewidth=2, color=bullCond ? bullColor : noneColor)
plotshape(bullCond ? overlay_main ? low[lbR] : osc[lbR] : na, offset=-lbR, title="Regular Bullish Label", text=" Bull ", style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor)

plot(plFound ? overlay_main ? low[lbR] : osc[lbR] : na, offset=-lbR, title="Hidden Bullish", linewidth=2, color=hiddenBullCond ? hiddenBullColor : noneColor)
plotshape(hiddenBullCond ? overlay_main ? low[lbR] : osc[lbR] : na, offset=-lbR, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=hiddenBullColor, textcolor=textColor)

plot(phFound ? overlay_main ? high[lbR] : osc[lbR] : na, offset=-lbR, title="Regular Bearish", linewidth=2, color=bearCond ? bearColor : noneColor)
plotshape(bearCond ? overlay_main ? high[lbR] : osc[lbR] : na, offset=-lbR, title="Regular Bearish Label", text=" Bear ", style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor)

plot(phFound ? overlay_main ? high[lbR] : osc[lbR] : na, offset=-lbR, title="Hidden Bearish", linewidth=2, color=hiddenBearCond ? hiddenBearColor : noneColor)
plotshape(hiddenBearCond ? overlay_main ? high[lbR] : osc[lbR] : na, offset=-lbR, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=hiddenBearColor, textcolor=textColor)

// Alerts
if ta.crossover(weightedScore, 0) and alertZeroCrossUp
    alert("Zero Line Cross Up Detected", alert.freq_once_per_bar)
if ta.crossunder(weightedScore, 0) and alertZeroCrossDown
    alert("Zero Line Cross Down Detected", alert.freq_once_per_bar)
if bullCond and alertBullDiv
    alert("Regular Bullish Divergence Detected", alert.freq_once_per_bar)
if hiddenBullCond and alertHiddenBullDiv
    alert("Hidden Bullish Divergence Detected", alert.freq_once_per_bar)
if bearCond and alertBearDiv
    alert("Regular Bearish Divergence Detected", alert.freq_once_per_bar)
if hiddenBearCond and alertHiddenBearDiv
    alert("Hidden Bearish Divergence Detected", alert.freq_once_per_bar)

// Plot indicator (non-overlay)
plot(weightedScore, "AVAMS", color=weightedScore > 0 ? color.teal : color.purple, display=display.pane)
hline(overboughtLevel, "Overbought", color=color.purple, linestyle=hline.style_dashed)
hline(oversoldLevel, "Oversold", color=color.teal, linestyle=hline.style_dashed)
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_solid)

Overview

Adaptive Volatility-Adjusted Momentum Score divides that rate of change by price standard deviation, scales the result, and weights it by volume against a capped average. Users set the base lookback, volatility threshold, scale, volume cap, and overbought and oversold levels. Pivot settings mark regular and hidden divergences, with optional price-chart plots and alerts for zero crosses and divergences. It is declared on the price chart. Unless the close-delay option is on, plots can update before the bar closes.

Details

Published by

TamaraKGreen on GitHub

Code credit

notprofessorgreen, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Volatility & bands, Volume, Divergence

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Base Lookback Periodint14baseLookback
Volatility Thresholdfloat1.5volThreshold
Momentum Scale Factorfloat500scaleFactor
Volume Weight Capfloat3.0volumeCap
Overbought Levelfloat25overboughtLevel
Oversold Levelfloat-25oversoldLevel
Pivot Lookback Rightint5lbR
Pivot Lookback Leftint5lbL
Max of Lookback Rangeint60rangeUpper
Min of Lookback Rangeint5rangeLower
Plot Regular BullishboolfalseplotBull
Plot Hidden BullishboolfalseplotHiddenBull
Show all 22 settings
SettingTypeDefaultVariable
Plot Regular BearishboolfalseplotBear
Plot Hidden BearishboolfalseplotHiddenBear
Plot Divergences on Price Chartboolfalseoverlay_main
Delay Plot Until Candle Closes (No Repaint)boolfalsedelay_plot_til_closed
Alert on Zero Cross UpbooltruealertZeroCrossUp
Alert on Zero Cross DownbooltruealertZeroCrossDown
Alert on Regular Bullish DivergencebooltruealertBullDiv
Alert on Hidden Bullish DivergenceboolfalsealertHiddenBullDiv
Alert on Regular Bearish DivergencebooltruealertBearDiv
Alert on Hidden Bearish DivergenceboolfalsealertHiddenBearDiv
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

RSI Div at dVWAP StDev

by cryptorife
75 stars

This indicator marks RSI divergences only when price trades beyond daily VWAP standard-deviation bands. It compares recent RSI extremes with price highs and lows over a lookback window, and it treats a divergence as valid only while RSI stays beyond overbought

Indicator v4 DivergenceOscillators & momentum Repaints
Updated 3 years ago · GPL-3.0 GitHub repository of RSI Div at dVWAP StDev

QPulse

by JasonTeixeira
9 stars

QPulse is a multi-factor indicator that draws in a separate pane to evaluate market momentum, volume flow, and volatility dynamics. It calculates volume delta, a cumulative delta proxy, advanced adaptive ATR, and a hybrid volume-weighted RSI with overbought an

Indicator v6 Oscillators & momentumVolatility & bands
Updated 12 days ago · Custom licence GitHub repository of QPulse

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup
257 stars

This overlay indicator looks for regular price divergences against a set of oscillators, using pivot highs and lows. It compares those pivots with RSI, MACD and its histogram, stochastic, CCI, momentum, OBV, a directional oscillator, volume-weighted MACD, Chai

Indicator v5 DivergenceOscillators & momentum Repaints
Updated 6 weeks ago · None stated GitHub repository of Snag - Best Futures V3

LiqSpikeBounceLong Feb2026

by agutinbaigo28
147 stars

LiqSpikeBounceLong Feb2026 is an indicator designed to identify long bounce entries following high-volume liquidation cascades in bearish market contexts. It checks if price is below an exponential moving average, then detects large single-bar drops exceeding

Indicator v5 Volatility & bandsVolume
Updated 6 weeks ago · MIT GitHub repository of LiqSpikeBounceLong Feb2026

Aroon-based Strategy

by capissimo
114 stars

This indicator overlay generates buy and sell signals based on Aroon extreme levels combined with optional volume or volatility filters. It calculates Aroon Up and Aroon Down lines using localized high and low lookbacks, generating trade entries when Aroon rea

Indicator v4 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Aroon-based Strategy

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers