Indicator · Pine Script v6 · Own pane

Fisher Transform of Williams %R - Divergence

by theonetrade

This indicator rescales Williams %R and applies a recursive Fisher Transform, plotting the resulting Fisher oscillator alongside a trigger line in a separate pane.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code189
Settings27inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

189 lines of Pine Script v6 from assets/indicator/bit-exact/fisher_transform_of_williams_r_divergence_5eYf4t8I.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

fisher_transform_of_williams_r_divergence_5eYf4t8I.pine
//@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.

Details

Published by

theonetrade on GitHub

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Williams %R Lengthint14length
Fisher Transform Lengthint10fisherLength
Sourcesourceclosesrc
Overbought Levelfloat1.5obLevel
Oversold Levelfloat-1.5osLevel
Pivot Right Lookbackint5lbR
Pivot Left Lookbackint5lbL
Max Lookback Rangeint60rangeUpper
Min Lookback Rangeint5rangeLower
Min Bars Between Same-Type Signalsint0minBarsBetween
Min Fisher Differencefloat0.10minFishDiff
Show Regular DivergencebooltrueshowRegular
Show all 27 settings
SettingTypeDefaultVariable
Show Hidden DivergencebooltrueshowHidden
Require OB/OS Zone for DivergenceboolfalsezoneFilter
Show Fisher/Trigger Cross SignalsbooltrueshowCross
Trigger EMA Length (1 = Prev Bar)int3trigLen
Require Recent OB/OS ExtremebooltruezoneGate
Extreme Lookback Barsint8extLookback
Buy Below / Sell Above Zero LinebooltruezeroSide
Alternate Signals OnlybooltruealtOnly
Min Bars Between Cross Signalsint3crossMinBars
Bullish Divergence Colorcolor#00E676bullColor
Bearish Divergence Colorcolor#FF5252bearColor
Hidden Bullish Colorcolorcolor.new(#00E676, 40)hiddenBull
Hidden Bearish Colorcolorcolor.new(#FF5252, 40)hiddenBear
Fisher Line Colorcolor#2962FFfisherColor
Trigger Line Colorcolor#FF6D00trigColor
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.

Similar Pine Scripts

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

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator
368 stars

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),

Indicator v5 Oscillators & momentumDivergence
Updated 3 months ago · None stated GitHub repository of MACD + Divergences [Alorse]
228 stars

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

Indicator v6 Oscillators & momentumDivergence
Updated 4 months ago · None stated GitHub repository of Multi-Timeframe RSI with Divergence

Bubbles Indicator

by capissimo
114 stars

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

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 2 years ago · None stated GitHub repository of Bubbles Indicator

RSI [SystemAlpha]

by iamc1oud
56 stars

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

Indicator v4 Oscillators & momentumDivergence Repaints
Updated 3 months ago · None stated GitHub repository of RSI [SystemAlpha]
55 stars

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

Indicator v6 Oscillators & momentumDivergence
Updated 7 months ago · Apache-2.0 GitHub repository of RSI Divergence Detector

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers