Links: |TradingView|TradeStation|NinjaTrader|MT4|MT5|Python|
The Ultimate Strength Index (USI), introduced by John Ehlers in late 2024,
is a momentum oscillator designed to replace the Relative Strength Index (RSI) with a symmetric range (-1 to 1) and reduced lag.
It utilizes an "UltimateSmoother" filter to enhance trends and cycles.Â
Python Implementation The following implementation uses pandas and numpy to calculate the USI,
reproducing the logic described by Ehlers.Â
Code: Select all
import pandas as pd
import numpy as np
def calculate_ultimate_smoother(data, length):
"""
Calculates the UltimateSmoother as defined by John Ehlers.
"""
# Initialize with zeros
alpha = 2.0 / (length + 1.0)
ud = np.zeros(len(data))
# Simple smoothing for the first value
ud[0] = data[0]
# Calculate UltimateSmoother iteratively
for i in range(1, len(data)):
ud[i] = (alpha - 0.25 * alpha**2) * data[i] + \
0.5 * alpha**2 * data[i-1] - \
(alpha - 0.75 * alpha**2) * ud[i-1]
return ud
def calculate_usi(df, length=14):
"""
Calculates the Ultimate Strength Index (USI).
"""
close = df['close']
delta = close.diff()
# Calculate Strength Up (SU) and Strength Down (SD)
su = np.where(delta > 0, delta, 0.0)
sd = np.where(delta < 0, -delta, 0.0)
# Apply UltimateSmoother to SU and SD
ult_su = calculate_ultimate_smoother(su, length)
ult_sd = calculate_ultimate_smoother(sd, length)
# Calculate USI
usi = (ult_su - ult_sd) / (ult_su + ult_sd)
return usi
# Example Usage:
# df = pd.read_csv('your_data.csv') # Must have a 'close' column
# df['USI'] = calculate_usi(df, length=14)