OPEN-SOURCE SCRIPT
Aggiornato Lyapunov Market Instability (LMI)

Lyapunov Market Instability (LMI)
What is Lyapunov Market Instability?
Lyapunov Market Instability (LMI) is a revolutionary indicator that brings chaos theory from theoretical physics into practical trading. By calculating Lyapunov exponents—a measure of how rapidly nearby trajectories diverge in phase space—LMI quantifies market sensitivity to initial conditions. This isn't another oscillator or trend indicator; it's a mathematical lens that reveals whether markets are in chaotic (trending) or stable (ranging) regimes.
Inspired by the meditative color field paintings of Mark Rothko, this indicator transforms complex chaos mathematics into an intuitive visual experience. The elegant simplicity of the visualization belies the sophisticated theory underneath—just as Rothko's seemingly simple color blocks contain profound depth.
Theoretical Foundation (Chaos Theory & Lyapunov Exponents)
In dynamical systems, the Lyapunov exponent (λ) measures the rate of separation of infinitesimally close trajectories:
λ > 0: System is chaotic—small changes lead to dramatically different outcomes (butterfly effect)
λ < 0: System is stable—trajectories converge, perturbations die out
λ ≈ 0: Edge of chaos—transition between regimes
Phase Space Reconstruction
Using Takens' embedding theorem, we reconstruct market dynamics in higher dimensions:
Time-delay embedding: Create vectors from price at different lags
Nearest neighbor search: Find historically similar market states
Trajectory evolution: Track how these similar states diverged over time
Divergence rate: Calculate average exponential separation
Market Application
Chaotic markets (λ > threshold): Strong trends emerge, momentum dominates, use breakout strategies
Stable markets (λ < threshold): Mean reversion dominates, fade extremes, range-bound strategies work
Transition zones: Market regime about to change, reduce position size, wait for confirmation
How LMI Works
1. Phase Space Construction
Each point in time is embedded as a vector using historical prices at specific delays (τ). This reveals the market's hidden attractor structure.
2. Lyapunov Calculation
For each current state, we:
- Find similar historical states within epsilon (ε) distance
- Track how these initially similar states evolved
- Measure exponential divergence rate
- Average across multiple trajectories for robustness
3. Signal Generation
Chaos signals: When λ crosses above threshold, market enters trending regime
Stability signals: When λ crosses below threshold, market enters ranging regime
Divergence detection: Price/Lyapunov divergences signal potential reversals
4. Rothko Visualization
Color fields: Background zones represent market states with Rothko-inspired palettes
Glowing line: Lyapunov exponent with intensity reflecting market state
Minimalist design: Focus on essential information without clutter
Inputs:
📐 Lyapunov Parameters
Embedding Dimension (default: 3)
Dimensions for phase space reconstruction
2-3: Simple dynamics (crypto/forex) - captures basic momentum patterns
4-5: Complex dynamics (stocks/indices) - captures intricate market structures
Higher dimensions need exponentially more data but reveal deeper patterns
Time Delay τ (default: 1)
Lag between phase space coordinates
1: High-frequency (1m-15m charts) - captures rapid market shifts
2-3: Medium frequency (1H-4H) - balances noise and signal
4-5: Low frequency (Daily+) - focuses on major regime changes
Match to your timeframe's natural cycle
Initial Separation ε (default: 0.001)
Neighborhood size for finding similar states
0.0001-0.0005: Highly liquid markets (major forex pairs)
0.0005-0.002: Normal markets (large-cap stocks)
0.002-0.01: Volatile markets (crypto, small-caps)
Smaller = more sensitive to chaos onset
Evolution Steps (default: 10)
How far to track trajectory divergence
5-10: Fast signals for scalping - quick regime detection
10-20: Balanced for day trading - reliable signals
20-30: Slow signals for swing trading - major regime shifts only
Nearest Neighbors (default: 5)
Phase space points for averaging
3-4: Noisy/fast markets - adapts quickly
5-6: Balanced (recommended) - smooth yet responsive
7-10: Smooth/slow markets - very stable signals
📊 Signal Parameters
Chaos Threshold (default: 0.05)
Lyapunov value above which market is chaotic
0.01-0.03: Sensitive - more chaos signals, earlier detection
0.05: Balanced - optimal for most markets
0.1-0.2: Conservative - only strong trends trigger
Stability Threshold (default: -0.05)
Lyapunov value below which market is stable
-0.01 to -0.03: Sensitive - quick stability detection
-0.05: Balanced - reliable ranging signals
-0.1 to -0.2: Conservative - only deep stability
Signal Smoothing (default: 3)
EMA period for noise reduction
1-2: Raw signals for experienced traders
3-5: Balanced - recommended for most
6-10: Very smooth for position traders
🎨 Rothko Visualization
Rothko Classic: Deep reds for chaos, midnight blues for stability
Orange/Red: Warm sunset tones throughout
Blue/Black: Cool, meditative ocean depths
Purple/Grey: Subtle, sophisticated palette
Visual Options:
Market Zones: Background fields showing regime areas
Transitions: Arrows marking regime changes
Divergences: Labels for price/Lyapunov divergences
Dashboard: Real-time state and trading signals
Guide: Educational panel explaining the theory
Visual Logic & Interpretation
Main Elements
Lyapunov Line: The heart of the indicator
Above chaos threshold: Market is trending, follow momentum
Below stability threshold: Market is ranging, fade extremes
Between thresholds: Transition zone, reduce risk
Background Zones: Rothko-inspired color fields
Red zone: Chaotic regime (trending)
Gray zone: Transition (uncertain)
Blue zone: Stable regime (ranging)
Transition Markers:
Up triangle: Entering chaos - start trend following
Down triangle: Entering stability - start mean reversion
Divergence Signals:
Bullish: Price makes low but Lyapunov rising (stability breaking down)
Bearish: Price makes high but Lyapunov falling (chaos dissipating)
Dashboard Information
Market State: Current regime (Chaotic/Stable/Transitioning)
Trading Bias: Specific strategy recommendation
Lyapunov λ: Raw value for precision
Signal Strength: Confidence in current regime
Last Change: Bars since last regime shift
Action: Clear trading directive
Trading Strategies
In Chaotic Regime (λ > threshold)
Follow trends aggressively: Breakouts have high success rate
Use momentum strategies: Moving average crossovers work well
Wider stops: Expect larger swings
Pyramid into winners: Trends tend to persist
In Stable Regime (λ < threshold)
Fade extremes: Mean reversion dominates
Use oscillators: RSI, Stochastic work well
Tighter stops: Smaller expected moves
Scale out at targets: Trends don't persist
In Transition Zone
Reduce position size: Uncertainty is high
Wait for confirmation: Let regime establish
Use options: Volatility strategies may work
Monitor closely: Quick changes possible
Advanced Techniques
- Multi-Timeframe Analysis
- Higher timeframe LMI for regime context
- Lower timeframe for entry timing
- Alignment = highest probability trades
- Divergence Trading
- Most powerful at regime boundaries
- Combine with support/resistance
- Use for early reversal detection
- Volatility Correlation
- Chaos often precedes volatility expansion
- Stability often precedes volatility contraction
- Use for options strategies
Originality & Innovation
LMI represents a genuine breakthrough in applying chaos theory to markets:
True Lyapunov Calculation: Not a simplified proxy but actual phase space reconstruction and divergence measurement
Rothko Aesthetic: Transforms complex math into meditative visual experience
Regime Detection: Identifies market state changes before price makes them obvious
Practical Application: Clear, actionable signals from theoretical physics
This is not a combination of existing indicators or a visual makeover of standard tools. It's a fundamental rethinking of how we measure and visualize market dynamics.
Best Practices
Start with defaults: Parameters are optimized for broad market conditions
Match to your timeframe: Adjust tau and evolution steps
Confirm with price action: LMI shows regime, not direction
Use appropriate strategies: Chaos = trend, Stability = reversion
Respect transitions: Reduce risk during regime changes
Alerts Available
Chaos Entry: Market entering chaotic regime - prepare for trends
Stability Entry: Market entering stable regime - prepare for ranges
Bullish Divergence: Potential bottom forming
Bearish Divergence: Potential top forming
Chart Information
Script Name: Lyapunov Market Instability (LMI) Recommended Use: All markets, all timeframes Best Performance: Liquid markets with clear regimes
Academic References
Takens, F. (1981). "Detecting strange attractors in turbulence"
Wolf, A. et al. (1985). "Determining Lyapunov exponents from a time series"
Rosenstein, M. et al. (1993). "A practical method for calculating largest Lyapunov exponents"
Note: After completing this indicator, I discovered loxx's 2022 "Lyapunov Hodrick-Prescott Oscillator w/ DSL". While both explore Lyapunov exponents, they represent independent implementations with different methodologies and applications. This indicator uses phase space reconstruction for regime detection, while his combines Lyapunov concepts with HP filtering.
Disclaimer
This indicator is for research and educational purposes only. It does not constitute financial advice or provide direct buy/sell signals. Chaos theory reveals market character, not future prices. Always use proper risk management and combine with your own analysis. Past performance does not guarantee future results.
See markets through the lens of chaos. Trade the regime, not the noise.
Bringing theoretical physics to practical trading through the meditative aesthetics of Mark Rothko
Trade with insight. Trade with anticipation.
— Dskyz, for DAFE Trading Systems
What is Lyapunov Market Instability?
Lyapunov Market Instability (LMI) is a revolutionary indicator that brings chaos theory from theoretical physics into practical trading. By calculating Lyapunov exponents—a measure of how rapidly nearby trajectories diverge in phase space—LMI quantifies market sensitivity to initial conditions. This isn't another oscillator or trend indicator; it's a mathematical lens that reveals whether markets are in chaotic (trending) or stable (ranging) regimes.
Inspired by the meditative color field paintings of Mark Rothko, this indicator transforms complex chaos mathematics into an intuitive visual experience. The elegant simplicity of the visualization belies the sophisticated theory underneath—just as Rothko's seemingly simple color blocks contain profound depth.
Theoretical Foundation (Chaos Theory & Lyapunov Exponents)
In dynamical systems, the Lyapunov exponent (λ) measures the rate of separation of infinitesimally close trajectories:
λ > 0: System is chaotic—small changes lead to dramatically different outcomes (butterfly effect)
λ < 0: System is stable—trajectories converge, perturbations die out
λ ≈ 0: Edge of chaos—transition between regimes
Phase Space Reconstruction
Using Takens' embedding theorem, we reconstruct market dynamics in higher dimensions:
Time-delay embedding: Create vectors from price at different lags
Nearest neighbor search: Find historically similar market states
Trajectory evolution: Track how these similar states diverged over time
Divergence rate: Calculate average exponential separation
Market Application
Chaotic markets (λ > threshold): Strong trends emerge, momentum dominates, use breakout strategies
Stable markets (λ < threshold): Mean reversion dominates, fade extremes, range-bound strategies work
Transition zones: Market regime about to change, reduce position size, wait for confirmation
How LMI Works
1. Phase Space Construction
Each point in time is embedded as a vector using historical prices at specific delays (τ). This reveals the market's hidden attractor structure.
2. Lyapunov Calculation
For each current state, we:
- Find similar historical states within epsilon (ε) distance
- Track how these initially similar states evolved
- Measure exponential divergence rate
- Average across multiple trajectories for robustness
3. Signal Generation
Chaos signals: When λ crosses above threshold, market enters trending regime
Stability signals: When λ crosses below threshold, market enters ranging regime
Divergence detection: Price/Lyapunov divergences signal potential reversals
4. Rothko Visualization
Color fields: Background zones represent market states with Rothko-inspired palettes
Glowing line: Lyapunov exponent with intensity reflecting market state
Minimalist design: Focus on essential information without clutter
Inputs:
📐 Lyapunov Parameters
Embedding Dimension (default: 3)
Dimensions for phase space reconstruction
2-3: Simple dynamics (crypto/forex) - captures basic momentum patterns
4-5: Complex dynamics (stocks/indices) - captures intricate market structures
Higher dimensions need exponentially more data but reveal deeper patterns
Time Delay τ (default: 1)
Lag between phase space coordinates
1: High-frequency (1m-15m charts) - captures rapid market shifts
2-3: Medium frequency (1H-4H) - balances noise and signal
4-5: Low frequency (Daily+) - focuses on major regime changes
Match to your timeframe's natural cycle
Initial Separation ε (default: 0.001)
Neighborhood size for finding similar states
0.0001-0.0005: Highly liquid markets (major forex pairs)
0.0005-0.002: Normal markets (large-cap stocks)
0.002-0.01: Volatile markets (crypto, small-caps)
Smaller = more sensitive to chaos onset
Evolution Steps (default: 10)
How far to track trajectory divergence
5-10: Fast signals for scalping - quick regime detection
10-20: Balanced for day trading - reliable signals
20-30: Slow signals for swing trading - major regime shifts only
Nearest Neighbors (default: 5)
Phase space points for averaging
3-4: Noisy/fast markets - adapts quickly
5-6: Balanced (recommended) - smooth yet responsive
7-10: Smooth/slow markets - very stable signals
📊 Signal Parameters
Chaos Threshold (default: 0.05)
Lyapunov value above which market is chaotic
0.01-0.03: Sensitive - more chaos signals, earlier detection
0.05: Balanced - optimal for most markets
0.1-0.2: Conservative - only strong trends trigger
Stability Threshold (default: -0.05)
Lyapunov value below which market is stable
-0.01 to -0.03: Sensitive - quick stability detection
-0.05: Balanced - reliable ranging signals
-0.1 to -0.2: Conservative - only deep stability
Signal Smoothing (default: 3)
EMA period for noise reduction
1-2: Raw signals for experienced traders
3-5: Balanced - recommended for most
6-10: Very smooth for position traders
🎨 Rothko Visualization
Rothko Classic: Deep reds for chaos, midnight blues for stability
Orange/Red: Warm sunset tones throughout
Blue/Black: Cool, meditative ocean depths
Purple/Grey: Subtle, sophisticated palette
Visual Options:
Market Zones: Background fields showing regime areas
Transitions: Arrows marking regime changes
Divergences: Labels for price/Lyapunov divergences
Dashboard: Real-time state and trading signals
Guide: Educational panel explaining the theory
Visual Logic & Interpretation
Main Elements
Lyapunov Line: The heart of the indicator
Above chaos threshold: Market is trending, follow momentum
Below stability threshold: Market is ranging, fade extremes
Between thresholds: Transition zone, reduce risk
Background Zones: Rothko-inspired color fields
Red zone: Chaotic regime (trending)
Gray zone: Transition (uncertain)
Blue zone: Stable regime (ranging)
Transition Markers:
Up triangle: Entering chaos - start trend following
Down triangle: Entering stability - start mean reversion
Divergence Signals:
Bullish: Price makes low but Lyapunov rising (stability breaking down)
Bearish: Price makes high but Lyapunov falling (chaos dissipating)
Dashboard Information
Market State: Current regime (Chaotic/Stable/Transitioning)
Trading Bias: Specific strategy recommendation
Lyapunov λ: Raw value for precision
Signal Strength: Confidence in current regime
Last Change: Bars since last regime shift
Action: Clear trading directive
Trading Strategies
In Chaotic Regime (λ > threshold)
Follow trends aggressively: Breakouts have high success rate
Use momentum strategies: Moving average crossovers work well
Wider stops: Expect larger swings
Pyramid into winners: Trends tend to persist
In Stable Regime (λ < threshold)
Fade extremes: Mean reversion dominates
Use oscillators: RSI, Stochastic work well
Tighter stops: Smaller expected moves
Scale out at targets: Trends don't persist
In Transition Zone
Reduce position size: Uncertainty is high
Wait for confirmation: Let regime establish
Use options: Volatility strategies may work
Monitor closely: Quick changes possible
Advanced Techniques
- Multi-Timeframe Analysis
- Higher timeframe LMI for regime context
- Lower timeframe for entry timing
- Alignment = highest probability trades
- Divergence Trading
- Most powerful at regime boundaries
- Combine with support/resistance
- Use for early reversal detection
- Volatility Correlation
- Chaos often precedes volatility expansion
- Stability often precedes volatility contraction
- Use for options strategies
Originality & Innovation
LMI represents a genuine breakthrough in applying chaos theory to markets:
True Lyapunov Calculation: Not a simplified proxy but actual phase space reconstruction and divergence measurement
Rothko Aesthetic: Transforms complex math into meditative visual experience
Regime Detection: Identifies market state changes before price makes them obvious
Practical Application: Clear, actionable signals from theoretical physics
This is not a combination of existing indicators or a visual makeover of standard tools. It's a fundamental rethinking of how we measure and visualize market dynamics.
Best Practices
Start with defaults: Parameters are optimized for broad market conditions
Match to your timeframe: Adjust tau and evolution steps
Confirm with price action: LMI shows regime, not direction
Use appropriate strategies: Chaos = trend, Stability = reversion
Respect transitions: Reduce risk during regime changes
Alerts Available
Chaos Entry: Market entering chaotic regime - prepare for trends
Stability Entry: Market entering stable regime - prepare for ranges
Bullish Divergence: Potential bottom forming
Bearish Divergence: Potential top forming
Chart Information
Script Name: Lyapunov Market Instability (LMI) Recommended Use: All markets, all timeframes Best Performance: Liquid markets with clear regimes
Academic References
Takens, F. (1981). "Detecting strange attractors in turbulence"
Wolf, A. et al. (1985). "Determining Lyapunov exponents from a time series"
Rosenstein, M. et al. (1993). "A practical method for calculating largest Lyapunov exponents"
Note: After completing this indicator, I discovered loxx's 2022 "Lyapunov Hodrick-Prescott Oscillator w/ DSL". While both explore Lyapunov exponents, they represent independent implementations with different methodologies and applications. This indicator uses phase space reconstruction for regime detection, while his combines Lyapunov concepts with HP filtering.
Disclaimer
This indicator is for research and educational purposes only. It does not constitute financial advice or provide direct buy/sell signals. Chaos theory reveals market character, not future prices. Always use proper risk management and combine with your own analysis. Past performance does not guarantee future results.
See markets through the lens of chaos. Trade the regime, not the noise.
Bringing theoretical physics to practical trading through the meditative aesthetics of Mark Rothko
Trade with insight. Trade with anticipation.
— Dskyz, for DAFE Trading Systems
Note di rilascio
Update: Removed unused Nearest Neighbors parameterQuick housekeeping update - removed the "Nearest Neighbors" input parameter as it wasn't being utilized in the current implementation. This doesn't change any functionality or calculations - the indicator continues to work exactly as before.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Empowering everyday traders | DAFE Trading Systems
DAFETradingSystems.com
DAFETradingSystems.com
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Empowering everyday traders | DAFE Trading Systems
DAFETradingSystems.com
DAFETradingSystems.com
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.