Indicator · Pine Script v4 · Own pane

Stochastic

by everget

This indicator calculates an enhanced Stochastic Oscillator in a separate pane using smoothed %K and %D lines based on customizable periods and source data.

View on GitHub

GitHub stars948on the repository
Pine versionv4older, still runs
Lines of code57
Settings13inputs
LicenceGPL-3.0
Last update10 days ago18 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

57 lines of Pine Script v4 from oscillators/stochastic.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

stochastic.pine
//@version=4
// Copyright (c) 2021-present, Alex Orekhov (everget)
// Stochastic script may be freely distributed under the terms of GPL-3.0 license.
study("Stochastic", shorttitle="Stoch", precision=2)

periodK = input(title="K", minval=1, defval=14)
periodD = input(title="D", minval=1, defval=3)
smoothK = input(title="Smooth", minval=1, defval=3)
src = input(title="Source", type=input.source, defval=close)

obLevel = input(title="Overbought Level", type=input.integer, defval=80)
osLevel = input(title="Oversold Level", type=input.integer, defval=20)
maxLevel = input(title="Max Level", type=input.integer, defval=100)
minLevel = input(title="Min Level", type=input.integer, defval=0)
showHistogram = input(title="Show Histogram ?", type=input.bool, defval=false)
highlightBreakouts = input(title="Highlight Overbought/Oversold Breakouts ?", type=input.bool, defval=true)
highlightCrossovers = input(title="Highlight K/D Crossovers ?", type=input.bool, defval=true)
highlightMiddleCrossovers = input(title="Highlight Middle Line Crossovers ?", type=input.bool, defval=true)
applyRibbonFilling = input(title="Apply Ribbon Filling ?", type=input.bool, defval=true)

k = sma(stoch(src, high, low, periodK), smoothK)
d = sma(k, periodD)

trendColor = k > d ? #0ebb23 : color.red
kColor = applyRibbonFilling ? trendColor : #ff3e7d
dColor = applyRibbonFilling? trendColor : #3c78d8

kPlot = plot(k, title="%K", color=kColor, transp=0)
dPlot = plot(d, title="%D", color=dColor, transp=0)

hist = k - d
histColor = hist >= 0 ? hist[1] < hist ? #26A69A : #B2DFDB : hist[1] < hist ? #FFCDD2 : #EF5350
plot(showHistogram ? hist : na, title="Histogram", style=plot.style_columns, color=histColor, transp=0)

var color noneColor = color.new(color.white, 100)

maxLevelPlot = hline(maxLevel, title="Max Level", linestyle=hline.style_dotted, color=noneColor)
obLevelPlot = hline(obLevel, title="Overbought Level", linestyle=hline.style_dotted, color=#00796b)
hline(50, title="Middle Level", linestyle=hline.style_dotted, color=#989898)
osLevelPlot = hline(osLevel, title="Oversold Level", linestyle=hline.style_dotted, color=#f57f17)
minLevelPlot = hline(minLevel, title="Min Level", linestyle=hline.style_dotted, color=noneColor)
fill(obLevelPlot, osLevelPlot, title="Middle Zone", color=color.purple, transp=95)

obFillColor = k > obLevel and highlightBreakouts ? color.green : na
osFillColor = k < osLevel and highlightBreakouts ? color.red : na

fill(maxLevelPlot, obLevelPlot, title="Upper Band Breakout", color=obFillColor, transp=85)
fill(minLevelPlot, osLevelPlot, title="Lower Band Breakout", color=osFillColor, transp=85)

fillColor = applyRibbonFilling ? trendColor : na
fill(kPlot, dPlot, title="Ribbon", color=fillColor, transp=70)

middleCrossBgColor = highlightMiddleCrossovers ? (k > 50 ? color.green : color.red) : na
bgcolor(middleCrossBgColor, transp=90)

plotshape(highlightCrossovers and crossover(k, d) ? k : na, title="K/D Crossover", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(highlightCrossovers and crossunder(k, d) ? k : na, title="K/D Crossunder", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)

Overview

Stochastic visualizes momentum and trend shifts through optional ribbon filling between lines, a difference histogram, shapes at %K and %D crossovers, and background coloring for 50-level crosses. It also highlights overbought and oversold breakouts above or below defined thresholds. Inputs allow complete customization of periods, levels, and visual toggles.

Details

Published by

everget on GitHub

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinepinescripttechnical-indicatorsindicatorsoscillatorbandsaveragetradingviewindicatormoving-average

Settings

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

SettingTypeDefaultVariable
Kint14periodK
Dint3periodD
Smoothint3smoothK
Sourcesourceclosesrc
Overbought Levelint80obLevel
Oversold Levelint20osLevel
Max Levelint100maxLevel
Min Levelint0minLevel
Show Histogram ?boolfalseshowHistogram
Highlight Overbought/Oversold Breakouts ?booltruehighlightBreakouts
Highlight K/D Crossovers ?booltruehighlightCrossovers
Highlight Middle Line Crossovers ?booltruehighlightMiddleCrossovers
Show all 13 settings
SettingTypeDefaultVariable
Apply Ribbon Filling ?booltrueapplyRibbonFilling
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

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指標

ADX Histogram

by harryguiacorn
219 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram

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