Indicator · Pine Script v6 · On the chart

Ehlers Ultimate Bands (UBANDS)

by mihakralj

This indicator plots Ehlers Ultimate Bands on the price chart.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code54
Settings3inputs
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

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

ubands.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
// Ultimate Bands logic based on work by John F. Ehlers (c) 2024
indicator("Ehlers Ultimate Bands (UBANDS)", "UBANDS", overlay=true)

//@function Calculates Ultimate Bands
//@param src Source series for the bands
//@param length Lookback period for the Ehlers Ultrasmooth Filter and RMS
//@param mult RMS multiplier for band width
//@returns tuple [upperBand, middleBand, lowerBand]
ubands(series float src, simple int length, simple float mult) =>
    var float usf_state = na, var float c1=0.0, var float c2=0.0, var float c3=0.0, var int prev_len = 0
    if prev_len != length or na(c1)
        float arg = (math.sqrt(2)*math.pi)/math.max(1,float(length))
        float exp_arg = math.exp(-arg)
        c2 := 2*exp_arg*math.cos(arg)
        c3 := -exp_arg*exp_arg
        c1 := (1+c2-c3)/4.0
        prev_len := length
        usf_state := na
    float s = nz(src,src[1]), s1 = nz(src[1],s), s2 = nz(src[2],s1)
    float current_usf = na(usf_state) or na(usf_state[1]) or na(usf_state[2]) ? s :
      (1-c1)*s + (2*c1-c2)*s1 - (c1+c3)*s2 + c2*nz(usf_state[1],s1) + c3*nz(usf_state[2],s2)
    usf_state := current_usf
    float smooth = usf_state
    series float residuals = src - smooth
    float rms = 0.0
    if length > 0
        float sumSq_r = 0.0, int count_r = 0
        for i = 0 to length - 1
            float val_r = residuals[i]
            if not na(val_r)
                sumSq_r += val_r*val_r
                count_r += 1
        if count_r > 0
            rms := math.sqrt(sumSq_r/count_r)
    [smooth + mult*rms, smooth, smooth - mult*rms]

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

// Inputs
i_source = input.source(close, "Source")
i_length = input.int(20, "Length", minval=1, tooltip="Lookback period for smoothing and RMS calculation.")
i_mult = input.float(1.0, "RMS Multiplier", minval=0.01, tooltip="Band width as multiple of RMS value.")

// Calculation
[upperBand, middleBand, lowerBand] = ubands(i_source, i_length, i_mult)

// Plot
plot(middleBand, "Middle Band", color=color.yellow, linewidth=2)
p1 = plot(upperBand, "Upper Band", color=color.yellow, linewidth=2)
p2 = plot(lowerBand, "Lower Band", color=color.yellow, linewidth=2)
fill(p1, p2, color=color.new(color.blue, 90), title="Band Fill")

Overview

Ehlers Ultimate Bands (UBANDS) smooths the selected source with an Ehlers ultrasmooth filter, measures the root-mean-square of residuals over the lookback, and draws upper and lower bands as that smooth line plus or minus the RMS times a multiplier. Length sets both the filter and the RMS window, and the RMS multiplier sets band width. A translucent fill sits between the outer bands. It does not generate trade signals or exits.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

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
Sourcesourceclosei_source
Lengthint20i_length
RMS Multiplierfloat1.0i_mult
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

Chandelier Exit

by everget
948 stars

This indicator plots an ATR-based Chandelier Exit trailing stop on the price chart. It tracks a long stop under recent highs and a short stop above recent lows, then switches direction when price crosses the opposite stop. Buy and sell labels mark those flips.

Indicator v6 Volatility & bandsTrend Repaints
Updated 10 days ago · GPL-3.0 GitHub repository of Chandelier Exit

ICT Liquidity Void Fill

by ArunKBhaskar
575 stars

This overlay indicator marks ICT liquidity void fills on the price chart and can show long and short signals. It places a Fibonacci level inside a displacement candle, defaulting to the midpoint, and draws lines in a chosen style. Optional filters limit the fi

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Void Fill

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon

Algo AVT

by ricardosantos79
261 stars

This indicator calculates an outlier-filtered moving average based on statistical filtering concepts. It stores close prices in a rolling array over a user-defined length, calculates the mean and standard deviation, and excludes values falling within a specifi

Indicator v4 Moving averagesVolatility & bands
Updated 4 years ago · None stated GitHub repository of Algo AVT

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