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 (exponential, alpha = 1/length) instead of simple SMA — same indicator, slower turn, fewer false flips
- Plots %K and %D in the lower pane with shaded overbought/oversold zones at 80/20
- Drops up/down arrows on bullish/bearish %K-vs-%D crosses inside the OB/OS zones — the high-quality momentum signals
- Built-in alerts fire on cross-in-zone events and on OB/OS exits, ready to wire into thinkorswim notifications
## 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+.
## thinkScript code
```
# ─────────────────────────────────────────────
# │ 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.
declare lower;
input kLength = 14;
input kSmoothing = 3;
input dSmoothing = 3;
input overbought = 80;
input oversold = 20;
input zoneFilter = yes;
input showAlerts = yes;
# --- Raw %K (close vs range percentile) ---
def hh = Highest(high, kLength);
def ll = Lowest(low, kLength);
def rng = hh - ll;
def rawK = if rng == 0 then 50 else 100 * (close - ll) / rng;
# --- Wilder RMA smoothing for %K and %D ---
def K = WildersAverage(rawK, kSmoothing);
def D = WildersAverage(K, dSmoothing);
# --- Plots ---
plot PctK = K;
PctK.SetDefaultColor(Color.CYAN);
PctK.SetLineWeight(2);
plot PctD = D;
PctD.SetDefaultColor(Color.MAGENTA);
PctD.SetLineWeight(2);
plot OB = overbought;
plot OS = oversold;
plot Mid = 50;
OB.SetDefaultColor(Color.GRAY);
OS.SetDefaultColor(Color.GRAY);
Mid.SetDefaultColor(Color.DARK_GRAY);
OB.SetStyle(Curve.SHORT_DASH);
OS.SetStyle(Curve.SHORT_DASH);
Mid.SetStyle(Curve.SHORT_DASH);
AddCloud(100, overbought, Color.RED);
AddCloud(oversold, 0, Color.GREEN);
# --- Cross signals (optionally filtered to OB/OS zones) ---
def bullCross = K crosses above D;
def bearCross = K crosses below D;
def inOS = K <= oversold or D <= oversold;
def inOB = K >= overbought or D >= overbought;
def bullSignal = bullCross and (!zoneFilter or inOS);
def bearSignal = bearCross and (!zoneFilter or inOB);
plot BullArrow = if bullSignal then K else Double.NaN;
BullArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullArrow.SetDefaultColor(Color.GREEN);
BullArrow.SetLineWeight(3);
BullArrow.HideTitle();
plot BearArrow = if bearSignal then K else Double.NaN;
BearArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearArrow.SetDefaultColor(Color.RED);
BearArrow.SetLineWeight(3);
BearArrow.HideTitle();
# --- OB/OS exit flags (mean-reversion confirmation) ---
def exitOB = K crosses below overbought;
def exitOS = K crosses above oversold;
# --- Alerts ---
Alert(showAlerts and bullSignal, "MF Wilder Stoch: BULL cross in OS", Alert.BAR, Sound.Ring);
Alert(showAlerts and bearSignal, "MF Wilder Stoch: BEAR cross in OB", Alert.BAR, Sound.Ring);
Alert(showAlerts and exitOB, "MF Wilder Stoch: %K exited overbought", Alert.BAR, Sound.Bell);
Alert(showAlerts and exitOS, "MF Wilder Stoch: %K exited oversold", Alert.BAR, Sound.Bell);
```
Drop your tweaks, screenshots, and questions below — that's how the library gets better.

