Skip to content

StochasticOscillator


class backtide.indicators.StochasticOscillator(k_period=14, d_period=3)

Stochastic Oscillator (STOCH).

Compares the closing price to the high-low range over a period, producing a %K line and a smoothed %D signal line. Both oscillate between 0 and 100. Useful for overbought/oversold signals, %K/%D crossovers for entry/exit timing, and divergence analysis.

Formula:

\[ \begin{aligned} \%K_t &= 100 \cdot \frac{C_t - L_n}{H_n - L_n} \\\\ \%D_t &= SMA_d(\%K_t) \end{aligned} \]

where \(H_n\) and \(L_n\) are the highest high and lowest low over \(n\) periods. Read more on Wikipedia.

Parameters

k_period : int, default=14

%K look-back period.

d_period : int, default=3
%D smoothing period.

Attributes

acronym : str

Short ticker-style acronym.

name : str
Human-readable indicator name.


See Also

CommodityChannelIndex

Commodity Channel Index (CCI).

MovingAverageConvergenceDivergence

Moving Average Convergence Divergence (MACD).

RelativeStrengthIndex

Relative Strength Index (RSI).


Methods

compute Compute the indicator on a dataset.
description Short explanation of what the indicator measures.


method backtide.indicatorscompute(data)

Compute the indicator on a dataset.

Parameters

data : np.ndarray | pd.DataFrame | pl.DataFrame

Historical OHLCV data.

Returns

np.ndarray | pd.Series | pl.Series | pd.DataFrame | pl.DataFrame

The computed values. For multi-output indicators (e.g., upper and lower bounds), return a 2d structure.



method backtide.indicatorsdescription()

Short explanation of what the indicator measures.

Returns

str

The description.