OPEN-SOURCE SCRIPT
Sample Entropy (SampEn) Regime Detector

Sample Entropy (SampEn) Regime Detector (V6)
This indicator introduces Sample Entropy (SampEn) to TradingView—a sophisticated complexity measure used in algorithmic trading and academia to quantify how predictable or chaotic price behavior is. Unlike Approximate Entropy (ApEn), SampEn eliminates self-matching bias, making it far more reliable for financial time series.
How it works:
The indicator analyzes a rolling window of price action to find repeating patterns.
Low SampEn (Green Background): Indicates high regularity. The market is in a structured phase (strong trend or clean mean-reversion). Your standard strategies (RSI, MACD, Moving Averages) are most effective here.
High SampEn (Red Background): Indicates pure randomness or "Chop." The market lacks a tradable pattern. This is where most "fake-outs" happen.
Adaptive EMA (Yellow Line): This is a dynamic moving average that adjusts its smoothing based on entropy. In predictable regimes, it tightens to track price; in chaotic regimes, it slows down to filter out noise.
How to use it:
Regime Filter: Use the background colors as a "Traffic Light." Only take trades when the background is Green (Predictable) or neutral.
Risk Management: If the SampEn Score (top right) is above 2.0, consider reducing your position size or tightening your Stop-Loss, as the market is entering a high-noise phase.
Breakout Confirmation: A sudden drop in entropy (shifting from Red to Green) often signals the start of a massive, organized move.
Key Features:
V6 Engine: Optimized for the latest Pine Script performance.
Adaptive Smoothing: EMA speed changes bar-by-bar based on market chaos.
Professional Alerts: Built-in alerts for regime changes to reduce screen fatigue.
This indicator introduces Sample Entropy (SampEn) to TradingView—a sophisticated complexity measure used in algorithmic trading and academia to quantify how predictable or chaotic price behavior is. Unlike Approximate Entropy (ApEn), SampEn eliminates self-matching bias, making it far more reliable for financial time series.
How it works:
The indicator analyzes a rolling window of price action to find repeating patterns.
Low SampEn (Green Background): Indicates high regularity. The market is in a structured phase (strong trend or clean mean-reversion). Your standard strategies (RSI, MACD, Moving Averages) are most effective here.
High SampEn (Red Background): Indicates pure randomness or "Chop." The market lacks a tradable pattern. This is where most "fake-outs" happen.
Adaptive EMA (Yellow Line): This is a dynamic moving average that adjusts its smoothing based on entropy. In predictable regimes, it tightens to track price; in chaotic regimes, it slows down to filter out noise.
How to use it:
Regime Filter: Use the background colors as a "Traffic Light." Only take trades when the background is Green (Predictable) or neutral.
Risk Management: If the SampEn Score (top right) is above 2.0, consider reducing your position size or tightening your Stop-Loss, as the market is entering a high-noise phase.
Breakout Confirmation: A sudden drop in entropy (shifting from Red to Green) often signals the start of a massive, organized move.
Key Features:
V6 Engine: Optimized for the latest Pine Script performance.
Adaptive Smoothing: EMA speed changes bar-by-bar based on market chaos.
Professional Alerts: Built-in alerts for regime changes to reduce screen fatigue.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.