Docs

ta.stoch

Place the close within the recent high to low range as a raw 0 to 100 oscillator.

itm
ta.stoch(source, length, bars)

Raw, unsmoothed stochastic %K: 100 * (source - lowest(low, length)) / (highest(high, length) - lowest(low, length)), the high and low read from bars. They come from the bar handle, not from arguments. Smooth it yourself: ta.sma(ta.stoch(close, 14), 3) is the customary %K.

Parameters

A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.

NameKindTypeUnitDefaultRangeDescription
sourceSeriesnumber---The series measured against the range. Use close for the classic %K.
lengthConstantnumber-141 to 10000Window in observed bars.
barsConstantbarsbarsna-Which bars to read: a declared series, or na for the chart's own.

Output

NameTypeUnit
valuenumber-

Warm-up and missing values

Warm-up
length bars. Names in the warm-up are this operator’s parameters.
Missing values
Returns na until length consecutive bars with a usable high and low have been observed. An na resets the accumulation. na when the window's high equals its low, because a position inside a zero-width range is undefined.

Example

itm
ta.stoch(close, 14)
itm
plot(ta.sma(ta.stoch(close, 14), 3), "Stochastic 14")