Define Williams %R before backtesting
Williams %R (often written as “Williams R”) is a momentum-style indicator that compares the current close to the highest high and lowest low over a chosen lookback window. The core idea is to normalize where price sits within a recent trading range, so values are interpretable across different price levels.
Before you backtest, write down the exact computation choices you will use, because small differences change results:
- Lookback length (the number of bars used to find the highest high and lowest low).
- Price used for the “current” point (typically the close of the bar).
- Highest/lowest definition (including or excluding the current bar as your method dictates).
Assumption to state explicitly: you are using the same bar frequency and the same definition of “high” and “low” in both backtest data and any later verification.
Build a backtest dataset that matches your intended reality
A responsible backtest starts with data assumptions that you can defend.
Consider these data-related items:
- Bar construction: decide whether you use fixed time bars (e.g., 1-hour candles) or another schedule. Your indicator values will differ if you change the bar type.
- Corporate and instrument effects: if your dataset includes instruments where historical continuity is not clean, results can be distorted. Even in FX-like series (where contracts roll), you should account for discontinuities in a way you can describe.
- Trading universe consistency: if you test multiple instruments, keep the universe consistent over time, or you must justify how new listings are handled.
Uncertainty note: historical relationships do not establish future results. Even a “correct” calculation can fail because market behavior changes.
Model costs and execution timing as part of the indicator test
Backtests often look better than they should because they ignore frictions. For Williams %R, you cannot treat the indicator as if trading is free.
Costs and execution choices to model (with explicit assumptions):
- Spread/transaction cost: use a consistent way to subtract a cost from each completed trade.
- Slippage: decide how you approximate adverse execution versus an ideal fill.
- Order timing: specify whether you assume you can trade at the close that produced the indicator value, or whether you trade on the next bar. This is a major source of accidental “look-ahead.”
Example of an explicit assumption: “Signals are computed from bar close values and trades are entered at the next bar open.” If you do not do this, you can unintentionally assume information that would not have been available.
Control bias with parameter discipline and out-of-sample checks
Williams %R backtests can become fragile when you tune parameters until they fit one historical period. Responsible practice focuses on reducing that “overfitting” risk.
Key controls:
- Separate training and testing periods: pick a parameter set using one segment (training), then evaluate on a different segment (testing).
- Walk-forward validation: repeatedly train on a rolling window and test on the next window. This helps mimic how you would have updated rules over time.
- Limit the number of tuned knobs: if you test many lookback lengths, thresholds, and additional filters, you increase the chance that some configuration performs well by chance.
Material failure mode: a strategy can show strong in-sample performance yet perform poorly out of sample because it learned noise rather than a repeatable effect.
Define what “signal” means—without claiming standalone predictive power
An indicator value alone is not the trading rule. In a responsible backtest, you must define a rule that converts indicator behavior into decisions, including:
- Entry/exit logic (for example, when a Williams %R condition triggers a position change).
- Position sizing assumption (fixed size, fixed risk, or another rule).
- Holding and re-entry rules (how you behave after exits).
Limitation to acknowledge: indicator thresholds that seem meaningful on one dataset may not transfer to another. Treat any detected relationship as a hypothesis.
Use verification that is independent of the backtest engine
Finally, verification helps you confirm that results are not artifacts of a particular implementation.
Independent checks you can do:
- Recompute indicator values independently: verify Williams %R calculations on a small sample to catch formula or indexing mistakes. - Sanity-check distributions: confirm that %R values behave as expected relative to recent highs and lows (e. g.