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.
* **Modular Calculation Engine (`UltimateOscillator_Calculator.mqh`):** The entire calculation logic is encapsulated within a reusable include file, separating the mathematical complexity from the user interface.
* **Object-Oriented Design (Inheritance):** A `CUltimateOscillatorCalculator` base class and a `CUltimateOscillatorCalculator_HA` derived class are used to cleanly separate the logic for standard and Heikin Ashi price sources.
* **Optional Signal Line:** The indicator is enhanced with a user-configurable moving average signal line. A `Display Mode` input allows the user to toggle the visibility of this line.
* **Stability and Efficiency:** We employ a full recalculation within `OnCalculate` for maximum stability. The summation of Buying Pressure and True Range is handled by an efficient **sliding window sum** technique (`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.