OPEN-SOURCE SCRIPT

Stochastic [Paifc0de]

54
Stochastic [Paifc0de] — clean stochastic oscillator with visual masking, neutral markers, and basic filters


What it does
This indicator plots a standard stochastic oscillator (%K with smoothing and %D) and adds practical quality-of-life features for lower timeframes: optional visual masking when %K hugs overbought/oversold, neutral K–D cross markers, session-gated edge triangles (K crossing 20/80), and simple filters (minimum %K slope, minimum |K–D| gap, optional %D slope agreement, mid-zone mute, and a cooldown between markers). Display values are clamped to 0–100 to keep the panel scale stable. The tool is for research/education and does not generate entries/exits or financial advice.


Default preset: 20 / 10 / 10


K Length = 20
Classic lookback used in many textbooks. On intraday charts it balances responsiveness and stability: short enough to react to momentum shifts, long enough to avoid constant whipsaws. In practice it captures ~the last 20 bars’ position of close within the high–low range.


K Smoothing = 10
A 10-period SMA applied to the raw %K moderates the “saw-tooth” effect that raw stochastic can exhibit in choppy phases. The smoothing reduces over-reaction to micro spikes while preserving the main rhythm of swings; visually, %K becomes a continuous path that is easier to read.


D Length = 10
%D is the moving average of smoothed %K. With 10, %D becomes a clearly slower guide line. The larger separation between %K(10-SMA) and %D(10-SMA of %K) produces cleaner crosses and fewer spurious toggles than micro settings (e.g., 3/3/3). On M5–M15 this pair often yields readable cross cycles without flooding the chart.




How the 20/10/10 trio behaves


In persistent trends, %K will spend more time near 20 or 80; the 10-period smoothing delays flips slightly and emphasizes only meaningful turn attempts.

In ranges, %K oscillates around mid-zone (40–60). With 10/10 smoothing, cross signals cluster less densely; combining with the |K–D| gap filter helps keep only decisive crosses.

If your symbol is unusually volatile or illiquid, reduce K Length (e.g., 14) or reduce K Smoothing (e.g., 7) to keep responsiveness. If crosses feel late, decrease D Length (e.g., 7). If noise is excessive, increase K Smoothing first, then consider raising D Length.



Visuals

OB/OS lines: default 80/20 reference levels and a midline at 50.

Masking near edges: %K can be temporarily hidden when it is pressing an edge, approaching it with low slope, or going nearly flat near the boundary. This keeps the panel readable during “stuck at the edge” phases.

Soft glow (optional): highlights %K’s active path; can be turned off.

Light/Dark palette: quick toggle to match your chart theme.

Scale safety: all plotted values (lines, fills, markers) are clamped to 0–100 to prevent the axis from expanding beyond the stochastic range.



Markers and filters

Neutral K–D cross markers: circles in the mid-zone when %K crosses %D.

Edge triangles: show when %K crosses 20 or 80; can be restricted to a session window (02:00–12:00 ET).


Filters (optional):

Min %K slope: require a minimum absolute slope so very flat crosses are ignored.

Min |K–D| gap: demand separation between lines at the cross moment.

%D slope agreement: keep crosses that align with %D’s direction.

Mid-zone mute: suppress crosses inside a user-defined 40–60 band (defaults).

Cooldown: minimum bars between successive markers.



Parameters (quick guide)

K Length / K Smoothing / D Length: core stochastic settings. Start with 20/10/10; tune K Smoothing first if you see too much jitter.

Overbought / Oversold (80/20): adjust for assets that tend to trend (raise to 85/15) or mean-revert (lower to 75/25).

Slope & gap filters: increase on very noisy symbols; reduce if you miss too many crosses.

Session window (triangles only): use if you want edge markers only during active hours.

Marker size and offset: cosmetic; they do not affect calculations.



Alerts

K–D Cross Up (filtered) and K–D Cross Down (filtered): fire when a cross passes your filters/cooldown.

Edge Up / Edge Down: fire when %K crosses the 20/80 levels.
All alerts confirm on bar close.


Notes & attribution
Original implementation and integration by Paifc0de; no third-party code is copied.
This indicator is for research/education and does not provide entries/exits or financial advice.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.