Adaptive Universal Oscillator for TOS

Sesqui

Member
VIP
Here is another adaptive indicator but it uses a different approach.

The universal oscillator has essentially zero lag as an indicator however its implementation in TOS is not adaptive.

The indicator below changes the sensitivity to price moves using the volatility in much the same way as the TOS MovAvgAdaptive indicator. It becomes more sensitive when the price is moving smoothly and less sensitive when the price is volatile.

This is done by calculating the Efficiency Ratio (ER), a measure of relative trend strength, using close price relative to the high-low range. The MovAvgAdaptive gets a variable named ScaledSF. It uses the ScaledSF as an alpha value for an EMA, which is computed using:

EMA = alpha*Price + (1-alpha)*EMA[1].

Since we know that ScaledSF is the alpha value, and since it is known that for an N period SMA, alpha = 2/(N+1), setting ScaledSF = 2/(N+1) and solving for N yields:

N = 2/alpha -1.

This value of N is then used as the period for the Universal Oscillator in order to make it adaptive.

Here is a screenshot. The first indicator on the bottom is the adaptive Universal Oscillator. The second one is the Universal Oscillator that comes with TOS using default settings for comparison. It is evident there are trading opportunities that the adaptive oscillator identifies.

An HMA(34) in yellow was added to each oscillator as well as the zero line for potential use trading cross overs. But it seems that the peaks and valleys of the oscillator identify trading opportunities too.

1758243510714.png


CSS:
# Adaptive UniversalOsc Oscillator for TOS by Sesqui [18SEP2025]
 
# This  indicator changes its sensitivity to price moves using the volatility.
# It becomes more sensitive during periods when the price is moving smoothly in a certain direction and becomes less sensitive when the price is volatile. In much the same way as the TOS MovAvgAdaptive indicator does.
# This is done by calculating the Efficiency Ratio (ER), a measure of relative trend strength. The ER accounts for the location of the close price relative to the high-low range, which uses ER to then getActualEarnings a paramter called, ScaledSF. The AMA uses ScaledSF as an alpha value for an EMA, which is computed using:
# EMA = alpha*Price + (1-alpha)*EMA[1].
# Since we know that ScaledSF is the alpha value, and since it is known that for an N period SMA,
# alpha = 2/(N+1), setting ScaledSF = 2/(N+1) and solving for N yields: N =  2/alpha -1. This
# value of N is then used as the period for the Universal Oscillator in order to make it adaptive
# to the price action, adapting for the current volatilityStdDev in the market.
#

declare lower;

# *** Computes the Efficiency Ratio ***
def effRatioLength = 10;
def fastLength = 2;
def slowLength = 30;

def   ER = AbsValue((close - Lowest(low, effRatioLength)) - (Highest(high, effRatioLength) - close)) / (Highest(high, effRatioLength) - Lowest(low, effRatioLength));

def FastSF = 2 / (fastLength + 1);
def SlowSF = 2 / (slowLength + 1);
def ScaledSF = ER * (FastSF - SlowSF) + SlowSF;

# *** Determines the Period for the Universal Oscillator ***
# for an EMA: alpha = 1/ (L+1); where L is the lag
# Using this expression and solving for Lag:
# L = 2/alpha -1; let ScaledSF = alpha, and solve for the
# value of lag, L, to get: L = 2/scaledSF - 1;
# This lag, L becomes the Bandedge or cutoffLength passed to the
# EhlersSuperSmoother in the Universal Oscillator, making the
# Universal Osciallator adpative

def cutoffLength = 2 / ScaledSF - 1;

# *** Computes the Universal Oscillator in this section ***
def whiteNoise = (close - close[2]) / 2;
def filter = reference EhlersSuperSmootherFilter(price = whiteNoise, "cutoff length" = cutoffLength);
def peak = if IsNaN(filter) then peak[1] * 0.991 else Max(AbsValue(filter), peak[1] * 0.991);

plot UniversalOsc = filter / peak;
UniversalOsc.SetLineWeight(2);

def Diff = UniversalOSC - UniversalOSC[1];
UniversalOsc.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Color.Green else Color.Dark_Green else if Diff < Diff[1] then Color.Red else Color.DARK_RED);

# *** Displays an HMA(34) for cross overs ***
input length = 45;

plot HMA = MovingAverage(AverageType.HULL, UniversalOsc, length );
HMA.AssignValueColor(Color.YELLOW);
HMA.SetLineWeight(2);

plot centerLine = 0;
centerLine.AssignValueColor(Color.GRAY);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
1025 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top