Returns the raw stochastic: where source sits between the lowest low and highest high of the last length bars, from 0 to 100.
ta.stoch computes 100 * (source - lowestLow) / (highestHigh - lowestLow), where the extremes come from the low and high series you pass over the last length bars. It is the unsmoothed %K.
A close at the top of the range gives 100, at the bottom 0. %K starts on bar number length, when the first full range exists. A window where high equals low everywhere has no range, and the result is na.
Syntax
ta.stoch(source: series int/float, high: series int/float, low: series int/float, length: series int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | Series positioned inside the range, usually close. |
| high | series int/ | required | Series searched for the highest value, usually high. |
| low | series int/ | required | Series searched for the lowest value, usually low. |
| length | series int | required | Number of bars in the range. A whole number of 1 or more. |
Returns
series float: a value from 0 to 100, or na while the range window is not full.
Remarks
- The familiar %K and %D lines are smoothed versions:
ta.sma(ta.stoch(close, high, low, 14), 3) and an average of that.
Example
//@version=6
indicator("Stochastic")
raw = ta.stoch(close, high, low, 14)
k = ta.sma(raw, 3)
d = ta.sma(k, 3)
plot(k, "%K", color = color.blue)
plot(d, "%D", color = color.orange)
hline(80)
hline(20)See also
Runs on Sidechair