thanks. There seems to be a difference between "Super Smoother" and "Ultimate Smoother". I took the coefficients from a couple of contributors, see second link (top of code). So I added the IIR version to the code
// https://www.tradingview.com/script/4Plc7Zjk-TASC-2024-05-Ultimate-Channels-and-Ultimate-Bands/
// https://www.traders.com/Documentation/FEEDbk_docs/2024/05/TradersTips.html
PI = 3.14159265358979;
length = Param( "Length", 20, 1, 50, 1 );
lengthSTR = Param( "STR Length", 20, 1, 50, 1 );
multiplier = Param( "Width Multiplier", 1, 0.1, 50, 0.1 );
plist = ParamList( "Select", "Bands|Channel", 1 );
meth = ParamList( "Method", "fLoop|fIIR", 1 );
// global variables
mid = str = sd = bup = bdn = Null;
function UltimateSmoother_loop( src, period )
{
a1 = exp( ( -sqrt( 2 ) * PI ) / period );
c2 = 2 * a1 * cos( ( sqrt( 2 ) * PI ) / period );
c3 = -a1 * a1;
c1 = ( 1 + c2 - c3 ) / 4;
us = src;
for( i = 4; i < BarCount; i++ )
{
us[i] = ( 1 - c1 ) * src[i]
+ ( 2 * c1 - c2 ) * src[i - 1]
- ( c1 + c3 ) * src[i - 2]
+ c2 * us[i - 1]
+ c3 * us[i - 2];
}
return us;
}
function UltimateSmoother_IIR( src, period )
{
a1 = exp( ( -sqrt( 2 ) * PI ) / period );
c2 = 2 * a1 * cos( ( sqrt( 2 ) * PI ) / period );
c3 = -a1 * a1;
c1 = ( 1 + c2 - c3 ) / 4;
// input for IIR
b0 = ( 1 - c1 );
b1 = ( 2 * c1 - c2 );
b2 = -( c1 + c3 );
a1 = c2;
a2 = c3;
us = IIR( src, b0, a1, b1, a2, b2 );
return us;
}
function UltimateChannel( length, lengthSTR, mult )
{
if( meth == "fLoop" )
{
mid = UltimateSmoother_loop( Close, length );
str = UltimateSmoother_loop( ATR( 1 ), lengthSTR ) * mult;
}
if( meth == "fIIR" )
{
mid = UltimateSmoother_IIR( Close, length );
str = UltimateSmoother_IIR( ATR( 1 ), lengthSTR ) * mult;
}
}
function UltimateBands( src, length, mult )
{
if( meth == "fLoop" )
{
mid = UltimateSmoother_loop( src, length );
}
if( meth == "fIIR" )
{
mid = UltimateSmoother_IIR( src, length );
}
sd = StDev( src - mid, length ) * mult;
}
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 0 );
if( plist == "Channel" )
{
UltimateChannel( length, lengthSTR, multiplier );
Plot( bup = mid + str, "channel top", colorAqua, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
Plot( bdn = mid - str, "channel bot", colorAqua, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
}
if( plist == "Bands" )
{
UltimateBands( close, length, multiplier );
Plot( bup = mid + sd, "bands top", colorAqua, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
Plot( bdn = mid - sd, "bands bot", colorAqua, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
}