strategy · own pane · open source
Williams %R mean reversion strategy (14, −80 / −20)
Williams %R(14) mean reversion: buy below −80, exit above −20, with a 2%/6% bracket. Plain-English rules, copyable code and a backtest with costs included. Deepwick Script runs a subset of Pine Script.
What the Williams %R Mean Reversion strategy does
Williams %R mean reversion long-only: enter when %R drops below -80 (oversold), exit when it climbs above -20 (overbought).
- Lower the entry threshold (e.g. -90) for fewer, more extreme entries.
- 14 is the standard lookback; shorter lengths are more reactive.
- Combine with a higher-timeframe trend to filter against the prevailing move.
Entry and exit rules
Language reference: Deepwick Script.
Default inputs
| Input | Default | Min | Max |
|---|---|---|---|
Length | 14 | 5 | 50 |
Stop Loss % | 2 | 0.5 | 10 |
Take Profit % | 6 | 0 | 20 |
How Deepwick fills this strategy
- Market orders fill at the next bar's open.
- Stops and limits follow the bar's path: open → nearer extreme → farther extreme → close.
- Gaps fill at the open.
- Commission is charged on every fill, and slippage applies to market and stop fills, as set in
strategy().
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
strategy("Williams %R Mean Reversion", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
len = input.int(14, "Length", minval=5, maxval=50, step=1)
stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
colorBg = input.color("color.purple", "Color Bg")
colorUp = input.color("color.green", "Color Up")
colorDown = input.color("color.red", "Color Down")
colorNeutral = input.color("color.gray", "Color Neutral")
w = ta.wpr(len)
longSignal = strategy.position_size == 0 and w < -80
exitSignal = strategy.position_size > 0 and w > -20
if longSignal
strategy.entry("Long", strategy.long)
if strategy.position_size > 0
strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
if exitSignal
strategy.close("Long", comment="%R exit")
hline(-20, "Overbought", color=colorNeutral, linestyle=hline.style_dashed)
hline(-80, "Oversold", color=colorNeutral, linestyle=hline.style_dashed)
p_Williams__R = plot(w, "Williams %R", color=colorBg, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=colorDown, text="X")
alertcondition(longSignal, "Williams %R long entry", "Williams %R dropped below -80")
alertcondition(exitSignal, "Williams %R exit", "Williams %R climbed above -20")
Run it in Deepwick
- Open a chart of any crypto pair or CFD.
- Click “Scripts” and add this strategy.
- Press Run and read the trades in the Strategy Tester.
FAQ
Is Williams %R the same as the Stochastic?
%R is the fast Stochastic %K flipped onto a 0 to −100 scale, without smoothing. That is why it reacts faster and gives more signals.
Can I change the −80 / −20 levels?
Not from the inputs panel yet; they are constants in the code. Edit the two numbers in the script, or turn them into input.int() and rerun.
Does %R work on crypto?
It can be tested on any listed crypto or CFD symbol. Fast oscillators trade a lot, so read the costs and trade count in the table first.
No comments yet.
Sign in to comment.