JurikJMA

661
Library "JurikJMA"

jma(src, length, phase)
  calculates the Jurik Moving Average (JMA).
  Parameters:
    src (float): source price series.
    length (simple int): base smoothing length.
    phase (simple float): lag / overshoot trade-off in [-100, 100].
  Returns: JMA value returns na during the first 30 valid bars (warm-up) and on bars where src is na.

◈ OVERVIEW
This library provides a complete Pine Script v6 implementation of the Jurik Moving Average (JMA), based on Igor Durkin's full reverse-engineered algorithm (ported to MQL4 as "JJMA" by Nikolay Kositsin). Unlike simplified versions that use a fixed "power" input, this implementation keeps the adaptive core that defines JMA: the smoothing speed is recalculated on every bar from the market's relative volatility.

◇ HOW IT WORKS
• 30-bar bootstrap for accurate state initialization
• Adaptive Jurik bands tracking price
• Relative volatility: a 10-bar mean of band distance, normalized by a trimmed mean from a sorted 128-sample history
• Adaptive power derived from that volatility (faster in strong moves, smoother in quiet markets)
• Three-stage filter: adaptive EMA → phase-weighted detrender → 2nd-order Kalman-style smoother

All algorithm constants are kept as in the original reconstruction. Since the original Jurik code is proprietary, exact equivalence cannot be formally proven, but this is the most complete public reconstruction available.

◇ FUNCTION
jma(src, length, phase) → float
• src (series float): source series. Bars with na values are skipped safely.
• length (simple int): base smoothing length. Values below 2 are treated as 2.
• phase (simple float): -100 to +100. Higher = faster with more overshoot, 0 = balanced, lower = smoother with more lag. Out-of-range values are clamped.
Returns na during the first 30 valid bars (warm-up).

◈ USAGE
Pine Script®


◇ NOTES
• Call jma() once per bar in the global scope. Do not call it inside if blocks, loops or ternary expressions, because it keeps internal state between bars.
• Each call has its own independent state, so multiple JMAs with different settings can be used in the same script.
• Allow at least 128 bars of history for the volatility model to fully stabilize.

◇ CREDITS
JMA concept by Mark Jurik (Jurik Research). Algorithm reconstruction by Igor Durkin, MQL4 port by Nikolay Kositsin.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.