0bps

Strategy vault / Breakout

Williams R Indicator Trading Strategy

The Williams %R trading strategy generates signals based on the Williams Percent Range indicator, which measures market momentum by comparing the current close to the high-low range over a period. The strategy goes…

Author
ChaoZhang
Complexity
Starter · 33 lines
Parameters
3
Backtest bar
12h · swing
Tested on
BTC/USDT · futures

Strategy Logic

The Williams %R trading strategy generates signals based on the Williams Percent Range indicator, which measures market momentum by comparing the current close to the high-low range over a period.

The strategy goes long when the %R line crosses above oversold, and sells when the line crosses below overbought. The logic is:

  1. Calculate Williams %R over a timeframe (e.g. 14 periods)

  2. Set overbought (e.g. -20) and oversold (e.g. -80) levels

  3. Go long when the %R line crosses up through oversold

  4. Close longs when the %R line crosses down through overbought

This allows entries around potential reversal points to capitalize on short-term moves.

Advantages

  • Simple parameters and rules

  • Early identification of overbought/oversold

  • Systematic breakout trading

Risks

  • Lagging %R may miss opportunities

  • Requires optimization of inputs

  • Oversold/bought levels are rough guides

Summary

The Williams %R strategy aims to capture reversals by trading overbought/oversold regions. With proper position sizing and stops, risk can be controlled. But lag is a key limitation requiring additional tools for validation and caution in use.

Parameters

NameDefaultWhat it controls
v_input_114Length
v_input_2-20Overbought Level
v_input_3-80Oversold Level

Source Pine Script

/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-13 00:00:00
period: 12h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// © Julien_Eche

//@version=5
strategy("Williams %R Strategy", overlay=true, initial_capital=100000, shorttitle="W%R Strategy")

// Paramètres
length = input(14, "Length")
overboughtLevel = input(-20, "Overbought Level")
oversoldLevel = input(-80, "Oversold Level")

// Calcul du Williams %R
williamsR = -100 * (ta.highest(high, length) - close) / (ta.highest(high, length) - ta.lowest(low, length))

// Conditions d'achat et de vente
buySignal = ta.crossover(williamsR, oversoldLevel)
sellSignal = ta.crossunder(williamsR, overboughtLevel)

// Entrée en position longue
if buySignal
    strategy.entry("Buy", strategy.long)

// Sortie de la position longue
if sellSignal
    strategy.close("Buy")

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-14. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Williams-R-Indicator-Trading-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open