WilliamsR — Williams %R
תוכן זה אינו זמין עדיין בשפה שלך.
Where the close sits relative to the window’s true high: 0 at the high, −100 at the low.
Numerically %K − 100, but read on its own scale. The seeded WilliamsClose uses closes; this
is the textbook high-low form.
Signature
WilliamsR(period, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
period |
int Param or literal | Yes | Range lookback. Default 14, bounds 1–400. |
on= |
symbol | No | Source symbol. Defaults to the trade symbol. Reads high, low, close. |
Formula
$$ %R = -100,\frac{\max(H, n) - C}{\max(H, n) - \min(L, n)} $$
Warmup
period bars to a full window; partial before that. A flat window returns −50 (neutral).
Reading the value
wr.valuewr < -80wr.crossed_above(-50)Example
class WilliamsReversal(Strategy): """Buy deep oversold, exit at the midline.""" period = Param(14, min=1, max=400) trade = Symbol() sizing = FixedCapital()
def execute(self): wr = WilliamsR(self.period, on=self.trade) if wr.value < -80 and self.trade.is_flat: self.buy(self.trade, reason=f"%R {wr.value:.0f}") if wr.value > -50 and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Midline")Notes
- Larry Williams’ %R.
- Proven by an assert-via-trade run on SPY daily (matched the formula on every bar; zero alarm trades).
- Single-value on purpose — unlike
Stochasticit can be smoothed (SMA(3, on=wr)) and crossed.