Stochastic oscillator
All indicators

LibraryMomentum

Indicator

Stochastic oscillator

Where the close sits within the high to low range of the last bars, from 0 at the lowest low to 100 at the highest high.

MomentumOwn pane3 inputsStoch

How it is calculated

The raw %K is 100 times the close minus the lowest low, divided by the highest high minus the lowest low, over the %K length. The %K line is an SMA of the raw %K over the %K smoothing, %D an SMA of %K over the %D length; a smoothing of 1 leaves the value raw. A range of zero gives a raw %K of 0. %K is held back until %D has a value, so both lines start on the same bar. As TA-Lib STOCH with SMA smoothing, after Lane.

Reference: TA-Lib STOCH with SMA smoothing (Lane)

How to read it

Above 80 the close is near the top of its recent range, below 20 near the bottom. In a trend the lines can stay at an extreme for a long time, so %K crossing %D, or a return across 80 or 20, says more than the level. Divergences between price and %K hint at a fading move. It reacts fast and gives many false turns in a choppy market.

In a strategy

A mean reversion entry when %K crosses above %D below 20: ctx.ind("stoch", length=14, smooth_k=3, smooth_d=3) gives .k and .d; compare both with the previous bar, and take longs only in the direction of the trend on a higher timeframe.

Inputs

InputTypeDefaultRange or choices
%K lengthlengthWhole number14min 1, max 5000
%K smoothingsmooth_kWhole number3min 1, max 5000
%D lengthsmooth_dWhole number3min 1, max 5000

What it draws

LineDrawn as
%KLine
%DLine

Moves between 0 and 100. Guide lines at 20, 80.

Used in

No strategy template reads it yet.

OrionQuant