OPEN-SOURCE SCRIPT

Entropy Oscillator [JOAT]

364
ENTROPY OSCILLATOR [JOAT]

A pane oscillator that measures the Shannon entropy of recent returns — the information-theoretic measure of how uncertain (chaotic) vs how predictable (directional) the recent distribution of price moves has been. Low entropy = the market is in a directional regime; high entropy = the market is chopping. Unlike volatility, entropy does not care about how big moves are — only how concentrated their distribution is. That distinction is what makes it one of the cleanest regime-classification tools in quantitative finance.

สแนปชอต

Shannon entropy, applied to markets

For a sequence of N recent log returns, the script:

  1. Bins the returns into B equal-width bins across the empirical range.
  2. Computes the probability of each bin (count / N).
  3. Computes the Shannon entropy: H = −Σ p(i) · log(p(i)) over non-zero bins.
  4. Normalises to [0, 1] by dividing by log(B) — the maximum possible entropy for B bins, which corresponds to a perfectly uniform distribution.


A perfectly uniform distribution (returns evenly spread across all bins → chaotic chop) produces normalised entropy of 1.0. A perfectly concentrated distribution (all returns in one bin → directional regime) produces entropy of 0. Real markets sit in between, and the script's job is to tell you where.

Two-threshold regime classification

  • Normalised entropy < low threshold (default 0.30) → DIRECTIONAL regime. The distribution of returns is concentrated; momentum tools work.
  • Normalised entropy > high threshold (default 0.70) → CHOP regime. The distribution is spread; reversion tools work.
  • Between the thresholdsMIXED regime. Neither side has the edge.


The thresholds are the spec-default institutional values; tighten or loosen for your instrument.

Slope-coloured entropy line

The smoothed entropy series is plotted in the pane with a slope-driven colour gradient — bull colour when entropy is falling toward directional, bear colour when entropy is rising toward chop. At a glance you can see which way the regime is moving even before it has crossed a threshold.

Visual system (pane + chart overlay)

In the pane:

  • Slope-coloured entropy line.
  • Threshold lines at low / 0.5 / high (toggleable).
  • Translucent fill zones for the low and high regions.
  • Pane background tint by current regime (toggleable).


On the chart (force_overlay):

  • Bar colouring — chart bars tinted by regime (cool when directional, hot when chop, neutral when mixed). Off by default.
  • Overlay background — subtle bgcolor projected onto the main chart marking the current regime. Off by default.


A locked Crimson Pulse palette (electric blue directional / lime-yellow chop / muted mauve mixed on a crimson-black ground) gives the pane a distinctive structural identity.

Regime Suggestion dashboard row

Like its sister script Hurst Regime Sentinel, Entropy Oscillator exposes a Suggested JOAT Indicator row that names the best companion script for the current regime. Defaults: AlphaTrend / Kalman Quantum Drift / Doppler Velocity Shift family for Directional regimes; Z-Score Reversion / Heisenberg Uncertainty Bands / Brownian Motion Residual / Renaissance Mean Reversion for Chop; Liquidity Magnet / Schrödinger Zone Probability / Fractal Dimension Index for Mixed. Every suggestion is user-configurable — you pick from the JOAT suite which tool the dashboard recommends per regime.

Dashboard

Monospaced table positionable to any of nine corners. Surfaces:

  • Current normalised entropy value.
  • Smoothed entropy and its slope direction.
  • Regime classification.
  • Bars in current regime.
  • Distance from entropy to nearest threshold.
  • Source series + window length + bin count in use.
  • Suggested JOAT Indicator (toggleable).


Alerts

Three alert conditions, each independently controllable:

  • Cross into Low Entropy (directional regime entry).
  • Cross into High Entropy (chop regime entry).
  • Any Regime Change (any classification flip).


สแนปชอต

How to read it

Two reads, in order of conviction:

  1. Entry into Low Entropy — the directional commitment signal. The recent distribution of returns has narrowed; the market is in a momentum regime. Pair with a directional indicator (the dashboard's suggestion row tells you which).
  2. Entry into High Entropy — the chop confirmation signal. Returns are widely distributed; momentum tools whipsaw, reversion tools work. Pair with a reversion indicator.


The "slope of entropy" itself is the leading read — when the line is falling toward the low threshold, a directional regime is forming; when it is rising toward the high threshold, chop is building. You do not need to wait for the threshold cross if you trust the slope gradient.

Suggested settings

Defaults (window 50 returns, 10 bins, EMA smoothing 3) are tuned for 15m–4H on liquid markets. The rule of thumb is window / bins ≥ 5 so each bin has enough samples to be statistically meaningful. For lower timeframes drop window to 30 and bins to 6. For HTF raise window to 100 and bins to 12.

Originality / what's reused

Shannon entropy is textbook 1948 information theory — public domain. The implementation here — the rolling N-return histogram pipeline with configurable bins, the log(B)-normalised entropy formula, the two-threshold regime classifier with mixed centre, the slope-coloured entropy line, the chart-overlay bar-colouring projection from the pane, and the user-configurable Suggested JOAT Indicator dashboard row — is JOAT-original. No third-party code reused.

Open source

Published open-source under the default Mozilla Public License 2.0. The histogram + entropy loop, the regime classifier, the slope-colour pipeline, and the dashboard are isolated modules. Forks welcome with credit.

Limitations

Shannon entropy describes the recent distribution of returns — it does not predict direction. A directional regime tells you momentum tools should work; it does not say which way. The histogram is sensitive to bin count and window length; the rule-of-thumb window / bins ≥ 5 is the default sanity check. EMA smoothing trades some lag for substantially reduced flicker; turn smoothing to 1 to see raw entropy.



-made with passion by jackofalltrades

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน