Momentum OscillatorsPine Script v6

ta.stoch()Stochastic Oscillator

Stochastic oscillator. It is calculated by a formula: 100 * (source - lowest(low, length)) / (highest(high, length) - lowest(low, length)).

TradingView language reference

Syntax

Syntax
ta.stoch(source, high, low, length) → series float

Arguments

ParameterTypeDescription
sourceseries int/floatSeries compared to the range (commonly close).
highseries int/floatHigh series for the range calculation.
lowseries int/floatLow series for the range calculation.
lengthseries intLookback length for highest/lowest range.

Returns

Stochastic.

Remarks

na source values are ignored. A zero high-low range makes the ratio undefined. The usual 0–100 interpretation assumes the source lies within the supplied range; arbitrary input series need not do so.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.stoch")
plot(ta.stoch(close, high, low, 14))

Trading Applications

Identify overbought/oversold market conditions

Generate buy/sell signals with %K/%D crossovers

Detect bullish/bearish divergences

Combine with trend analysis for filtered entries

Related Functions

Frequently Asked Questions

ta.stoch() returns the raw stochastic %K-style value for the chosen source within the high/low range over length bars, scaled to 0–100.

Call ta.stoch(close, high, low, kLength) for raw %K. For a slow stochastic, smooth raw %K first, then smooth that result for %D. Specify both smoothing lengths and methods; ta.stoch() alone does not return a %K/%D tuple.

Common defaults are about 80/20 or 70/30, but no threshold is universally optimal. Treat them as context, not automatic trade triggers.

Generate ta.stoch() Code with AI

Draft Pine Script using ta.stoch() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.