Indicator · Pine Script v6 · Own pane

Dynamic Momentum Index (DYMI)

by mihakralj

This indicator plots a Dynamic Momentum Index in a separate pane.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code126
Settings6inputs
LicenceApache-2.0
Last update4 weeks ago27 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

126 lines of Pine Script v6 from lib/oscillators/dymi/dymi.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

dymi.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Dynamic Momentum Index (DYMI)", "DYMI", overlay=false)

//@description Dynamic Momentum Index by Tushar Chande and Stanley Kroll (1994).
// A three-stage pipeline that produces a volatility-adaptive RSI:
// Stage 1: Dual circular-buffer StdDev → volatility ratio V = σ_short / σ_long
// Stage 2: dynamic_period = clamp(round(basePeriod / V), minPeriod, maxPeriod)
// Stage 3: Wilder RMA RSI with adaptive alpha = 1 / dynamic_period
// When price volatility is high V > 1, the period shortens → faster response.
// When volatility is low V < 1, the period lengthens → smoother output.

//@function Calculates StdDev over a circular buffer of given period
//@param source Price series
//@param period Window size
//@returns Population standard deviation of the window
stddev_circ(series float source, simple int period) =>
    var array<float> buf = array.new_float(period, na)
    var int head = 0
    var int count = 0
    var float sumV = 0.0
    var float sumSq = 0.0

    float oldest = array.get(buf, head)
    if not na(oldest)
        sumV  -= oldest
        sumSq -= oldest * oldest

    float val = na(source) ? 0.0 : source
    array.set(buf, head, val)
    sumV  += val
    sumSq += val * val
    head := (head + 1) % period
    if count < period
        count += 1

    float mean = sumV / count
    float variance = sumSq / count - mean * mean
    float sd = variance > 0.0 ? math.sqrt(variance) : 0.0
    sd

//@function Calculates Wilder's RMA RSI with warmup compensation and adaptive alpha
//@param source Close price series
//@param dynPeriod Dynamic period (integer, already clamped)
//@returns RSI value in [0, 100]
rsi_wilder(series float source, series int dynPeriod) =>
    var float prevVal  = na
    var float avgGain  = 0.0
    var float avgLoss  = 0.0
    var float e        = 1.0
    var bool  warmup   = true

    float result = 50.0

    if not na(source)
        if na(prevVal)
            prevVal := source
        else
            float alpha  = 1.0 / dynPeriod
            float beta   = 1.0 - alpha
            float change = source - prevVal
            float gain   = change > 0.0 ? change : 0.0
            float loss   = change < 0.0 ? -change : 0.0
            prevVal := source

            avgGain := alpha * gain + beta * avgGain
            avgLoss := alpha * loss + beta * avgLoss

            if warmup
                e *= beta
                float c    = e > 1e-10 ? 1.0 / (1.0 - e) : 1.0
                float aG   = avgGain * c
                float aL   = avgLoss * c
                float total = aG + aL
                result := total != 0.0 ? 100.0 * aG / total : 50.0
                if e <= 1e-10
                    warmup := false
            else
                float total = avgGain + avgLoss
                result := total != 0.0 ? 100.0 * avgGain / total : 50.0

    result

//@function Calculates Dynamic Momentum Index
//@param source Close price series
//@param basePeriod Base RSI period (default 14)
//@param shortPeriod Short StdDev window (default 5)
//@param longPeriod Long StdDev window (default 10)
//@param minPeriod Minimum dynamic period (default 3)
//@param maxPeriod Maximum dynamic period (default 30)
//@returns DYMI value in [0, 100]
//@optimized Uses circular buffers for O(1) StdDev; adaptive Wilder RMA for RSI
dymi(series float source, simple int basePeriod, simple int shortPeriod, simple int longPeriod, simple int minPeriod, simple int maxPeriod) =>
    if basePeriod < 2 or shortPeriod < 2 or longPeriod <= shortPeriod or minPeriod < 2 or maxPeriod < minPeriod
        runtime.error("Invalid DYMI parameters")

    // Stage 1: dual StdDev volatility ratio
    float sdShort = stddev_circ(source, shortPeriod)
    float sdLong  = stddev_circ(source, longPeriod)

    float v = sdLong > 1e-10 ? sdShort / sdLong : 1.0

    // Stage 2: dynamic period
    int rawPeriod  = v > 1e-10 ? math.round(basePeriod / v) : maxPeriod
    int dynPeriod  = math.max(minPeriod, math.min(maxPeriod, rawPeriod))

    // Stage 3: adaptive Wilder RSI
    float result = rsi_wilder(source, dynPeriod)
    math.max(0.0, math.min(100.0, result))

// ---------- Main loop ----------

i_basePeriod  = input.int(14, "Base RSI Period",   minval=2,  maxval=500)
i_shortPeriod = input.int(5,  "Short StdDev Period", minval=2,  maxval=500)
i_longPeriod  = input.int(10, "Long StdDev Period",  minval=2,  maxval=500)
i_minPeriod   = input.int(3,  "Min Period",          minval=2,  maxval=500)
i_maxPeriod   = input.int(30, "Max Period",          minval=2,  maxval=500)
i_source      = input.source(close, "Source")

dymi_val = dymi(i_source, i_basePeriod, i_shortPeriod, i_longPeriod, i_minPeriod, i_maxPeriod)

plot(dymi_val, "DYMI", color=color.yellow, linewidth=2)
hline(70, "Overbought", color=color.gray, linestyle=hline.style_dotted)
hline(50, "Midline",    color=color.gray, linestyle=hline.style_dotted)
hline(30, "Oversold",   color=color.gray, linestyle=hline.style_dotted)

Overview

Dynamic Momentum Index (DYMI) computes a volatility ratio from short and long population standard deviations, then clamps a rounded base period divided by that ratio between minimum and maximum lengths. A Wilder RMA RSI uses an adaptive smoothing factor of one over the dynamic period. Higher volatility shortens the period for a faster response; lower volatility lengthens it. Settings control the base, short, long, min and max periods and the price source. It does not generate trade entries or exits.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

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

SettingTypeDefaultVariable
Base RSI Periodint14i_basePeriod
Short StdDev Periodint5i_shortPeriod
Long StdDev Periodint10i_longPeriod
Min Periodint3i_minPeriod
Max Periodint30i_maxPeriod
Sourcesourceclosei_source
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

TTM Squeeze

by Alorse
330 stars

This indicator plots a TTM Squeeze momentum oscillator in a separate pane. It compares a Bollinger Band offset to a Keltner Channel offset and marks the zero line white when the difference is non-negative and black when the bands are inside the channel. A line

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of TTM Squeeze

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
218 stars

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

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