← Back to Home
Trading Signal / Indicator
🎒

Stochastic Oscillator

Compare closing price to its range to detect momentum shifts.

Start Automating Free β†’

Want to automate this strategy? Try auto-Trading free β€” no credit card required.

Stochastic Oscillator chart

Overview

What is Stochastic Oscillator?

The Stochastic Oscillator, developed by George Lane in the 1950s, measures the closing price relative to the high-low range over a specified period. The premise is that in uptrending markets, prices tend to close near the high of the range, and in downtrending markets near the low. Divergence from this pattern signals a potential reversal.

The indicator consists of two lines: %K (the raw oscillator = (Current Close βˆ’ Lowest Low) Γ· (Highest High βˆ’ Lowest Low) Γ— 100) and %D (a 3-period SMA of %K, which acts as the signal line). Both oscillate between 0 and 100. Readings above 80 indicate overbought conditions; below 20 indicates oversold.

Trading signals include: %K crossing above %D from below in the oversold zone (bullish), %K crossing below %D from above in the overbought zone (bearish), and divergence between the oscillator and price. The "Stoch RSI" variant applies the stochastic formula to RSI values rather than price, making it even more sensitive for short-term trading.

Like RSI, the Stochastic works best in ranging markets and should be used with a trend filter in trending environments to avoid shorting strong uptrends or buying into strong downtrends.

How It Works in auto-Trading

Automate It

auto-Trading computes both Fast Stochastic (%K, %D) and Slow Stochastic (which applies additional smoothing). The strategy builder supports %K/%D crossover signals, overbought/oversold threshold alerts, and divergence detection. Users configure the lookback period (default 14) and smoothing periods through the properties panel.

Try Free β†’

Strategy Code

Pick a script below, copy it, and use it on your chart.

Pine Script (TradingView)

This is a TradingView Pine Script example for this indicator. Paste it into the TradingView Pine Editor, add it to your chart, and adjust inputs for your market and timeframe.

//@version=6
strategy("Stochastic Oscillator", overlay=true)
length = input.int(14, "Length")
smooth = input.int(3, "Smoothing")
k = ta.sma(ta.stoch(close, high, low, length), smooth)

Get full strategy code access

Enter your email address and full name to unlock this strategy code.

ThinkScript (thinkorswim)

This is a thinkorswim ThinkScript example for this indicator. Open thinkorswim, create a custom study, paste the script, and apply it to your chart.

def k = StochasticFull()."FullK";
def d = StochasticFull()."FullD";
def buySignal = k crosses above d and k < 25;
def sellSignal = k crosses below d and k > 75;
AddOrder(OrderType.BUY_AUTO, buySignal, close, 1, Color.GREEN, Color.GREEN, "Stoch Buy");

Get full strategy code access

Enter your email address and full name to unlock this strategy code.

Ready to automate Stochastic Oscillator?

Join thousands of traders who use auto-Trading to execute this strategy automatically, 24/7.

Get Started Free β†’

All Strategies & Signals

Continue Learning

Trading Strategies

Trading Signals & Indicators