Quantitative Analysis · Data Science · Machine Learning

# Stochastic Oscillator

## What is the Stochastic Oscillator?

The Stochastic Oscillator is a technical analysis indicator that measures the level of the security’s price relative to its price range over a specified period of time. It is calculated using the following formula:

### %K = (Current Close – Lowest Low) / (Highest High – Lowest Low)

Where “Current Close” is the current closing price of the security, “Lowest Low” is the lowest low over the specified period of time, and “Highest High” is the highest high over the specified period of time.

The %K value is then smoothed using a moving average to create the %D line, which is the Stochastic Oscillator. The %D line is typically a 3-day moving average of the %K line. The formula for calculating the %D line is as follows:

### %D = 3-day EMA of %K

The Stochastic Oscillator is typically displayed as two lines on a chart: the %K line and the %D line. The %K line oscillates between 0 and 100, and the %D line oscillates around the 50 level.

## There are several ways that the Stochastic Oscillator can be used in an algorithmic trading strategy:

1. Overbought/oversold: One common way to use the Stochastic Oscillator is to look for overbought and oversold conditions. An overbought condition occurs when the %K line is above 80, indicating that the security may be becoming overvalued and that a price reversal may be imminent. An oversold condition occurs when the %K line is below 20, indicating that the security may be undervalued and that a price reversal may be imminent.
2. Divergence: Another way to use the Stochastic Oscillator is to look for divergences between the %K and %D lines and the security’s price. A bullish divergence occurs when the %K and %D lines are making higher lows while the security’s price is making lower lows, indicating that the security may be about to experience upward momentum. A bearish divergence occurs when the %K and %D lines are making lower highs while the security’s price is making higher highs, indicating that the security may be about to experience downward momentum.
3. Trend confirmation: The Stochastic Oscillator can also be used to confirm trends in the security’s price. If the %K and %D lines are consistently above 50 and rising, it can be taken as a sign that the security is in an uptrend. Conversely, if the %K and %D lines are consistently below 50 and falling, it can be taken as a sign that the security is in a downtrend.

It’s important to note that the Stochastic Oscillator should be used in conjunction with other technical analysis tools and fundamental analysis in order to provide a well-rounded view of a security’s market conditions.