Indicator · Pine Script v6 · On the chart

Ultimate Channel (UCHANNEL)

by mihakralj

The Ultimate Channel calculates an ultra-smoothed centerline alongside upper and lower volatility bands directly on the main price chart.

View on GitHub

GitHub stars47on the repository
Pine versionv6current
Lines of code67
Settings6inputs
LicenceMIT
Last update8 months ago28 Feb 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

67 lines of Pine Script v6 from indicators/channels/uchannel.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

uchannel.pine
// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Ultimate Channel (UCHANNEL)", "UCHANNEL", overlay=true)

//@function Calculates Ultimate Channel
//@param src Source series for the centerline (typically close)
//@param high_src Source series for high prices
//@param low_src Source series for low prices
//@param strLength Lookback period for smoothing the True Range
//@param length Lookback period for smoothing the centerline
//@param numSTRs Multiplier for the Smoothed True Range to define channel width
//@returns tuple [upperChannel, middleChannel, lowerChannel]
uchannel(series float src_centerline, series float high_src, series float low_src, simple int strLength_param, simple int length_param, simple float numSTRs_param) =>
    if strLength_param <= 0 or length_param <= 0 or numSTRs_param <= 0
        runtime.error("strLength, numSTR and length must be greater than 0")
    var float usf_s = na, var float usf_c = na
    var float c1_s = 0.0, var float c2_s = 0.0, var float c3_s = 0.0
    var float c1_c = 0.0, var float c2_c = 0.0, var float c3_c = 0.0
    var int prev_sLen = 0, var int prev_cLen = 0
    float th = math.max(high_src, nz(src_centerline[1], high_src))
    float tl = math.min(low_src, nz(src_centerline[1], low_src))
    series float tr_s = th - tl // true_range_series
    if prev_sLen != strLength_param or na(c1_s)
        float arg = (math.sqrt(2)*math.pi)/float(strLength_param)
        float exp_arg = math.exp(-arg)
        c2_s := 2*exp_arg*math.cos(arg)
        c3_s := -exp_arg*exp_arg
        c1_s := (1+c2_s-c3_s)/4.0
        prev_sLen := strLength_param
        usf_s := na
    float s_str = nz(tr_s, tr_s[1]), s1_str = nz(tr_s[1], s_str), s2_str = nz(tr_s[2], s1_str)
    float cur_usf_s = na(usf_s) or na(usf_s[1]) or na(usf_s[2]) ? s_str : (1-c1_s)*s_str + (2*c1_s-c2_s)*s1_str - (c1_s+c3_s)*s2_str + c2_s*nz(usf_s[1],s1_str) + c3_s*nz(usf_s[2],s2_str)
    usf_s := cur_usf_s
    float str_val = usf_s
    if prev_cLen != length_param or na(c1_c)
        float arg = (math.sqrt(2)*math.pi)/float(length_param)
        float exp_arg = math.exp(-arg)
        c2_c := 2*exp_arg*math.cos(arg)
        c3_c := -exp_arg*exp_arg
        c1_c := (1+c2_c-c3_c)/4.0
        prev_cLen := length_param
        usf_c := na
    float s_cen = nz(src_centerline,src_centerline[1]), s1_cen = nz(src_centerline[1],s_cen), s2_cen = nz(src_centerline[2],s1_cen)
    float cur_usf_c = na(usf_c) or na(usf_c[1]) or na(usf_c[2]) ? s_cen : (1-c1_c)*s_cen + (2*c1_c-c2_c)*s1_cen - (c1_c+c3_c)*s2_cen + c2_c*nz(usf_c[1],s1_cen) + c3_c*nz(usf_c[2],s2_cen)
    usf_c := cur_usf_c
    float centerline = usf_c
    [centerline + numSTRs_param*str_val, centerline, centerline - numSTRs_param*str_val]

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

// Inputs
i_source = input.source(close, "Source for Centerline")
i_high = input.source(high, "Source for High")
i_low = input.source(low, "Source for Low")
i_strLength = input.int(20, "STR Length", minval=1, tooltip="Lookback period for smoothing the True Range.")
i_length = input.int(20, "Centerline Length", minval=1, tooltip="Lookback period for smoothing the centerline (close price).")
i_numSTRs = input.float(1.0, "STR Multiplier", minval=0.01, tooltip="Number of Smoothed True Ranges for channel width.")

// Calculation
[upperCh, middleCh, lowerCh] = uchannel(i_source, i_high, i_low, i_strLength, i_length, i_numSTRs)

// Plot
plot(middleCh, "Middle Channel", color=color.yellow, linewidth=2)
p_upper = plot(upperCh, "Upper Channel", color=color.yellow, linewidth=2)
p_lower = plot(lowerCh, "Lower Channel", color=color.yellow, linewidth=2)
fill(p_upper, p_lower, color=color.new(color.blue, 90), title="Channel Fill")

Overview

Ultimate Channel (UCHANNEL) processes true range values through an advanced infinite impulse response smoothing filter to establish dynamic channel width, scaled by a user-defined multiplier. Traders can adjust the lookback periods for both the centerline smoothing and the true range calculation, as well as customize input price sources. The indicator plots three lines overlaying price movements to help identify trend direction and volatility boundaries without generating direct trade signals.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volatility & bands, Trend, Support & resistance

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

pinescriptpinescript-indicatorstechnical-analysistradingview-indicators

Settings

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

SettingTypeDefaultVariable
Source for Centerlinesourceclosei_source
Source for Highsourcehighi_high
Source for Lowsourcelowi_low
STR Lengthint20i_strLength
Centerline Lengthint20i_length
STR Multiplierfloat1.0i_numSTRs
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

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

Dynamic Linear Regression

by TradersPost
218 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

ATR Trailing Stop

by mihakralj
99 stars

Calculates an ATR-based trailing stop overlaid on the price chart to assist with trend identification and stop placement. Using a specified ATR period and multiplier, it projects upper and lower bounds around the closing price. The stop line ratchets up during

Indicator v5 TrendVolatility & bands
Updated 4 weeks ago · Apache-2.0 GitHub repository of ATR Trailing Stop

Moon Dev Lunar Sniper

by moondevonyt
92 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev Lunar Sniper

SuperTrend & Pivots

by dcaoyuan
55 stars

This overlay indicator plots a SuperTrend line on the price chart using a fixed ATR length of 10 and a factor of 3. When the trend direction is up it draws a green line and a light green fill toward the candle midpoint; when down it draws a red line and a ligh

Indicator v6 TrendVolatility & bands
Updated 6 months ago · Apache-2.0 GitHub repository of SuperTrend & Pivots

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