Indicator · Pine Script v6 · Own pane

Taught to Trade - Configurable Stochastics

by obekheet

This indicator calculates and plots a stochastic oscillator in a separate pane with exposed fast %K, slow %K, and slow %D lines.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv6current
Lines of code74
Settings7inputs
LicenceMPL-2.0
Last update12 days ago16 Oct 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

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.

Details

Published by

obekheet on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Topics

pine-scriptpinescripttechnical-analysistrading-indicatorstradingviewtradingview-indicators

Settings

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

SettingTypeDefaultVariable
%K lengthint14kLen
%K smoothingint3kSmooth
%D lengthint3dLen
Smoothing methodstringSMAmaType
Show fast %KbooltrueshowFast
Overboughtint80obLvl
Oversoldint20osLvl
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

Asymmetrical RSI

by everget
948 stars

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

Indicator v4 Oscillators & momentum
Updated 10 days ago · GPL-3.0 GitHub repository of Asymmetrical RSI

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

Beep Boop

by magic8bot
409 stars

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

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
261 stars

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

Indicator v4 Oscillators & momentum
Updated 4 years ago · None stated GitHub repository of Example: Graph Style - 4th Dimension RSI

KD指標

by TaichiS
219 stars

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

Indicator v4 Oscillators & momentum
Updated 5 years ago · None stated GitHub repository of KD指標

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers