top of page

Pine Script Library

Public·1 member

Wilder-Smoothed Stochastic — Momentum Drop


# Wilder-Smoothed Stochastic — Momentum Drop


The classic G.C. Lane stochastic measures where price closed inside the recent high-low range, but its simple-MA smoothing reacts so fast that it whips in chop. This build swaps in Wilder's RMA for both %K and %D, which damps the noise and gives you a momentum read you can actually trade off of without flicker.


## What it does

- Computes raw %K as the standard close-vs-range percentile over the last N bars

- Smooths %K and %D using Wilder's RMA (`ta.rma`, alpha = 1/length) instead of SMA — same indicator, slower turn, fewer false flips

- Plots %K and %D in a lower pane with shaded overbought/oversold zones at 80/20

- Drops up/down triangles on bullish/bearish %K-vs-%D crosses inside the OB/OS zones — the high-quality momentum signals

- Built-in `alertcondition` calls fire on cross-in-zone events and on OB/OS exits, ready to wire into TradingView alerts


## Recommended settings

- %K length: **14**

- %K smoothing: **3**

- %D smoothing: **3**

- Overbought level: **80**

- Oversold level: **20**

- Signal zone filter: **on** (only arrows when cross occurs in OB/OS)

- Show alerts: **on**


## Ideal timeframe

Tuned for 15m–4h swing work and 1h–Daily position trades where momentum extremes actually mean something. On 1m/5m it'll still plot cleanly but the Wilder smoothing is the whole point — give it room to breathe on intraday-and-up. Best when paired with a higher-timeframe trend filter so you can lean on oversold crosses in uptrends and overbought crosses in downtrends.


## How to use

Treat the OB/OS zones as the only places worth taking the cross. In an uptrend, wait for %K to dip into the oversold zone, then take the bullish %K-over-%D cross as a long trigger; do the mirror in downtrends. Above 80 or below 20, momentum is stretched — fade the cross *back across the level*, not the level itself. Because Wilder smoothing slows the response, you'll see fewer crosses than the standard stoch, but the ones you get carry more weight. If you want it twitchier, drop %K length to 9 or set both smoothings to 1; if you want pure regime reads, push smoothing to 5+.


## Pine Script v5 code

```

//@version=5

// ─────────────────────────────────────────────

// │ MarketFragments.com | DNA & Market │

// │ info@marketfragments.com │

// │ www.marketfragments.com │

// ─────────────────────────────────────────────

// Time →

// │

// █ █ █│ █

// █ █ █ │ █ █

// █ █ █ │ █ █ █ ╭─╮

// █ █ █ │ █ █ █ █ ╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ ╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ █ █ ╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ █ █ █ █╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ █ █ █ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ █ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ ╰─────╯

// ──────┴──────────────────────────────────────────────────────────────

// T1 T2 T3 T4 T5 T6

//

// Wilder-Smoothed Stochastic — MarketFragments free drop

// Classic stochastic %K/%D but with Wilder's RMA smoothing instead of SMA.

// Slower-turning, less whippy, and gives momentum reads you can lean on.

// Free for non-commercial use. Attribution appreciated.


indicator("MF Wilder Stochastic", shorttitle="MF WStoch", overlay=false)


// --- Inputs ---

kLength = input.int(14, "%K Length", minval=1)

kSmooth = input.int(3, "%K Smoothing", minval=1)

dSmooth = input.int(3, "%D Smoothing", minval=1)

obLevel = input.int(80, "Overbought", minval=50, maxval=100)

osLevel = input.int(20, "Oversold", minval=0, maxval=50)

zoneFilter = input.bool(true, "Only Arrows in OB/OS Zones")

showAlerts = input.bool(true, "Enable Alerts")


// --- Raw %K (close vs range percentile) ---

hh = ta.highest(high, kLength)

ll = ta.lowest(low, kLength)

rng = hh - ll

rawK = rng == 0 ? 50.0 : 100.0 * (close - ll) / rng


// --- Wilder RMA smoothing for %K and %D ---

k = ta.rma(rawK, kSmooth)

d = ta.rma(k, dSmooth)


// --- Plots ---

plot(k, "%K", color=color.new(color.aqua, 0), linewidth=2)

plot(d, "%D", color=color.new(color.fuchsia, 0), linewidth=2)


obBand = hline(obLevel, "Overbought", color=color.new(color.gray, 0), linestyle=hline.style_dashed)

osBand = hline(osLevel, "Oversold", color=color.new(color.gray, 0), linestyle=hline.style_dashed)

midBand = hline(50, "Midline", color=color.new(color.gray, 60), linestyle=hline.style_dotted)

topBand = hline(100, display=display.none)

botBand = hline(0, display=display.none)

fill(obBand, topBand, color=color.new(color.red, 85), title="OB Zone")

fill(botBand, osBand, color=color.new(color.green, 85), title="OS Zone")


// --- Cross signals (optionally filtered to OB/OS zones) ---

bullCross = ta.crossover(k, d)

bearCross = ta.crossunder(k, d)

inOS = k <= osLevel or d <= osLevel

inOB = k >= obLevel or d >= obLevel

bullSignal = bullCross and (not zoneFilter or inOS)

bearSignal = bearCross and (not zoneFilter or inOB)


plotshape(bullSignal, "Bull Cross", style=shape.triangleup,

location=location.bottom, color=color.green, size=size.small)

plotshape(bearSignal, "Bear Cross", style=shape.triangledown,

location=location.top, color=color.red, size=size.small)


// --- OB/OS exit flags (mean-reversion confirmation) ---

exitOB = ta.crossunder(k, obLevel)

exitOS = ta.crossover(k, osLevel)


// --- Alerts ---

alertcondition(showAlerts and bullSignal,

"MF Wilder Stoch BULL cross in OS",

"Wilder Stoch BULL cross in OS on {{ticker}} @ {{close}}")

alertcondition(showAlerts and bearSignal,

"MF Wilder Stoch BEAR cross in OB",

"Wilder Stoch BEAR cross in OB on {{ticker}} @ {{close}}")

alertcondition(showAlerts and exitOB,

"MF Wilder Stoch exit OB",

"Wilder Stoch %K exited overbought on {{ticker}} @ {{close}}")

alertcondition(showAlerts and exitOS,

"MF Wilder Stoch exit OS",

"Wilder Stoch %K exited oversold on {{ticker}} @ {{close}}")

```


Drop your tweaks, screenshots, and questions below — that's how the library gets better.


Brain with financial data analysis.

Inquiries at :

Important Risk Notice: Trading involves substantial risk of loss. This is educational content only—not advice. Full details here  ------------>  

Proceed only if you're prepared.

tel#: (843) 321-8514

bottom of page