Williams %R Pine Strategy Without Coding (Negative Levels)

Williams %R 14 with cross up −80 / cross down −20 — negative scale explained — export strategy() and backtest on TradingView.

📖 3 min read

📝 599 words

🏷️ Pine Script and TradingView

Share this article:

The scale runs negative

Williams %R measures where the current close sits inside the recent high-to-low range. Its scale is the thing to get right before anything else:

%R runs from −100 to 0. Not 0 to 100.

A reading of −100 means the close is at the very bottom of the lookback range; 0 means it is at the very top. Every other bounded oscillator most people have met — RSI, stochastic — runs 0 to 100, which is exactly why this one causes a specific and silent failure.

The condition that is always true

Write the oversold threshold the way you would for RSI and you get this:

pine
// WRONG — every %R value is at or below 0, so this is true on every bar
oversold = wprValue < 20
pine
// Correct — the oversold end of the %R scale is near -80
oversold = wprValue < -80
overbought = wprValue > -20

The broken version does not error, does not warn, and does not look broken. It produces a strategy that enters on every bar until pyramiding is full, reports a full trade list, and shows an equity curve. Nothing in the Strategy Tester says "your condition is a constant".

This is why the input test matters. Move the threshold from 20 to 50 to 90 and watch the trade count. If it never changes, your condition is not reading the indicator — the same check that catches an unreferenced input, described in reading the Strategy Tester.

Building it in the form

FieldValueWhy
IndicatorWilliams %R
Length14the conventional lookback; nothing derives it
Oversold−80note the minus sign
Overbought−20
Exitopposite level, or an ATR stop%R gives no exit of its own

Then read the export and confirm the emitted comparison carries the negative sign. If the generated Pine shows a bare positive number against the %R series, the control in the settings dialog is not the number the logic uses — see what each field becomes.

What %R does not tell you

The same thing no oscillator tells you: whether the move is over. %R reaching −100 means price closed at the bottom of its recent range, which in a downtrend is the normal state rather than a reversal. It can sit near −100 for dozens of bars.

So %R alone is a range tool. In a trend it needs a gate — a moving-average filter or a volatility regime test — and the honest way to check whether your gate does anything is to count how many trades it removes: the confluence test.



Tactix AI — Studio vs Guide

Tactix AI is AlfaTactix’s product assistant brand (open Tactix AI).

  • Tactix Studio turns a one-sentence strategy description into a draft across Timeframe, Signals, Filters, and Risk in the visual Strategy Builder. You review and edit every field before Code Generator writes MQL5 or Pine Script.
  • Tactix Guide explains the step you are on — what to fill, what a control means, or how to phrase a rule — without dumping untested source code.

That is form-first automation: the LLM never replaces Code Generator, and you keep plan limits and real-time validation.

Frequently Asked Questions

Yes. Add Williams %R, Length 14, Buy when %R crosses up through −80 (oversold), Sell when %R crosses down through −20 (overbought). Values are negative. DemoEditorTester.

Williams %R scales from 0 to −100. Oversold is near −80/−100; overbought near 0/−20. Do not paste RSI’s +30/+70. Theory: Williams %R.

Prefer Cross for entries (CODED). Compare is available for “still oversold” style filters. No NOT. Cross-indicator cross type is limited — use compare/slope for multi-series ideas.

% equity + % or ATR SL — Pine risk. Pattern twin: RSI.

One TF, ≤2 indicators, no SuperTrend/Ichimoku/ADX/news. Hub.

First steps [1] · Editor.