The Ultimate Oscillator (UO), developed by Larry Williams, is a momentum oscillator designed to address the problem of false divergence signals often found in single-timeframe oscillators. It achieves this by incorporating three different timeframes (short, medium, and long) into a single, weighted oscillator value, providing a smoother and more reliable measure of momentum.
Our `UltimateOscillator_Pro` implementation is a unified, professional version that includes an **optional, fully customizable signal line** and allows the calculation to be based on either **standard** or **Heikin Ashi** price data.
The UO's calculation combines "Buying Pressure" relative to "True Range" over three distinct periods, using Larry Williams' specific definitions for these terms.
The entire calculation logic is encapsulated within a reusable include file.
* **Composition:** The calculator internally uses our universal `MovingAverage_Engine.mqh` to handle the smoothing of the Signal Line. This allows for advanced smoothing types (like DEMA or TEMA) beyond the standard SMA.
Unlike basic implementations that recalculate the entire history on every tick, this indicator employs an intelligent incremental algorithm.
* **State Tracking:** It utilizes `prev_calculated` to process only new bars.
* **Persistent Buffers:** Internal buffers persist their state between ticks.
* **Sliding Window:** The summation of Buying Pressure and True Range is handled by an efficient sliding window logic (`sum += new_value; sum -= old_value;`), which is significantly faster than recalculating the sum on every bar.
A three-step pattern is required for a buy signal:
1. A **bullish divergence** occurs: the price makes a **lower low**, but the UO makes a **higher low**.
2. The low of the UO during the divergence must be **below 30**.
3. A buy signal is triggered only when the UO subsequently breaks **above the high** it made between the two lows of the divergence.
### Bearish Divergence (Primary Sell Signal)
A three-step pattern is required for a sell signal:
1. A **bearish divergence** occurs: the price makes a **higher high**, but the UO makes a **lower high**.
2. The high of the UO during the divergence must be **above 70** (some sources suggest 50).
3. A sell signal is triggered only when the UO subsequently breaks **below the low** it made between the two highs of the divergence.
### Secondary Signals
* **Signal Line Crossovers:** If the signal line is enabled, its crossovers with the UO line can provide earlier, shorter-term momentum signals, similar to a MACD or Stochastic.
* **Overbought/Oversold:** While not its primary purpose, values above 70 can be considered overbought and values below 30 can be considered oversold, especially in ranging markets.