Entropy

Windowed · default period 20Statistics

The Entropy node computes Shannon entropy using uniform binning into approximately √n bins over the rolling window. High entropy means values are spread across many bins (chaotic, unpredictable); low entropy means they cluster tightly (trending, predictable). This makes Entropy a powerful market regime detector — trending markets exhibit low entropy while choppy, sideways markets exhibit high entropy.

Algorithm

  • bins = max(2, round(√n)) where n = count of non-null values
  • Divide [min, max] of window values into "bins" equal-width buckets
  • Count values per bucket and compute probabilities p_i = count_i / n
  • entropy = −Σ p_i × log₂(p_i) for all non-empty buckets
  • Returns null with fewer than 2 non-null values; returns 0 when all values are equal

Parameters

NameTypeDefaultDescription
periodnumber20Rolling window size.

Inputs & Outputs

PortTypeDescription
Inputs
inputnumber[]Source numeric array
Outputs
valuesnumber | nullComputed value at each bar; null before the warmup period completes
timestampsnumber[]Bar timestamps (UNIX ms), aligned 1-to-1 with values
Live mode: In live streaming mode the node updates only the last bar in-place rather than recalculating the full array, keeping CPU usage minimal during real-time data feeds.

Use Cases

Trend vs. Noise Filter

Gate trend-following signals when entropy is below a threshold (e.g., < 1.5 bits) — lower entropy indicates price is moving directionally rather than randomly.

Volatility Breakout Anticipation

Low entropy following a compression period (triangle, flag) often precedes a breakout. Combine with ATR or range compression for a dual-confirmation breakout filter.

Strategy Mode Switch

Use entropy to dynamically switch between trend-following (low entropy) and mean-reversion (high entropy) strategy variants in a multi-mode system.