This indicator rescales Williams %R and applies a recursive Fisher Transform, plotting the resulting Fisher oscillator alongside a trigger line in a separate pane.
//@version=6
// Fisher Transform of Williams %R with Divergence Engine and Filtered Cross Signals
// - Williams %R is rescaled over a rolling window and passed through a recursive Fisher Transform
// - Regular / hidden divergence detection on the Fisher line (pivot based, confirmed on bar close)
// - Fisher / Trigger cross signals with noise filters (OB/OS extreme, zero-line side, alternation, cooldown)
indicator("Fisher Transform of Williams %R - Divergence", shorttitle="Fish%R Div", format=format.price, precision=2, overlay=false, max_lines_count=500, max_labels_count=500)
// ================= INPUTS =================
length = input.int(14, title="Williams %R Length", minval=1, group="Core Settings")
fisherLength = input.int(10, title="Fisher Transform Length", minval=1, group="Core Settings")
src = input.source(close, title="Source", group="Core Settings")
obLevel = input.float(1.5, title="Overbought Level", group="Core Settings")
osLevel = input.float(-1.5, title="Oversold Level", group="Core Settings")
// ================= DIVERGENCE SETTINGS =================
lbR = input.int(5, title="Pivot Right Lookback", minval=1, group="Divergence Settings", tooltip="Number of bars to the right required to confirm a pivot")
lbL = input.int(5, title="Pivot Left Lookback", minval=1, group="Divergence Settings", tooltip="Number of bars to the left used to detect a pivot")
rangeUpper = input.int(60, title="Max Lookback Range", minval=1, group="Divergence Settings", tooltip="Maximum bar distance between two pivots when searching for a divergence")
rangeLower = input.int(5, title="Min Lookback Range", minval=1, group="Divergence Settings", tooltip="Minimum bar distance between two pivots when searching for a divergence")
minBarsBetween = input.int(0, title="Min Bars Between Same-Type Signals", minval=0, group="Divergence Settings", tooltip="Minimum number of bars between the pivots of two same-type divergence signals. Values at or below Min Lookback Range have no practical effect (0 = off)")
minFishDiff = input.float(0.10, title="Min Fisher Difference", minval=0.0, step=0.05, group="Divergence Settings", tooltip="Minimum Fisher difference between two pivots. Filters out negligible divergences (0 = off)")
showRegular = input.bool(true, title="Show Regular Divergence", group="Divergence Toggle")
showHidden = input.bool(true, title="Show Hidden Divergence", group="Divergence Toggle")
zoneFilter = input.bool(false, title="Require OB/OS Zone for Divergence", group="Divergence Toggle", tooltip="If enabled, divergences are only generated when the Fisher pivot is inside the overbought/oversold zone")
// ================= CROSS SIGNAL SETTINGS =================
showCross = input.bool(true, title="Show Fisher/Trigger Cross Signals", group="Cross Signals", tooltip="Standalone confirmation signals generated when the Fisher line crosses its trigger line")
trigLen = input.int(3, title="Trigger EMA Length (1 = Prev Bar)", minval=1, group="Cross Signals", tooltip="1 = classic Fisher[1] trigger (very noisy). 2+ = an EMA of Fisher is used as the trigger, which makes crosses less frequent")
zoneGate = input.bool(true, title="Require Recent OB/OS Extreme", group="Cross Signals", tooltip="Buy requires Fisher to have reached the oversold zone recently; Sell requires the overbought zone")
extLookback = input.int(8, title="Extreme Lookback Bars", minval=1, group="Cross Signals", tooltip="Number of bars to look back for an overbought/oversold extreme")
zeroSide = input.bool(true, title="Buy Below / Sell Above Zero Line", group="Cross Signals", tooltip="Buy crosses must occur below the zero line, Sell crosses above it")
altOnly = input.bool(true, title="Alternate Signals Only", group="Cross Signals", tooltip="Prevents repeated signals in the same direction (Buy-Sell-Buy)")
crossMinBars = input.int(3, title="Min Bars Between Cross Signals", minval=0, group="Cross Signals", tooltip="Minimum number of bars between two cross signals (0 = off)")
// ================= STYLE & COLORS =================
bullColor = input.color(#00E676, "Bullish Divergence Color", group="Style & Colors")
bearColor = input.color(#FF5252, "Bearish Divergence Color", group="Style & Colors")
hiddenBull = input.color(color.new(#00E676, 40), "Hidden Bullish Color", group="Style & Colors")
hiddenBear = input.color(color.new(#FF5252, 40), "Hidden Bearish Color", group="Style & Colors")
fisherColor = input.color(#2962FF, "Fisher Line Color", group="Style & Colors")
trigColor = input.color(#FF6D00, "Trigger Line Color", group="Style & Colors")
// ================= WILLIAMS %R =================
hh = ta.highest(high, length)
ll = ta.lowest(low, length)
// Neutral value (-50) when the range is zero or during warm-up; 0 is the overbought extreme
percentR = (na(hh) or na(ll) or hh == ll) ? -50.0 : 100 * (src - hh) / (hh - ll)
// ================= FISHER TRANSFORM =================
highestPR = ta.highest(percentR, fisherLength)
lowestPR = ta.lowest(percentR, fisherLength)
// Neutral value (0.5) when the range is zero -> normVal = 0
rawVal = (highestPR == lowestPR) ? 0.5 : (percentR - lowestPR) / (highestPR - lowestPR)
normVal = 2 * (rawVal - 0.5)
// Classic Ehlers scaling: 0.66 * (raw - 0.5) = 0.33 * normVal
var float val = 0.0
val := math.max(math.min(0.33 * normVal + 0.67 * nz(val[1]), 0.999), -0.999)
var float fisher = 0.0
fisher := 0.5 * math.log((1 + val) / (1 - val)) + 0.5 * nz(fisher[1])
emaTrig = ta.ema(fisher, trigLen)
trigger = trigLen == 1 ? fisher[1] : emaTrig
// ================= PLOTS =================
plot(fisher, title="Fisher %R", color=fisherColor, linewidth=2)
plot(trigger, title="Trigger Line", color=trigColor, linewidth=1)
h1 = hline(obLevel, title="Overbought Level", color=color.gray, linestyle=hline.style_dashed)
h0 = hline(0, title="Zero Line", color=color.new(color.gray, 50), linestyle=hline.style_dotted)
h2 = hline(osLevel, title="Oversold Level", color=color.gray, linestyle=hline.style_dashed)
fill(h1, h2, color=color.new(#2962FF, 93), title="OB/OS Background")
// ================= FILTERED CROSS SIGNALS =================
crossUp = ta.crossover(fisher, trigger)
crossDown = ta.crossunder(fisher, trigger)
wasOS = ta.lowest(fisher, extLookback) <= osLevel
wasOB = ta.highest(fisher, extLookback) >= obLevel
rawBuy = crossUp and (not zoneGate or wasOS) and (not zeroSide or trigger < 0)
rawSell = crossDown and (not zoneGate or wasOB) and (not zeroSide or trigger > 0)
var int lastCrossDir = 0
var int lastCrossBar = na
cooldownOk = na(lastCrossBar) or (bar_index - lastCrossBar) >= crossMinBars
// barstate.isconfirmed: signals are only generated on bar close (no repainting, alerts fire once)
buySig = showCross and barstate.isconfirmed and rawBuy and cooldownOk and (not altOnly or lastCrossDir != 1)
sellSig = showCross and barstate.isconfirmed and rawSell and cooldownOk and (not altOnly or lastCrossDir != -1)
if buySig
lastCrossDir := 1
lastCrossBar := bar_index
if sellSig
lastCrossDir := -1
lastCrossBar := bar_index
plotshape(buySig ? fisher : na, title="Buy Cross Signal", style=shape.triangleup, location=location.absolute, color=bullColor, size=size.tiny)
plotshape(sellSig ? fisher : na, title="Sell Cross Signal", style=shape.triangledown, location=location.absolute, color=bearColor, size=size.tiny)
// ================= DIVERGENCE ENGINE =================
pl = ta.pivotlow(fisher, lbL, lbR)
ph = ta.pivothigh(fisher, lbL, lbR)
var int lastBullBar = na
var int lastBearBar = na
bool regBullSig = false
bool hdnBullSig = false
bool regBearSig = false
bool hdnBearSig = false
pivotBar = bar_index[lbR]
// --- Bullish Divergences ---
if not na(pl) and barstate.isconfirmed
int prevPlIndex = na
for i = rangeLower to rangeUpper
if not na(pl[i])
prevPlIndex := i
break
if not na(prevPlIndex)
float currentFisherLow = fisher[lbR]
float prevFisherLow = fisher[prevPlIndex + lbR]
float currentPriceLow = low[lbR]
float prevPriceLow = low[prevPlIndex + lbR]
bool inZone = not zoneFilter or currentFisherLow <= osLevel
bool spacingOk = na(lastBullBar) or (pivotBar - lastBullBar) >= minBarsBetween
bool diffOk = math.abs(currentFisherLow - prevFisherLow) >= minFishDiff
// Regular Bullish: price lower low, Fisher higher low
if showRegular and inZone and spacingOk and diffOk and currentPriceLow < prevPriceLow and currentFisherLow > prevFisherLow
line.new(bar_index[prevPlIndex + lbR], prevFisherLow, pivotBar, currentFisherLow, color=bullColor, width=2)
label.new(pivotBar, currentFisherLow, "Reg Bull", color=bullColor, style=label.style_label_up, textcolor=color.white, size=size.tiny)
lastBullBar := pivotBar
regBullSig := true
// Hidden Bullish: price higher low, Fisher lower low
else if showHidden and inZone and spacingOk and diffOk and currentPriceLow > prevPriceLow and currentFisherLow < prevFisherLow
line.new(bar_index[prevPlIndex + lbR], prevFisherLow, pivotBar, currentFisherLow, color=hiddenBull, width=2, style=line.style_dashed)
label.new(pivotBar, currentFisherLow, "Hdn Bull", color=hiddenBull, style=label.style_label_up, textcolor=color.white, size=size.tiny)
lastBullBar := pivotBar
hdnBullSig := true
// --- Bearish Divergences ---
if not na(ph) and barstate.isconfirmed
int prevPhIndex = na
for i = rangeLower to rangeUpper
if not na(ph[i])
prevPhIndex := i
break
if not na(prevPhIndex)
float currentFisherHigh = fisher[lbR]
float prevFisherHigh = fisher[prevPhIndex + lbR]
float currentPriceHigh = high[lbR]
float prevPriceHigh = high[prevPhIndex + lbR]
bool inZone = not zoneFilter or currentFisherHigh >= obLevel
bool spacingOk = na(lastBearBar) or (pivotBar - lastBearBar) >= minBarsBetween
bool diffOk = math.abs(currentFisherHigh - prevFisherHigh) >= minFishDiff
// Regular Bearish: price higher high, Fisher lower high
if showRegular and inZone and spacingOk and diffOk and currentPriceHigh > prevPriceHigh and currentFisherHigh < prevFisherHigh
line.new(bar_index[prevPhIndex + lbR], prevFisherHigh, pivotBar, currentFisherHigh, color=bearColor, width=2)
label.new(pivotBar, currentFisherHigh, "Reg Bear", color=bearColor, style=label.style_label_down, textcolor=color.white, size=size.tiny)
lastBearBar := pivotBar
regBearSig := true
// Hidden Bearish: price lower high, Fisher higher high
else if showHidden and inZone and spacingOk and diffOk and currentPriceHigh < prevPriceHigh and currentFisherHigh > prevFisherHigh
line.new(bar_index[prevPhIndex + lbR], prevFisherHigh, pivotBar, currentFisherHigh, color=hiddenBear, width=2, style=line.style_dashed)
label.new(pivotBar, currentFisherHigh, "Hdn Bear", color=hiddenBear, style=label.style_label_down, textcolor=color.white, size=size.tiny)
lastBearBar := pivotBar
hdnBearSig := true
// ================= ALERTS =================
alertcondition(regBullSig, title="Regular Bullish Divergence", message="Fish%R Div: Regular Bullish Divergence Confirmed")
alertcondition(hdnBullSig, title="Hidden Bullish Divergence", message="Fish%R Div: Hidden Bullish Divergence Confirmed")
alertcondition(regBearSig, title="Regular Bearish Divergence", message="Fish%R Div: Regular Bearish Divergence Confirmed")
alertcondition(hdnBearSig, title="Hidden Bearish Divergence", message="Fish%R Div: Hidden Bearish Divergence Confirmed")
alertcondition(buySig, title="Fisher Buy Cross", message="Fish%R Div: Filtered BUY cross")
alertcondition(sellSig, title="Fisher Sell Cross", message="Fish%R Div: Filtered SELL cross")
Overview
Fisher Transform of Williams %R - Divergence automatically detects regular and hidden divergences by identifying pivot highs and lows, confirmed after a set right lookback period. Additionally, it highlights Fisher and trigger line crossover signals filtered by overbought or oversold extremes, zero-line position, and custom cooldown periods. Settings allow users to adjust oscillator lengths, pivot lookbacks, threshold levels, and filter conditions. Signal confirmation lags by the right lookback length.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Williams %R Length
int
14
length
Fisher Transform Length
int
10
fisherLength
Source
source
close
src
Overbought Level
float
1.5
obLevel
Oversold Level
float
-1.5
osLevel
Pivot Right Lookback
int
5
lbR
Pivot Left Lookback
int
5
lbL
Max Lookback Range
int
60
rangeUpper
Min Lookback Range
int
5
rangeLower
Min Bars Between Same-Type Signals
int
0
minBarsBetween
Min Fisher Difference
float
0.10
minFishDiff
Show Regular Divergence
bool
true
showRegular
Show all 27 settings
Setting
Type
Default
Variable
Show Hidden Divergence
bool
true
showHidden
Require OB/OS Zone for Divergence
bool
false
zoneFilter
Show Fisher/Trigger Cross Signals
bool
true
showCross
Trigger EMA Length (1 = Prev Bar)
int
3
trigLen
Require Recent OB/OS Extreme
bool
true
zoneGate
Extreme Lookback Bars
int
8
extLookback
Buy Below / Sell Above Zero Line
bool
true
zeroSide
Alternate Signals Only
bool
true
altOnly
Min Bars Between Cross Signals
int
3
crossMinBars
Bullish Divergence Color
color
#00E676
bullColor
Bearish Divergence Color
color
#FF5252
bearColor
Hidden Bullish Color
color
color.new(#00E676, 40)
hiddenBull
Hidden Bearish Color
color
color.new(#FF5252, 40)
hiddenBear
Fisher Line Color
color
#2962FF
fisherColor
Trigger Line Color
color
#FF6D00
trigColor
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div
This indicator calculates the MACD oscillator from a configurable source with fast and slow lengths, then plots the histogram, MACD line, and signal line in a separate pane. It detects regular bullish divergences (price lower lows with oscillator higher lows),
This indicator calculates the Relative Strength Index (RSI) across four user-selected timeframes and plots the results in a separate pane. It identifies regular bullish and bearish divergences between price pivot points and the primary timeframe RSI value. Add
The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend
This indicator plots a standard Relative Strength Index (RSI) in a separate pane alongside customizable overbought and oversold threshold levels with shaded fills. It identifies pivot highs and lows on the oscillator to detect regular and hidden bullish and be
This indicator calculates a 14-period RSI from close and plots it in a separate pane with dotted overbought and dashed oversold lines at 70 and 30. It marks bullish divergence when a five-bar pivot low in price is lower than the price twenty bars earlier while