Indicator · Pine Script v6 · Own pane

Ultimate Oscillator

by mihakralj

This indicator calculates the Ultimate Oscillator from buying pressure and true range over three lookback windows.

View on GitHub

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

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

ultosc.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Ultimate Oscillator (ULTOSC)", "ULTOSC", overlay=false)

//@function Calculates the Ultimate Oscillator using three weighted time periods
//@param fastPeriod Short-term period for momentum calculation
//@param mediumPeriod Medium-term period for momentum calculation
//@param slowPeriod Long-term period for momentum calculation
//@param fastWeight Weight applied to fast period calculation
//@param mediumWeight Weight applied to medium period calculation
//@param slowWeight Weight applied to slow period calculation
//@returns Ultimate Oscillator value (0-100 scale)
ultosc(simple int fastPeriod, simple int mediumPeriod, simple int slowPeriod, simple float fastWeight, simple float mediumWeight, simple float slowWeight) =>
    if fastPeriod <= 0 or mediumPeriod <= 0 or slowPeriod <= 0
        runtime.error("All periods must be positive")
    if fastPeriod >= mediumPeriod or mediumPeriod >= slowPeriod
        runtime.error("Periods must be in ascending order: fast < medium < slow")
    if fastWeight <= 0 or mediumWeight <= 0 or slowWeight <= 0
        runtime.error("All weights must be positive")
    prev_close = nz(close[1], close)
    true_low = math.min(low, prev_close)
    true_high = math.max(high, prev_close)
    buying_pressure = close - true_low
    true_range = true_high - true_low
    var array<float> bp_fast_buffer = array.new_float(fastPeriod, na)
    var array<float> tr_fast_buffer = array.new_float(fastPeriod, na)
    var array<float> bp_medium_buffer = array.new_float(mediumPeriod, na)
    var array<float> tr_medium_buffer = array.new_float(mediumPeriod, na)
    var array<float> bp_slow_buffer = array.new_float(slowPeriod, na)
    var array<float> tr_slow_buffer = array.new_float(slowPeriod, na)
    var int fast_head = 0, var int medium_head = 0, var int slow_head = 0
    var float bp_fast_sum = 0.0, var float tr_fast_sum = 0.0
    var float bp_medium_sum = 0.0, var float tr_medium_sum = 0.0
    var float bp_slow_sum = 0.0, var float tr_slow_sum = 0.0
    var int fast_count = 0, var int medium_count = 0, var int slow_count = 0
    bp_fast_oldest = array.get(bp_fast_buffer, fast_head)
    tr_fast_oldest = array.get(tr_fast_buffer, fast_head)
    bp_fast_sum := not na(bp_fast_oldest) ? bp_fast_sum - bp_fast_oldest : bp_fast_sum
    tr_fast_sum := not na(tr_fast_oldest) ? tr_fast_sum - tr_fast_oldest : tr_fast_sum
    fast_count := not na(bp_fast_oldest) ? fast_count - 1 : fast_count
    bp_fast_sum := not na(buying_pressure) ? bp_fast_sum + buying_pressure : bp_fast_sum
    tr_fast_sum := not na(true_range) ? tr_fast_sum + true_range : tr_fast_sum
    fast_count := not na(buying_pressure) ? fast_count + 1 : fast_count
    array.set(bp_fast_buffer, fast_head, buying_pressure)
    array.set(tr_fast_buffer, fast_head, true_range)
    fast_head := (fast_head + 1) % fastPeriod
    bp_medium_oldest = array.get(bp_medium_buffer, medium_head)
    tr_medium_oldest = array.get(tr_medium_buffer, medium_head)
    bp_medium_sum := not na(bp_medium_oldest) ? bp_medium_sum - bp_medium_oldest : bp_medium_sum
    tr_medium_sum := not na(tr_medium_oldest) ? tr_medium_sum - tr_medium_oldest : tr_medium_sum
    medium_count := not na(bp_medium_oldest) ? medium_count - 1 : medium_count
    bp_medium_sum := not na(buying_pressure) ? bp_medium_sum + buying_pressure : bp_medium_sum
    tr_medium_sum := not na(true_range) ? tr_medium_sum + true_range : tr_medium_sum
    medium_count := not na(buying_pressure) ? medium_count + 1 : medium_count
    array.set(bp_medium_buffer, medium_head, buying_pressure)
    array.set(tr_medium_buffer, medium_head, true_range)
    medium_head := (medium_head + 1) % mediumPeriod
    bp_slow_oldest = array.get(bp_slow_buffer, slow_head)
    tr_slow_oldest = array.get(tr_slow_buffer, slow_head)
    bp_slow_sum := not na(bp_slow_oldest) ? bp_slow_sum - bp_slow_oldest : bp_slow_sum
    tr_slow_sum := not na(tr_slow_oldest) ? tr_slow_sum - tr_slow_oldest : tr_slow_sum
    slow_count := not na(bp_slow_oldest) ? slow_count - 1 : slow_count
    bp_slow_sum := not na(buying_pressure) ? bp_slow_sum + buying_pressure : bp_slow_sum
    tr_slow_sum := not na(true_range) ? tr_slow_sum + true_range : tr_slow_sum
    slow_count := not na(buying_pressure) ? slow_count + 1 : slow_count
    array.set(bp_slow_buffer, slow_head, buying_pressure)
    array.set(tr_slow_buffer, slow_head, true_range)
    slow_head := (slow_head + 1) % slowPeriod
    raw_fast = tr_fast_sum > 0 and fast_count >= fastPeriod ? 100 * bp_fast_sum / tr_fast_sum : 0
    raw_medium = tr_medium_sum > 0 and medium_count >= mediumPeriod ? 100 * bp_medium_sum / tr_medium_sum : 0
    raw_slow = tr_slow_sum > 0 and slow_count >= slowPeriod ? 100 * bp_slow_sum / tr_slow_sum : 0
    total_weight = fastWeight + mediumWeight + slowWeight
    weighted_sum = (raw_fast * fastWeight) + (raw_medium * mediumWeight) + (raw_slow * slowWeight)
    slow_count >= slowPeriod ? weighted_sum / total_weight : na

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

// Inputs
i_fastPeriod = input.int(7, "Fast Period", minval=1, maxval=50, tooltip="Short-term period for momentum calculation")
i_mediumPeriod = input.int(14, "Medium Period", minval=1, maxval=100, tooltip="Medium-term period for momentum calculation")
i_slowPeriod = input.int(28, "Slow Period", minval=1, maxval=200, tooltip="Long-term period for momentum calculation")
i_fastWeight = input.float(4.0, "Fast Weight", minval=0.1, maxval=10.0, step=0.1, tooltip="Weight applied to fast period calculation")
i_mediumWeight = input.float(2.0, "Medium Weight", minval=0.1, maxval=10.0, step=0.1, tooltip="Weight applied to medium period calculation")
i_slowWeight = input.float(1.0, "Slow Weight", minval=0.1, maxval=10.0, step=0.1, tooltip="Weight applied to slow period calculation")

// Calculation
ultosc_value = ultosc(i_fastPeriod, i_mediumPeriod, i_slowPeriod, i_fastWeight, i_mediumWeight, i_slowWeight)

// Plots
plot(ultosc_value, "Ultimate Oscillator", color=color.yellow, linewidth=2)

Overview

Ultimate Oscillator weights the fast, medium, and slow averages, defaulting to periods of 7, 14, and 28 with weights of 4, 2, and 1, then plots the result on a 0 to 100 scale in a separate pane. Inputs change each window length and its relative weight. Periods must stay positive and strictly ascending, and weights must stay positive. It does not mark entries, exits, or stops.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum

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
Fast Periodint7i_fastPeriod
Medium Periodint14i_mediumPeriod
Slow Periodint28i_slowPeriod
Fast Weightfloat4.0i_fastWeight
Medium Weightfloat2.0i_mediumWeight
Slow Weightfloat1.0i_slowWeight
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

Asymmetrical RSI

by everget
948 stars

Asymmetrical RSI is an indicator that computes a custom relative strength index from the rate of change of a user-selected source. It plots the resulting ARSI line in a separate pane with color coding that turns green above the overbought level and red below t

Indicator v4 Oscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Asymmetrical RSI

This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
261 stars

This indicator demonstrates an experimental graph-style scatter visualization within a separate pane using Pine Script arrays. It tracks two features across recent bars: the single-bar price change and a scaled 14-period Relative Strength Index. Values are loa

Indicator v4 Oscillators & momentum
Updated 4 years ago · None stated GitHub repository of Example: Graph Style - 4th Dimension RSI

KD指標

by TaichiS
219 stars

This script calculates and plots a Stochastic Oscillator (KD indicator) in a separate chart pane. It determines the fast stochastic value over a 9-period lookback, then applies a 3-period Simple Moving Average (SMA) to create the %K line, and a second 3-period

Indicator v4 Oscillators & momentum
Updated 5 years ago · None stated GitHub repository of KD指標

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