Bentrix Docs
HomePricingDashboard

Ultimate Oscillator

Oscillatorsoscillatorone linein every package

Buying pressure divided by true range, summed over three windows and combined with weights 4, 2 and 1 toward the shortest, mapped to 0 to 100.

It measures one-sidedness on three horizons at once so that a single window's noise cannot produce the whole reading. Conventional readings: above 70 called overbought and below 30 oversold, and divergences that survive on all three windows.

01The study, live

Live figureScroll to zoom, drag the bars to pan.
3070
bar —O — H — L — C —main line —first value at —
Show where:

Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.

What this figure shows

The figure is computed over 300 sample bars. Ultimate Oscillator has no value on the first 28 — the bars it needs before it can answer — and its first value stands on bar 29. Its line runs between 22.61 and 73.23 on these bars, and the last value is 51.24. The pane's scale is fixed at 0 to 100, the range the study can take. Counting the conditions the study declares on these bars: crosses above 30 twice; crosses below 30 twice; crosses above 70 4 times; crosses below 70 4 times. Press a condition under the figure to see each place marked. As states rather than moments: is above 30 on 264 bars; is below 30 on 8 bars; is above 70 on 6 bars; is below 70 on 266 bars.

02Its parts, named

The bars it readseach bar's open, high, low and closeWarm-upno value on the first 28 bars: thestudy needs them before it cananswerThe main linethe study's own value on each barLevel 70a fixed reference the study is readagainstLevel 30a fixed reference the study is readagainst
Computed by Bentrix’s own code over the sample bars. It is drawn on once, as you reach the figure.

03What you see

An oscillator between 0 and 100 that combines buying pressure over three windows — 7, 14 and 28 bars by default.

04Where it comes from

Larry Williams published it in 1985 to reduce the false extremes of single-window oscillators by blending three horizons.

05The formula

Buying pressure BP=C−min(L,Ct−1), true range TR; for each window the average ∑BP/∑TR; then

UO=100·4A7+2A14+A287
Anthe buying pressure over the true range, summed over n bars
BPthe buying pressure, C−min(L,Ct−1)
TRthe bar's true range

06A worked example

The sample bars used here are eight: closes 20, 21, 23, 22, 24, 25, 24, 26; highs 21, 22, 24, 24, 25, 26, 26, 27; lows 18, 19, 20, 21, 21, 23, 23, 23; opens 19, 20, 21, 23, 22, 24, 25, 24.

Take periods of 2, 4 and 6 in place of 7, 14 and 28. For each bar, buying pressure is the close minus the true low (the lower of the bar's low and the previous close), and the true range is measured the same way from the true high.

For the last six bars buying pressure is 3, 1, 3, 2, 1, 3 and the true range 4, 3, 4, 3, 3, 4.

  • over 2 bars: 4 / 7 = 0.571
  • over 4 bars: 9 / 14 = 0.643
  • over 6 bars: 13 / 21 = 0.619

UO = 100 × (4 × 0.571 + 2 × 0.643 + 0.619) / 7 = 59.86

The shortest window weighs four times the longest, but the longest still takes part: a burst that shows only in the short window cannot carry the line to an extreme alone.

07Built in Assay

The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.

THE SCRIPT’S GRAPH
//@version=6
indicator("Ultimate Oscillator")
length1 = input.int(7, "Short")
length2 = input.int(14, "Middle")
length3 = input.int(28, "Long")
// Buying pressure: how far the close is above the lower of this bar's low and the last close.
trueLow = math.min(low, close[1])
pressure = close - trueLow
trueRange = math.max(high - low, math.abs(close[1] - high), math.abs(close[1] - low))
// The pressure as a share of the range, over three windows.
average1 = math.sum(pressure, length1) / math.sum(trueRange, length1)
average2 = math.sum(pressure, length2) / math.sum(trueRange, length2)
average3 = math.sum(pressure, length3) / math.sum(trueRange, length3)
// The shortest window weighs four times, the middle twice, the longest once.
ultimate = 100 * ((4 * average1) + (2 * average2) + average3) / 7
plot(ultimate, "UO")
hline(70)
hline(30)

Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.

08Readings — what traders look for

Above 70 and below 30 are read as strong buying or selling pressure across the three horizons; divergences with price are the reading Williams emphasised.

How the 70 and 30 readings fail. In a strong trend the line stays at one end of its scale for a long time; a high reading there describes the trend and does not mark its end. Williams did not read the levels alone: his own rule needed a divergence that began beyond a level.

How divergence fails. A divergence can form two, three or four times in a row while price keeps going; it describes a slowing pace, and a move can keep slowing for a long while.

09In different markets and timeframes

The Ultimate Oscillator blends three windows so that a short burst cannot carry it to an extreme alone; it is calmer than a single short oscillator and quicker than a single long one. Williams' rule for it is about divergence in a market that has reached an extreme.

10With other studies

Read beside price for the divergence his rule requires, and beside a single-window oscillator (an RSI of the middle period) to see what the blend changes.

11What it does not tell you

!

Blending windows smooths the line; it does not make its extremes predictive.

12Inputs and defaults

Ultimate Oscillator (7, 14)settings card
1Short period7
2Middle period14
3Long period28
4TimeframeChart
5Wait for the candle to closeOn
  1. 1
    Short period — 7The shortest window, weighted 4. It makes the line responsive.
  2. 2
    Middle period — 14The middle window, weighted 2.
  3. 3
    Long period — 28The longest window, weighted 1. It keeps a short burst from reaching the extremes alone. Williams used 7, 14 and 28: each double the one before.
  4. 4
    Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
  5. 5
    Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.

The settings in use

  • In use7, 14 and 28 are Williams': each double the last. Keeping that ratio (5, 10, 20) keeps the character.

13Limits and common misreadings

Three windows, one warm-up: the first value needs the longest period.

Sums, not averages: each bar leaves each window abruptly, at three different times.

14Conditions an alert or a strategy can watch

crosses above 30 eventcrosses below 30 eventis above 30 stateis below 30 statecrosses above 70 eventcrosses below 70 eventis above 70 stateis below 70 state

Event: the bar it happens on an event happens on one barState: every bar while it holds a state holds on every bar while it lasts

These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.

15Practise it in the laboratory

Put the Ultimate Oscillator (7, 14, 28) and RSI 7 in two panes; replay a sharp three-bar burst and compare how far each line travels.

Open the laboratory

17In Bentrix

  • From the menu: a chart's Indicators button › Oscillators › Ultimate Oscillator, or type Ultimate Oscillator in its search.
  • Its settings: the settings card opens when it is added; its legend's name opens it again.

18From an agent or a program

Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "ult_osc"}).

The study, as a chart files it

This is a new Ultimate Oscillator’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.

{
  "applied": "close",
  "convention": "talib",
  "kind": "ult_osc",
  "settings": {
    "p1": 7,
    "p2": 14,
    "p3": 28,
    "shape": "three"
  }
}

An agent

An agent calls the MCP tool with it:

{
  "name": "study_values",
  "arguments": {
    "bench": "bentrix://lab/\u2026/bench/\u2026",
    "symbol": "EURUSD",
    "timeframe": "H1",
    "limit": 5,
    "study": {
      "applied": "close",
      "convention": "talib",
      "kind": "ult_osc",
      "settings": {
        "p1": 7,
        "p2": 14,
        "p3": 28,
        "shape": "three"
      }
    }
  }
}

A program

A program does the same in its language — bench and market as in the built-in indicators guide:

Python

values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "talib", "kind": "ult_osc", "settings": {"p1": 7, "p2": 14, "p3": 28, "shape": "three"}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
    print("line:", line["line"])
    print("  newest values:", line["values"])

JSJavaScript

const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "talib", "kind": "ult_osc", "settings": { "p1": 7, "p2": 14, "p3": 28, "shape": "three" } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
  console.log("line:", line.line);
  console.log("  newest values:", line.values);
}

C#C#

var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "talib", ["kind"] = "ult_osc", ["settings"] = new Dictionary<string, object?> { ["p1"] = 7, ["p2"] = 14, ["p3"] = 28, ["shape"] = "three" } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
    Console.WriteLine($"line: {line!["line"]!}");
    Console.WriteLine($"  newest values: {line!["values"]!}");
}

GOGo

values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "talib", "kind": "ult_osc", "settings": map[string]any{"p1": 7, "p2": 14, "p3": 28, "shape": "three"}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
	fmt.Println("line:", at(line, "line"))
	fmt.Println("  newest values:", at(line, "values"))
}

Java

Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "talib", "kind", "ult_osc", "settings", obj("p1", 7, "p2", 14, "p3", 28, "shape", "three"))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
    System.out.println("line:" + " " + at(line, "line"));
    System.out.println("  newest values:" + " " + at(line, "values"));
}

C++C++

auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "talib"}, {"kind", "ult_osc"}, {"settings", Json::Object{{"p1", 7}, {"p2", 14}, {"p3", 28}, {"shape", "three"}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
    std::cout << "line:" << " " << line["line"].dump() << std::endl;
    std::cout << "  newest values:" << " " << line["values"].dump() << std::endl;
}

Julia

values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "talib", "kind" => "ult_osc", "settings" => Dict{String,Any}("p1" => 7, "p2" => 14, "p3" => 28, "shape" => "three")); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
    println("line:", " ", line["line"])
    println("  newest values:", " ", line["values"])
end

RR

values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "talib", kind = "ult_osc", settings = list(p1 = 7, p2 = 14, p3 = 28, shape = "three")), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
  cat("line:", format(line$line), "\n")
  cat("  newest values:", format(line$values), "\n")
}

RRust

let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "talib", "kind": "ult_osc", "settings": {"p1": 7, "p2": 14, "p3": 28, "shape": "three"}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
    println!("line: {}", line["line"]);
    println!("  newest values: {}", line["values"]);
}

Reading the answer

  • times — the candles’ open times, in milliseconds since 1970 (UTC), oldest first.
  • lines — one entry per line, in this order, each with its line name and its values; values[i] belongs to the candle at times[i].
  • The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
  • null is a candle with no value yet — the warm-up, about 1 × the period at the start of the history.
  • Its fixed levels, drawn on the chart: [30.0, 70.0].
lineWhat it is
Mainthe indicator's own value

In a strategy

Filed under a key of your choice in a strategy document’s studies — here ult_osc: {"ult_osc": {"applied": "close", "convention": "talib", "kind": "ult_osc", "settings": {"p1": 7, "p2": 14, "p3": 28, "shape": "three"}}} — its rules can name:

WriteWhat it is
ult_oscits main line, as a value in a compare
{"cond": "ult_osc:level.cross_up:30"}a condition it declares itself
{"cond": "ult_osc:level.cross_down:30"}a condition it declares itself
{"cond": "ult_osc:level.above:30"}a condition it declares itself
{"cond": "ult_osc:level.below:30"}a condition it declares itself
{"cond": "ult_osc:level.cross_up:70"}a condition it declares itself
{"cond": "ult_osc:level.cross_down:70"}a condition it declares itself
{"cond": "ult_osc:level.above:70"}a condition it declares itself
{"cond": "ult_osc:level.below:70"}a condition it declares itself

19Sources

  1. Williams, Larry. "The Ultimate Oscillator." Technical Analysis of Stocks & Commodities, 1985.

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed