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)).

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

None.

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.

Use ta.stoch() (or ta.stoch(close, high, low, k)) for %K, then smooth it for %D (for example with ta.sma() or ta.ema()) using your preferred signal length.

Common defaults are about 80/20 or 70/30, but optimal levels vary by symbol and timeframe. Treat them as context, not automatic trade triggers.

Generate ta.stoch() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.stoch() and other built-in functions instantly.