Stochastic Divergence Alert
Dec 9, 2021

The Stochastic Divergence Alert indicator identifies potential price reversals by detecting bullish and bearish divergences between price action and the Stochastic oscillator.
Usage
The Usage section describes how the script can be used to identify trend exhaustion and potential turning points.
- Bullish Divergence: Occurs when price makes a lower low while the Stochastic %K line makes a higher low. This is specifically filtered to trigger when the previous Stochastic low was below the "Bottom Level" (oversold). A green line connects the oscillator lows to signal a potential long opportunity.
- Bearish Divergence: Occurs when price makes a higher high while the Stochastic %K line makes a lower high. This triggers when the previous Stochastic high was above the "Top Level" (overbought). A red line connects the oscillator highs to signal a potential short opportunity.
The indicator is often used in conjunction with a long-term moving average (such as a 400-period SMA) to filter signals in the direction of the primary trend.
Details
This script automates the detection of divergences by comparing current and previous "cross areas" of the Stochastic oscillator. It tracks the highest %K and highest price during bullish periods (K >= D), and the lowest %K and lowest price during bearish periods (K <= D). By storing these values and calculating the distance between crossovers, the script can accurately draw trendlines on the oscillator pane when the divergence conditions are met.
Settings
Inputs
- Period %K: The lookback period used for the initial Stochastic calculation.
- %K Smoothing: The length of the simple moving average applied to the Stochastic value to create the %K line.
- %D Smoothing: The length of the simple moving average applied to the %K line to create the signal (%D) line.
- Top Level: The overbought threshold used to validate bearish divergences (default is 70).
- Bottom Level: The oversold threshold used to validate bullish divergences (default is 30).
FAQ
How do I use the alerts?
You can set up alerts using the "Any alert() function call" condition or by selecting the specific "Long_k" and "Short_k" alert conditions in the TradingView alert menu.
Which timeframe is best for this indicator?
While it can be used on any timeframe, it is frequently utilized on lower timeframes like the 1m chart for scalp setups when combined with higher-period trend filters.
How can I access Stochastic Divergence Alert?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.