Add the Williams %R strategy

New williams_r indicator (in [-100, 0]) exposed as ctx.williams_r(period), and a
long-only mean-reversion strategy: enter when %R is at/below the oversold level,
exit when it reaches the overbought level, with an optional ATR stop. 11
strategies total. Adds indicator and strategy tests; smoke-tested on live
BTC/USDT 5m (backtest + parameter sweep).
This commit is contained in:
matitos committed 2026-09-26 18:44:00 +00:00
1 parent ef895b6b9c
commit d92f152f9b
6 files changed
+171 -2

No files matched your search

+16
View File
@@ -151,6 +151,22 @@ def roc(values: Sequence[float], period: int = 10) -> list[Number]:
return out
def williams_r(candles: Sequence[Candle], period: int = 14) -> list[Number]:
"""Williams %R, in [-100, 0]. Below -80 is oversold, above -20 overbought."""
if period <= 0:
raise ValueError("period must be positive")
out: list[Number] = [None] * len(candles)
for i in range(period - 1, len(candles)):
window = candles[i - period + 1 : i + 1]
highest = max(candle.high for candle in window)
lowest = min(candle.low for candle in window)
if highest == lowest:
out[i] = -50.0
else:
out[i] = (highest - candles[i].close) / (highest - lowest) * -100
return out
def typical_price(candle: Candle) -> float:
return (candle.high + candle.low + candle.close) / 3