ta.stoch
Place the close within the recent high to low range as a raw 0 to 100 oscillator.
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.
| Name | Kind | Type | Unit | Default | Range | Description |
|---|---|---|---|---|---|---|
source | Series | number | - | - | - | The series measured against the range. Use close for the classic %K. |
length | Constant | number | - | 14 | 1 to 10000 | Window in observed bars. |
bars | Constant | bars | bars | na | - | Which bars to read: a declared series, or na for the chart's own. |
Output
| Name | Type | Unit |
|---|---|---|
value | number | - |
Warm-up and missing values
- Warm-up
lengthbars. Names in the warm-up are this operator’s parameters.- Missing values
- Returns na until
lengthconsecutive 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
ta.stoch(close, 14)plot(ta.sma(ta.stoch(close, 14), 3), "Stochastic 14")