1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
74 lines of Pine Script v6 from scripts/configurable-stochastics.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.
configurable-stochastics.pine
//@version=6
// =============================================================================
// Taught to Trade - Configurable Stochastics
// shorttitle: TT Stoch
// -----------------------------------------------------------------------------
// WHAT IT IS
// A stochastic oscillator that exposes the parts most versions hide: it plots
// fast %K, slow %K, and slow %D, and lets you pick the SMOOTHING method
// (SMA / EMA / WMA / HMA) instead of forcing plain SMA. Same classic stochastic
// math - more control over how it responds.
//
// HOW TO USE
// Read overbought/oversold and %K/%D crosses as you would any stochastic. Faster
// smoothing (HMA/WMA) reacts sooner but gives more false turns; slower (SMA) is
// steadier but later. Set YOUR OWN alerts from the conditions provided - this
// script does not send buy/sell signals.
//
// WHERE IT FAILS
// - Stochastics whipsaw in strong trends (they stay "overbought" while price keeps
// rising). Best as ranging/confirmation context, not a standalone trigger.
// - Signals evaluate on close and can change intrabar.
//
// Educational tool only - not investment advice. (c) 2026 Taught to Trade.
// =============================================================================
indicator("Taught to Trade - Configurable Stochastics", shorttitle = "TT Stoch", overlay = false)
// ----- MA selector ----------------------------------------------------------
f_ma(series float src, simple int len, simple string t) =>
switch t
"SMA" => ta.sma(src, len)
"EMA" => ta.ema(src, len)
"WMA" => ta.wma(src, len)
"HMA" => ta.hma(src, len)
=> ta.sma(src, len)
// ----- Inputs ---------------------------------------------------------------
grp = "Stochastic"
kLen = input.int(14, "%K length", minval = 1, group = grp)
kSmooth = input.int(3, "%K smoothing", minval = 1, group = grp)
dLen = input.int(3, "%D length", minval = 1, group = grp)
maType = input.string("SMA", "Smoothing method", options = ["SMA","EMA","WMA","HMA"], group = grp, tooltip = "How %K and %D are smoothed. HMA/WMA react faster; SMA is steadier.")
showFast= input.bool(true, "Show fast %K", group = grp)
grpL = "Levels"
obLvl = input.int(80, "Overbought", minval = 50, maxval = 100, group = grpL)
osLvl = input.int(20, "Oversold", minval = 0, maxval = 50, group = grpL)
// ----- Calculations ---------------------------------------------------------
fastK = ta.stoch(close, high, low, kLen) // raw %K, 0..100
slowK = f_ma(fastK, kSmooth, maType)
slowD = f_ma(slowK, dLen, maType)
// ----- Colors ---------------------------------------------------------------
cK = color.new(#2F6FED, 0)
cD = color.new(#E8A13C, 0)
cF = color.new(#8A8F98, 40)
// ----- Plots ----------------------------------------------------------------
plot(showFast ? fastK : na, "Fast %K", color = cF, linewidth = 1)
plot(slowK, "Slow %K", color = cK, linewidth = 2)
plot(slowD, "Slow %D", color = cD, linewidth = 2)
hline(obLvl, "Overbought", color = color.new(#C64545, 50), linestyle = hline.style_dashed)
hline(50, "Mid", color = color.new(#8A8F98, 70))
hline(osLvl, "Oversold", color = color.new(#3F8F5F, 50), linestyle = hline.style_dashed)
// ----- Signals + user alerts (no pushed buy/sell) ---------------------------
bullCross = ta.crossover(slowK, slowD) and slowK < osLvl + 10
bearCross = ta.crossunder(slowK, slowD) and slowK > obLvl - 10
plotshape(bullCross, title = "K/D up in oversold", style = shape.triangleup, location = location.bottom, color = color.new(#3F8F5F,0), size = size.tiny)
plotshape(bearCross, title = "K/D down in overbought",style = shape.triangledown, location = location.top, color = color.new(#C64545,0), size = size.tiny)
alertcondition(bullCross, "Stoch bullish cross (oversold)", "TT Stoch: %K crossed above %D from oversold on {{ticker}} ({{interval}}). Educational only - not a trade instruction.")
alertcondition(bearCross, "Stoch bearish cross (overbought)","TT Stoch: %K crossed below %D from overbought on {{ticker}} ({{interval}}). Educational only - not a trade instruction.")
Overview
Taught to Trade - Configurable Stochastics allows users to customize the smoothing method using SMA, EMA, WMA, or HMA instead of forcing standard SMA. Key input settings include %K length, %K and %D smoothing periods, and overbought or oversold threshold levels. It highlights bullish and bearish %K/%D crossovers near extreme levels with plot shapes. Line plots and signal markers update on intrabar prices and may change prior to bar close.
Customizable MA smoothing types (SMA, EMA, WMA, HMA)
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
%K length
int
14
kLen
%K smoothing
int
3
kSmooth
%D length
int
3
dLen
Smoothing method
string
SMA
maType
Show fast %K
bool
true
showFast
Overbought
int
80
obLvl
Oversold
int
20
osLvl
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.
Asymmetrical RSI is an indicator that computes a custom relative strength index from the rate of change of a user-selected source. It plots the resulting ARSI line in a separate pane with color coding that turns green above the overbought level and red below t
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 a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome
This indicator plots the Average Directional Index in a separate pane and colors the line teal or maroon according to whether plus DI is above minus DI. A horizontal key level and a silver background mark periods when ADX exceeds that threshold. With labels en
This indicator demonstrates an experimental graph-style scatter visualization within a separate pane using Pine Script arrays. It tracks two features across recent bars: the single-bar price change and a scaled 14-period Relative Strength Index. Values are loa
This script calculates and plots a Stochastic Oscillator (KD indicator) in a separate chart pane. It determines the fast stochastic value over a 9-period lookback, then applies a 3-period Simple Moving Average (SMA) to create the %K line, and a second 3-period