Inertial Stochastic [LuxAlgo]The Inertial Stochastic indicator introduces a novel approach to oscillator smoothing by implementing "Forced Persistence," a technique that achieves stability at the mathematical source rather than through traditional lagging filters. By dynamically optimizing the lookback period on every bar to minimize the variation between consecutive values, the tool effectively creates an inertial effect that resists erratic market noise and "sawtooth" fluctuations. This provides a significant advantage over standard oscillators, as it maintains a high degree of smoothness and trend coherence without the heavy group delay typically introduced by long-period moving averages, allowing traders to stay positioned in trends while identifying overbought or oversold conditions with greater clarity.
🔶 USAGE
The indicator is used similarly to a standard Stochastic oscillator but with significantly reduced noise and more stable transitions. It helps traders identify momentum and overbought/oversold conditions while maintaining a more consistent trajectory, making it easier to interpret the underlying market trend without being shaken out by minor price jitters.
🔹 Forced Persistence
Traditional oscillators achieve smoothness by applying lagging filters (like moving averages) to a fixed-length calculation. The Inertial Stochastic introduces the concept of "Forced Persistence," where smoothing is achieved by selecting the input data dynamically. By selecting the lookback length that results in the smallest change from the previous bar, the oscillator "forces" itself to remain stable. This allows the indicator to stay at extreme levels during strong trends or transition smoothly during reversals without the typical noise found in fixed-length oscillators.
🔹 Interpretation
K Line (Solid): Represents the primary smoothed inertial stochastic. It changes color based on whether it is above or below the 50 centerline (Bullish/Bearish).
D Line (Dotted): A signal line calculated as a simple moving average of the K line, used to identify potential local crossovers.
Zones: The area between the K line and the 50 level is filled with a gradient to highlight the strength and direction of the current momentum.
🔶 DETAILS
The core logic of the script is an optimization loop that runs on every bar. Instead of using one fixed value for N (the lookback period), the algorithm evaluates every possible integer length within the user-defined range (from Minimum Length to Maximum Length).
For each potential length, the script calculates a raw Stochastic value. It then measures the absolute difference between that candidate value and the final output from the previous bar. The algorithm "hunts" for the specific length that minimizes this difference:
Best Stoch = min(|Current Candidate(N) - Previous Final Stoch|)
By selecting the value that is most similar to the previous one, the indicator effectively filters out market noise by choosing a lookback window that "agrees" with the current trend's inertia. This methodology allows the oscillator to be responsive to major price shifts while ignoring minor fluctuations that do not significantly alter the lookback's internal range.
🔶 SETTINGS
🔹 Settings
Minimum Length: The shortest lookback period the algorithm can consider for the optimization loop.
Maximum Length: The longest lookback period the algorithm can consider. A wider range between min/max allows for more "inertia" but increases computational intensity.
K Smoothing: The length of the SMA used to provide a final aesthetic smoothing to the inertial stochastic value.
D Smoothing: The length of the SMA used to create the signal (D) line from the K line.
🔹 Visuals
Bullish Color: Defines the color of the K line and the upper gradient fill when the value is above 50.
Bearish Color: Defines the color of the K line and the lower gradient fill when the value is below 50.
Pine Script® Indikator






















