Williams %R tells you where the close sits inside the recent high-low range. It is fast and clear, but it spends long stretches pinned near its extremes, which makes turning points hard to see. This indicator runs %R through a Fisher Transform: the result is a sharp oscillator that swings well beyond its usual levels only when a move is really stretched, and turns crisply when it ends.
On top of that line it adds two tools: a divergence engine that finds regular and hidden divergences between price and the Fisher line, and a cross signal against a trigger line, filtered so that only the crosses coming out of a real extreme are kept.
Williams %R. Over the last 14 bars, %R = 100 x (close – highest high) / (highest high – lowest low). It runs from -100 (close at the low of the range) to 0 (close at the high).
Normalisation. %R is then measured against its own range over the last 10 bars and rescaled to the interval -1 to +1. A value of +1 means %R is at the top of its recent range, -1 at the bottom.
Fisher Transform. John Ehlers’ transform takes a value between -1 and +1 and stretches the tails: value = 0.33 x normalised %R + 0.67 x previous value, clamped to +/-0.999, and Fisher = 0.5 x ln((1 + value) / (1 – value)) + 0.5 x previous Fisher. Values near the middle barely move, while values near the edges grow fast. That is why the line makes sharp peaks at turning points instead of the flat plateaus of %R.
Trigger line. A 3-bar exponential average of the Fisher line (with length 1, the Fisher of the previous bar, as in the classic version). The average crosses less often than the one-bar lag.
Cross filters. A buy is a cross of the Fisher above the trigger that also: comes after the Fisher touched the oversold level (-1.5) in the last 8 bars, happens below the zero line, alternates with the previous signal (no buy after buy) and keeps at least 3 bars from the previous cross. Sells mirror this.
Divergences. Pivot lows and highs of the Fisher line are found with 5 bars on each side. Each new pivot is compared with the previous pivot of the same type found between 5 and 60 bars earlier:
A divergence needs a minimum difference of 0.10 between the two Fisher pivots, so that near-identical pivots do not count. Optionally it can be required to form inside the overbought or oversold zone, and same-type divergences can be spaced out.
Core settings:
Divergence settings:
Cross signal settings:
//---------------------------------------------------------------
// PRC_Fisher WPR Divergence
// version = 0
// 01.12.2026
// Iván González @ www.prorealcode.com
// Author: mehmetbezgincan
// Sharing ProRealTime knowledge
//--------------------------------------------------------------------//
// Apply in a SEPARATE WINDOW (oscillator panel).
// The price source is the indicator's "Close" setting (CustomClose).
//
// Every DRAW* call lives inside the "IF islastbarupdate" block at the end:
// the divergence lines and the cross markers are repainted in one pass from
// their registers. That is a full redraw of the stored state, so the defparam
// is required - without it each new bar would stack another copy of the set.
//--------------------------------------------------------------------//
DEFPARAM drawonlastbaronly = true
//--------------------------------------------------------------------//
// --- Core settings ---
//--------------------------------------------------------------------//
length = 14 // Williams %R length
fisherLength = 10 // Fisher transform length
obLevel = 1.5 // Overbought level
osLevel = 0 - 1.5 // Oversold level
//--------------------------------------------------------------------//
// --- Divergence settings ---
//--------------------------------------------------------------------//
lbR = 5 // Pivot right lookback (bars needed to confirm a pivot)
lbL = 5 // Pivot left lookback
rangeUpper = 60 // Max bar distance between the two pivots
rangeLower = 5 // Min bar distance between the two pivots
minBarsBetween = 0 // Min bars between the pivots of two same-type signals (0 = off)
minFishDiff = 0.10 // Min Fisher difference between the two pivots (0 = off)
showRegular = 1 // 1 = show regular divergences
showHidden = 1 // 1 = show hidden divergences
zoneFilter = 0 // 1 = only divergences whose Fisher pivot is inside the OB/OS zone
//--------------------------------------------------------------------//
// --- Cross signal settings ---
//--------------------------------------------------------------------//
showCross = 1 // 1 = show the filtered Fisher / Trigger cross signals
trigLen = 3 // Trigger EMA length (1 = previous bar of the Fisher)
zoneGate = 1 // 1 = Buy needs a recent oversold extreme, Sell a recent overbought one
extLookback = 8 // Bars to look back for that extreme
zeroSide = 1 // 1 = Buy crosses below the zero line, Sell crosses above it
altOnly = 1 // 1 = alternate signals only (Buy-Sell-Buy)
crossMinBars = 3 // Min bars between two cross signals (0 = off)
//--------------------------------------------------------------------//
// --- Colours ---
//--------------------------------------------------------------------//
ONCE bullR = 0 // #00E676 bullish
ONCE bullG = 230
ONCE bullB = 118
ONCE bearR = 255 // #FF5252 bearish
ONCE bearG = 82
ONCE bearB = 82
ONCE hidA = 153 // hidden divergences: same colours at 60 % opacity
ONCE fisR = 41 // #2962FF Fisher line
ONCE fisG = 98
ONCE fisB = 255
ONCE trgR = 255 // #FF6D00 Trigger line
ONCE trgG = 109
ONCE trgB = 0
ONCE gryR = 120 // #787B86 levels
ONCE gryG = 123
ONCE gryB = 134
ONCE maxDivs = 500 // divergences kept on the chart (lines and labels)
//--------------------------------------------------------------------//
//=== 1. WILLIAMS %R ===
// Neutral value (-50) during the warm up and when the range is zero.
//--------------------------------------------------------------------//
hh = highest[length](high)
ll = lowest[length](low)
IF barindex < length - 1 THEN
percentR = 0 - 50
ELSIF hh = ll THEN
percentR = 0 - 50
ELSE
percentR = 100 * (customclose - hh) / (hh - ll)
ENDIF
//--------------------------------------------------------------------//
//=== 2. FISHER TRANSFORM ===
// %R is rescaled to [-1, 1] over its own recent range, smoothed recursively
// (classic Ehlers scaling 0.66 * (raw - 0.5) = 0.33 * normVal) and clamped
// before the logarithm, which blows up at +/-1.
// The line has no value until fisherLength bars of %R exist. During that
// warm up both recursions are seeded with 0, and the line stays invisible.
//--------------------------------------------------------------------//
highestPR = highest[fisherLength](percentR)
lowestPR = lowest[fisherLength](percentR)
warmF = fisherLength - 1
IF barindex < warmF THEN
val = 0
fish = 0
ELSE
IF highestPR = lowestPR THEN
normVal = 0
ELSE
normVal = 2 * ((percentR - lowestPR) / (highestPR - lowestPR) - 0.5)
ENDIF
val = max(min(0.33 * normVal + 0.67 * val[1], 0.999), 0 - 0.999)
fish = 0.5 * log((1 + val) / (1 - val)) + 0.5 * fish[1]
ENDIF
emaTrig = average[trigLen, 1](fish)
IF trigLen = 1 THEN
trig = fish[1]
ELSE
trig = emaTrig
ENDIF
warmT = warmF + trigLen
IF barindex >= warmF THEN
fishA = 255
ELSE
fishA = 0
ENDIF
IF barindex >= warmT THEN
trigA = 255
ELSE
trigA = 0
ENDIF
//--------------------------------------------------------------------//
//=== 3. FILTERED CROSS SIGNALS ===
// The state (last direction and last bar) is plain scalars: on the live
// candle they rewind tick to tick, so a cross that appears and then vanishes
// before the close leaves nothing behind.
//--------------------------------------------------------------------//
ONCE lastCrossDir = 0
ONCE lastCrossBar = 0 - 1
crossUp = 0
crossDn = 0
wasOS = 0
wasOB = 0
IF barindex > warmT THEN
IF fish > trig AND fish[1] <= trig[1] THEN
crossUp = 1
ENDIF
IF fish < trig AND fish[1] >= trig[1] THEN
crossDn = 1
ENDIF
ENDIF
IF barindex >= warmF + extLookback - 1 THEN
IF lowest[extLookback](fish) <= osLevel THEN
wasOS = 1
ENDIF
IF highest[extLookback](fish) >= obLevel THEN
wasOB = 1
ENDIF
ENDIF
rawBuy = crossUp = 1 AND (zoneGate = 0 OR wasOS = 1) AND (zeroSide = 0 OR trig < 0)
rawSell = crossDn = 1 AND (zoneGate = 0 OR wasOB = 1) AND (zeroSide = 0 OR trig > 0)
cooldownOk = lastCrossBar < 0 OR (barindex - lastCrossBar) >= crossMinBars
buySig = showCross = 1 AND rawBuy AND cooldownOk AND (altOnly = 0 OR lastCrossDir <> 1)
sellSig = showCross = 1 AND rawSell AND cooldownOk AND (altOnly = 0 OR lastCrossDir <> 0 - 1)
ONCE nCx = 0
IF buySig THEN
lastCrossDir = 1
lastCrossBar = barindex
$cxB[nCx] = barindex
$cxD[nCx] = 1
$cxY[nCx] = fish
nCx = nCx + 1
ENDIF
IF sellSig THEN
lastCrossDir = 0 - 1
lastCrossBar = barindex
$cxB[nCx] = barindex
$cxD[nCx] = 0 - 1
$cxY[nCx] = fish
nCx = nCx + 1
ENDIF
//--------------------------------------------------------------------//
//=== 4. FISHER PIVOTS ===
// A pivot low is lbR bars back: strictly below the lbR bars after it and
// below or equal to the lbL bars before it (on a tie the most recent bar
// wins). isPL / isPH are kept as series so the previous pivot can be found
// by looking back over them.
//--------------------------------------------------------------------//
isPL = 0
isPH = 0
IF barindex >= warmF + lbL + lbR THEN
IF fish[lbR] < lowest[lbR](fish) AND fish[lbR] <= lowest[lbL](fish)[lbR + 1] THEN
isPL = 1
ENDIF
IF fish[lbR] > highest[lbR](fish) AND fish[lbR] >= highest[lbL](fish)[lbR + 1] THEN
isPH = 1
ENDIF
ENDIF
//--------------------------------------------------------------------//
//=== 5. DIVERGENCE ENGINE ===
// The previous pivot is the most recent one between rangeLower and
// rangeUpper bars before the current one (measured between confirmations),
// whether or not it produced a divergence itself.
// Regular = reversal (price and Fisher disagree on the extreme).
// Hidden = continuation (they disagree on the retracement).
// Lines go into a register written by plain assignment with a scalar
// counter, so the live candle cannot leave a stale line behind.
//--------------------------------------------------------------------//
ONCE lastBullBar = 0 - 1
ONCE lastBearBar = 0 - 1
ONCE nDv = 0
dvRing = maxDivs + 1
pivotBar = barindex - lbR
regBullSig = 0
hdnBullSig = 0
regBearSig = 0
hdnBearSig = 0
// --- Bullish divergences ---
IF isPL = 1 THEN
prevIdx = 0 - 1
FOR i = rangeLower TO rangeUpper DO
IF prevIdx < 0 AND i <= barindex THEN
IF isPL[i] = 1 THEN
prevIdx = i
ENDIF
ENDIF
NEXT
IF prevIdx >= 0 THEN
curFL = fish[lbR]
prvFL = fish[prevIdx + lbR]
curPL = low[lbR]
prvPL = low[prevIdx + lbR]
inZone = zoneFilter = 0 OR curFL <= osLevel
spacingOk = lastBullBar < 0 OR (pivotBar - lastBullBar) >= minBarsBetween
diffOk = abs(curFL - prvFL) >= minFishDiff
IF showRegular = 1 AND inZone AND spacingOk AND diffOk AND curPL < prvPL AND curFL > prvFL THEN
regBullSig = 1
ELSIF showHidden = 1 AND inZone AND spacingOk AND diffOk AND curPL > prvPL AND curFL < prvFL THEN
hdnBullSig = 1
ENDIF
IF regBullSig = 1 OR hdnBullSig = 1 THEN
slD = nDv MOD dvRing
$dvX1[slD] = barindex - prevIdx - lbR
$dvY1[slD] = prvFL
$dvX2[slD] = pivotBar
$dvY2[slD] = curFL
IF regBullSig = 1 THEN
$dvT[slD] = 1
ELSE
$dvT[slD] = 2
ENDIF
nDv = nDv + 1
lastBullBar = pivotBar
ENDIF
ENDIF
ENDIF
// --- Bearish divergences ---
IF isPH = 1 THEN
prevIdx = 0 - 1
FOR i = rangeLower TO rangeUpper DO
IF prevIdx < 0 AND i <= barindex THEN
IF isPH[i] = 1 THEN
prevIdx = i
ENDIF
ENDIF
NEXT
IF prevIdx >= 0 THEN
curFH = fish[lbR]
prvFH = fish[prevIdx + lbR]
curPH = high[lbR]
prvPH = high[prevIdx + lbR]
inZone = zoneFilter = 0 OR curFH >= obLevel
spacingOk = lastBearBar < 0 OR (pivotBar - lastBearBar) >= minBarsBetween
diffOk = abs(curFH - prvFH) >= minFishDiff
IF showRegular = 1 AND inZone AND spacingOk AND diffOk AND curPH > prvPH AND curFH < prvFH THEN
regBearSig = 1
ELSIF showHidden = 1 AND inZone AND spacingOk AND diffOk AND curPH < prvPH AND curFH > prvFH THEN
hdnBearSig = 1
ENDIF
IF regBearSig = 1 OR hdnBearSig = 1 THEN
slD = nDv MOD dvRing
$dvX1[slD] = barindex - prevIdx - lbR
$dvY1[slD] = prvFH
$dvX2[slD] = pivotBar
$dvY2[slD] = curFH
IF regBearSig = 1 THEN
$dvT[slD] = 0 - 1
ELSE
$dvT[slD] = 0 - 2
ENDIF
nDv = nDv + 1
lastBearBar = pivotBar
ENDIF
ENDIF
ENDIF
//--------------------------------------------------------------------//
//=== 6. ALERT SERIES ===
// One invisible series per family, +1 bullish / -1 bearish / 0 quiet.
// Alert on "Sig Regular", "Sig Hidden" or "Sig Cross" crossing over 0.5
// (bullish) or under -0.5 (bearish).
//--------------------------------------------------------------------//
sigRegular = regBullSig - regBearSig
sigHidden = hdnBullSig - hdnBearSig
sigCross = 0
IF buySig THEN
sigCross = 1
ELSIF sellSig THEN
sigCross = 0 - 1
ENDIF
//--------------------------------------------------------------------//
//=== 7. DRAWING ===
//--------------------------------------------------------------------//
IF islastbarupdate THEN
labOff = (obLevel - osLevel) * 0.12
// Divergence lines and their labels (the last maxDivs)
dCnt = min(nDv, maxDivs)
IF dCnt > 0 THEN
FOR q = 0 TO dCnt - 1 DO
slD = (nDv - dCnt + q) MOD dvRing
dTy = $dvT[slD]
dX1 = $dvX1[slD]
dY1 = $dvY1[slD]
dX2 = $dvX2[slD]
dY2 = $dvY2[slD]
IF dTy = 1 THEN
DRAWSEGMENT(dX1, dY1, dX2, dY2) COLOURED(bullR, bullG, bullB, 255) STYLE(line, 2)
DRAWTEXT("Reg Bull", dX2, dY2 - labOff, dialog, bold, 9) COLOURED(bullR, bullG, bullB, 255)
ELSIF dTy = 2 THEN
DRAWSEGMENT(dX1, dY1, dX2, dY2) COLOURED(bullR, bullG, bullB, hidA) STYLE(dottedline2, 2)
DRAWTEXT("Hdn Bull", dX2, dY2 - labOff, dialog, bold, 9) COLOURED(bullR, bullG, bullB, hidA)
ELSIF dTy = 0 - 1 THEN
DRAWSEGMENT(dX1, dY1, dX2, dY2) COLOURED(bearR, bearG, bearB, 255) STYLE(line, 2)
DRAWTEXT("Reg Bear", dX2, dY2 + labOff, dialog, bold, 9) COLOURED(bearR, bearG, bearB, 255)
ELSE
DRAWSEGMENT(dX1, dY1, dX2, dY2) COLOURED(bearR, bearG, bearB, hidA) STYLE(dottedline2, 2)
DRAWTEXT("Hdn Bear", dX2, dY2 + labOff, dialog, bold, 9) COLOURED(bearR, bearG, bearB, hidA)
ENDIF
NEXT
ENDIF
// Cross markers, drawn on the Fisher line
IF nCx > 0 THEN
FOR q = 0 TO nCx - 1 DO
IF $cxD[q] = 1 THEN
DRAWTEXT("▲", $cxB[q], $cxY[q], dialog, standard, 10) COLOURED(bullR, bullG, bullB, 255)
ELSE
DRAWTEXT("▼", $cxB[q], $cxY[q], dialog, standard, 10) COLOURED(bearR, bearG, bearB, 255)
ENDIF
NEXT
ENDIF
ENDIF
//--------------------------------------------------------------------//
//=== 8. LEVELS AND RETURN ===
//--------------------------------------------------------------------//
COLORBETWEEN(obLevel, osLevel, 41, 98, 255, 18)
RETURN fish COLOURED(fisR, fisG, fisB, fishA) STYLE(line, 2) AS "Fisher %R", trig COLOURED(trgR, trgG, trgB, trigA) STYLE(line, 1) AS "Trigger Line", obLevel COLOURED(gryR, gryG, gryB, 255) STYLE(dottedline2, 1) AS "Overbought Level", 0 COLOURED(gryR, gryG, gryB, 128) STYLE(dottedline, 1) AS "Zero Line", osLevel COLOURED(gryR, gryG, gryB, 255) STYLE(dottedline2, 1) AS "Oversold Level", sigRegular COLOURED(0, 0, 0, 0) AS "Sig Regular", sigHidden COLOURED(0, 0, 0, 0) AS "Sig Hidden", sigCross COLOURED(0, 0, 0, 0) AS "Sig Cross"
Original author: mehmetbezgincan, published open source.