Expand description
§Williams %R
Oscillator on high/low/close over lookback (N):
%R = -100 * (HH − close) / (HH − LL)where (HH = \max(high)) and (LL = \min(low)) over the last (N) bars. Range is typically [−100, 0]. Flat window ((HH = LL)): carry previous %R, else −50.
Default: period 14 (WillrParams::period_14).
§Trading perspective
| Region | Habit (classic, not a rule) |
|---|---|
| %R > −20 | “Overbought” screen |
| %R < −80 | “Oversold” screen |
| Cross back from extreme | Momentum resume / mean-reversion exit screen |
§vs other oscillators
| Williams %R | Stochastic | RSI | |
|---|---|---|---|
| Scale | [−100, 0] | [0, 100] | [0, 100] |
| Inputs | H/L/C window | H/L/C + smooth | Closes only |
| Feel | Fast, inverted Stoch-like | Smoothed %K/%D | Wilder smooth, slower |
Rough map: raw Stoch %K ≈ 100 + %R (same HH/LL idea; sign/offset differ). Prefer
Stochastic when you want %D signal line; %R when you want a single fast line.
§Pairs well with
- ADX / DI — only fade %R extremes when ADX is low (range); avoid fading when ADX is high.
- SMA/EMA trend filter — long setups only above rising MA, etc.
- Volume (OBV/MFI) — confirm oversold bounce with rising money flow.
- ATR stops — oscillator does not size risk; ATR does.
§Engineering
WillrParams → willr / WillrState → willr_solution.
Batch uses WillrState end-to-end. HH/LL are amortized O(1) (sliding max/min).
§Word problem
Highs 12, lows 10, close 11 for three bars with (N=3). What is %R on bar 2?
Expect: (HH=12), (LL=10), %R = (-100 \times (12-11)/(12-10) = -50).
use finance_solution::stocks::ta::{willr, WillrParams};
let h = [12.0, 12.0, 12.0];
let l = [10.0, 10.0, 10.0];
let c = [11.0, 11.0, 11.0];
let s = willr(&h, &l, &c, WillrParams::new(3)).unwrap();
assert!((s.willr[2].unwrap() - (-50.0)).abs() < 1e-12);Structs§
- Validated
Willr - Validated pack.
- Willr
Params - Williams %R lookback.
- Willr
Series - Willr
Solution - Willr
State - Incremental Williams %R.
Functions§
- willr
- willr_
solution - Examples