Entropy
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
| Name | Type | Default | Description |
|---|---|---|---|
| period | number | 20 | Rolling window size. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Inputs | ||
| input | number[] | Source numeric array |
| Outputs | ||
| values | number | null | Computed value at each bar; null before the warmup period completes |
| timestamps | number[] | Bar timestamps (UNIX ms), aligned 1-to-1 with values |
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.