Williams' Percent Range (%R), developed by Larry Williams, is a momentum oscillator that identifies overbought and oversold conditions. It is mathematically the inverse of the **Fast Stochastic Oscillator's %K line**, plotted on a negative scale from -100 to 0.
Our `WPR_Pro` implementation is a unified, professional version that not only allows the calculation to be based on either **standard** or **Heikin Ashi** price data, but also includes an optional, fully customizable **signal line**, effectively mirroring the functionality of a full Fast Stochastic oscillator on the WPR's scale.
## 2. Mathematical Foundations and Calculation Logic
The %R formula compares the current close to the recent high-low range.
### Required Components
* **Period (N):** The lookback period for the calculation (e.g., 14).
* **Price Data:** The `High`, `Low`, and `Close` of each bar.
### Calculation Steps (Algorithm)
1.**Find the Highest High and Lowest Low:** For each bar, determine the highest high and lowest low over the last `N` periods.
2.**Calculate the Williams %R:** Apply the main formula.
* **Composition Pattern:** The `WPR_Calculator` orchestrates two powerful engines:
1.**Stochastic Engine:** It reuses the `StochasticFast_Calculator.mqh` to compute the raw %K value, which is then transformed into %R. This eliminates code duplication and guarantees consistency.
2.**MA Engine:** It uses the `MovingAverage_Engine.mqh` to calculate the optional signal line. This allows for advanced smoothing methods beyond standard MAs.
* **Oversold:** Readings between **-80 and -100**.
* **Divergence:** Look for divergences between the %R and the price action.
* **Momentum Failure:** A common signal is when the %R enters the overbought zone, pulls back, and then fails to re-enter it on a subsequent price rally.
* **Caution:** Like all oscillators, %R can remain in overbought or oversold territory for extended periods during a strong trend.