Adaptive Entropy Trend [QuantAlgo]🟢 Overview
Adaptive Entropy Trend is a trend-following indicator built on Shannon information theory rather than conventional price averaging. It quantifies the statistical disorder of recent log returns to determine whether the market is in a directional regime or a random one, then feeds this entropy reading into every layer of the system simultaneously, helping traders identify directional shifts that are validated by both low-entropy momentum conditions and genuine volatility expansion across different timeframes and markets.
🟢 How It Works
The foundation of the indicator is a per-bar entropy calculation built from the distribution of log returns over the lookback window. Log returns are computed and their range is divided into equal-width histogram bins:
logReturn = math.log(close / close )
minReturn = ta.lowest(logReturn, lookbackLen)
maxReturn = ta.highest(logReturn, lookbackLen)
returnRange = maxReturn - minReturn
Each historical return within the lookback is assigned to a bin, building a frequency distribution. Shannon entropy is then calculated from the probability of each bin, measuring how uniformly returns are spread across the range:
probability = array.get(binCounts, i) / lookbackLen
if probability > 0
entropy := entropy - probability * math.log(probability) / math.log(2)
A uniform distribution produces maximum entropy, reflecting a chaotic, non-directional market. A concentrated distribution produces low entropy, reflecting a market where returns are clustering in a consistent direction. The raw entropy is normalized against the theoretical maximum for the bin count to produce a stable 0-1 score:
normalizedEntropy = maxEntropy > 0 ? entropy / maxEntropy : 0.5
This score is then wired directly into the EMA smoothing factor. Higher entropy lengthens the effective period of the EMA, insulating it from noise. Lower entropy shortens it, allowing the EMA to track price closely during genuine trends:
adaptiveAlpha = 2.0 / (lookbackLen * (0.3 + normalizedEntropy * 1.4) + 1.0)
adaptiveEma := na(adaptiveEma) ? close : adaptiveEma + adaptiveAlpha * (close - adaptiveEma)
The same entropy reading drives band width through an inverted trend strength factor. Unlike volatility-based bands that widen during noise, these bands widen specifically during trending conditions and tighten during choppy ones:
trendStrength = 1.0 - normalizedEntropy
fastBandWidth = atr * fastMultiplier * (0.5 + trendStrength)
slowBandWidth = atr * slowMultiplier * (0.5 + trendStrength)
Finally, trend state is determined when price breaks beyond the inner bands, and transitions are tracked for alert conditions:
if close > innerUpper
trendDirection := 1
else if close < innerLower
trendDirection := -1
trendTurnedBullish = trendDirection == 1 and trendDirection != 1
trendTurnedBearish = trendDirection == -1 and trendDirection != -1
This creates a self-regulating trend system where the EMA baseline, the trigger threshold, and the visual envelope all adapt together from the same entropy source, rather than using a fixed center with adaptive edges or vice versa.
🟢 Signal Interpretation
▶ Bullish Trend (Price Above Inner Upper Band, Green): When price closes above the inner upper band, the indicator switches to bullish mode with bullish coloring across all visual elements = Confirmed uptrend signal for trend-following long positions. Because the inner band expands in low-entropy trending conditions, a bullish confirmation in a genuinely directional market requires a more meaningful breakout than in a noisy one. The trend remains bullish until price breaks below the inner lower band, allowing traders to stay positioned through normal pullbacks that remain within the band range.
▶ Bearish Trend (Price Below Inner Lower Band, Red): When price closes below the inner lower band, the indicator switches to bearish mode with bearish coloring throughout all visual elements = Confirmed downtrend signal for short positions or long exit signals. The adaptive band floor ensures the trigger threshold in choppy, high-entropy markets is tighter, reducing the risk of false breakdowns on thin directional moves. The trend remains bearish until price breaks above the inner upper band.
▶ Neutral Zone (Price Between Inner Bands): When price trades between the inner upper and lower bands, the indicator holds its previous trend direction = Continuation of existing trend during consolidation or normal volatility retracements. This prevents whipsaws during sideways action by requiring price to make a statistically meaningful move beyond the entropy-scaled band boundaries rather than reacting to minor crosses of the adaptive EMA centerline.
🟢 Features
▶ Preconfigured Presets: Three optimized parameter sets for different trading approaches and timeframes. "Default" provides balanced trend detection for swing trading on 4-hour and daily charts, "Fast Response" delivers quicker trend signals for intraday trading on 1-minute to 1-hour charts, and "Smooth Trend" focuses on major trend changes for position trading on daily to weekly timeframes.
▶ Built-in Alerts: Three alert conditions enable automated monitoring of trend changes without constant chart watching. "Bullish Trend Signal" triggers when the indicator switches to bullish mode after price breaks above the inner upper band, alerting for potential long entries. "Bearish Trend Signal" activates when the indicator switches to bearish mode after price breaks below the inner lower band, signaling potential short entries or long exits. "Trend Direction Changed" provides a combined alert for any trend transition regardless of direction, allowing traders to monitor both bullish and bearish opportunities with a single alert setup.
▶ Visual Customization: Six color presets (Classic, Aqua, Cosmic, Cyber, Neon, plus Custom) accommodate different chart backgrounds and aesthetic preferences, with coordinated bullish, bearish, and neutral color schemes applied across all indicator elements. Inner and outer band fills create a two-layer gradient envelope around the adaptive EMA, with the inner zone between the two bands rendered slightly more transparent than the outer zone to preserve natural depth, both controlled by a single fill transparency input (0-100%) so the visual weight of the envelope can be adjusted without disrupting the gradient relationship. Optional bar coloring tints price bars with trend-appropriate colors during bullish and bearish periods, enabling instant visual confirmation of trend state across multiple timeframes without switching between chart and indicator panels.
อินดิเคเตอร์ Pine Script®






















