OPEN-SOURCE SCRIPT
已更新

Permutation Entropy Complexity Oscillator

216
Permutation Entropy — Complexity Oscillator

What this script does

This is a complexity oscillator: it measures, on a 0–1 scale, how random versus structured recent price action is — not which direction price is going, but whether there is any exploitable order to go on. It reads the order of successive moves (not their size): every three consecutive prices form one of six up/down shapes ("ordinal patterns"), and the oscillator measures how evenly those shapes are spread over a rolling window. Near 1, all shapes are equally likely — the tape is effectively random. Near 0, a few shapes dominate — the tape is structured and, in principle, more predictable.

Why these components are combined (mashup justification)

This is not several indicators shown side by side. There is exactly one plotted value — the normalized ordinal-pattern entropy — and every other element is a decision-support layer built on that single value:

The entropy engine is the core. Conventional price-level oscillators tell you where price is in its range; none of them tell you whether the range is even worth trading. Ordinal-pattern entropy is amplitude-free and noise-robust, so it isolates one orthogonal question — is there structure right now? — that the price-level family cannot answer.
The predictable / random thresholds classify the reading into a regime (structured / mixed / random). They don't add a second indicator; they interpret the one oscillator.
The statistical-complexity measure (complexity–entropy plane) is computed from the same ordinal-pattern counts and answers the question entropy cannot: low entropy alone can be genuinely structured or trivially degenerate (near-periodic). Pairing entropy with complexity separates "richly structured and potentially exploitable" from "low-entropy but trivial," so a signal only treats the tape as structured when both agree.
The momentum sign does nothing on its own — it only sets the direction of an already-armed regime signal. The bet is "a structured tape tends to keep doing what it's doing"; momentum just says which way that is.
The calibration harness is the reason the rest is trustworthy. It logs every signal the oscillator arms and, a fixed horizon later, checks whether price actually extended ≥ k×ATR in that direction — then reports Hit %, the unconditional Base %, and the Edge (Hit − Base).


Every part answers one question about the same entropy reading, which is why they belong in one script rather than as separate studies.

What makes it original

Two things. First, it brings an information-theoretic structure measure — usually seen only in research, not on charts — into a live, bounded oscillator with regime bands and a clean visual. Second, and more importantly, it does not assume the common claim that "low entropy means predictable, tradeable price." It tests that claim, live, on your instrument, with the built-in calibration harness. If low-entropy signals don't actually precede a forward move on your symbol and timeframe, the Edge row shows it plainly — often at or below zero. That honesty layer, not the entropy calculation alone, is the contribution.

How to use it


Add to a chart. Defaults target intraday index futures (e.g. NSE NIFTY); for other markets simply change the chart, or set the Price source input (group 01) — you can even feed it another indicator's output.
Read the regime at a glance from the background tint: green = genuine structure (low entropy and high complexity → the actionable state), amber = low-complexity / trivial low entropy (caution), grey = random / efficient tape (stand aside), no tint = mixed (wait). The line carries the same colour, with a bright line confirming genuine structure; the dashboard "Tape (plane)" chip shows the same state in words.
Optionally enable the statistical-complexity overlay (group 05) to see the complexity–entropy plane directly: it peaks at intermediate entropy where structure is richest and falls toward zero for both pure noise and trivial tapes. The dashboard shows the live complexity value and a ● when it clears the genuine-structure threshold.
Tie-robustness and delay τ (group 02): on discrete / tick-quantised instruments (index futures, where equal consecutive prints are common) equal values bias ordinal-pattern entropy toward false structure. The tie-robust dither (on by default) and an optional delay τ > 1 mitigate this; τ also probes a coarser timescale. Set τ = 1 and tie-robust off to reproduce the plain estimator.
Triangles mark the moment a predictable regime starts, with direction set by recent momentum — points to investigate, not automatic entries. With the complexity gate on (default), a signal only arms when complexity also confirms genuine structure; turn it off to A/B that choice against the entropy-only signal in the Edge row.
Read the Edge row before trusting the signal. A positive Edge means structured starts preceded a forward move more often than chance here; near or below zero means low entropy is not buying you predictability on this instrument.
Window length, smoothing, embedding delay, the two entropy thresholds, the complexity threshold, the momentum length, and the calibration horizon / threshold are all configurable.


Limitations

Entropy describes the tape's structure, not its direction — low entropy can precede a clean trend or a clean oscillation. The momentum-direction bet is one testable interpretation, not a law; the calibration row is there precisely so you don't take it on faith.
Statistics are in-sample, close-to-close, without costs — a study aid, not a backtest.
The reading needs a full window before it is meaningful (the panel shows "warm" until then).
This is an analytical complexity study. It issues no automated buy/sell instructions and is not a strategy.


Concept credit

Permutation entropy / ordinal-pattern analysis — Christoph Bandt and Bernd Pompe (2002).
Information entropy — Claude E. Shannon (1948).
Statistical complexity (the complexity–entropy plane) — the MPR statistical-complexity measure of P. W. Lamberti, M. T. Martín, A. Plastino and O. A. Rosso, applied to markets via the complexity–entropy causality plane of L. Zunino, M. Zanin, B. M. Tabak, D. G. Pérez and O. A. Rosso (2010).
Tie / equal-value bias in ordinal patterns — informed by the work of D. Cuesta-Frau and colleagues (2018).


The implementation, the regime/threshold logic, the complexity gate, the tie-robust dither, the calibration harness and the packaging are original.

Disclaimer

For research and educational purposes only. This script is not financial advice, not a recommendation, and not a guarantee of future results. Indicators describe price behaviour; they do not predict the future. Trading carries risk of loss. Test on out-of-sample data and make your own decisions. The author accepts no liability for any use of this script.
版本注释
Permutation Entropy — Complexity Oscillator (short name: Perm Entropy)

New in this update — amplitude-weighted entropy and forbidden patterns. Standard ordinal-pattern entropy reads only the shape of moves, ignoring their size. This update adds an amplitude-weighted entropy that incorporates how large each move is — sharper near the noise floor on discrete intraday instruments — plus a count of "forbidden" patterns (shapes that never occur in the window), a documented early-warning marker for instability. Both ride the existing window, so there is no added lag.


New dashboard rows: Weighted-entropy / Forbidden count, Edge floor.
New exports: EXP_Entropy, EXP_WPE, EXP_Complexity, EXP_Forbidden, EXP_Regime, EXP_Signal, EXP_Edge, EXP_EdgeLB, EXP_RunsZ.

Honest note: entropy describes the tape's structure, not its direction. Low entropy can precede a trend or a clean oscillation — read the Edge floor.
版本注释
v2.0 — Multiscale entropy, adaptive thresholds, honest out-of-sample harness, and a cleaner read

MULTISCALE permutation entropy: the tape is coarse-grained (block-averaged) across scales and the entropy is read at each, so structure living at a slower scale than the bar isn't hidden by fine noise. The multiscale average (MPE) is a scale-robust complexity read, shown on the panel and exported.
ADAPTIVE (percentile) thresholds: "predictable" can now mean the entropy is in the LOW end of its OWN recent range on this instrument — so a liquid index that sits at 0.90–0.98 still produces signals when it's relatively low, without hand-tuning an absolute number. Absolute mode (fixed 0–1 levels) is still available.
HARNESS+: the calibration adds a uniqueness-weighted EFFECTIVE sample size (overlapping forward windows aren't independent), an IN-SAMPLE / OUT-OF-SAMPLE split — the new "Edge OOS" row is the one to trust — and a multiple-testing deflated significance bar.
Cleaner read: conventional-oscillator layout with shaded structured (green) / random (grey) zone bands and a regime-coloured line; the readout panel gains a Compact (default) / Pro toggle and a live fired-signal count; signals now also plot on the price chart as green-up / red-down triangles.
Bug fix: the tie-jitter and the smoothing EMAs were stateful ta.* calls sitting behind a ternary (can silently skip bars) — now hoisted to top level, and the entropy engine is refactored into one reusable function.
Added the MPL-2.0 licence header. New exports: EXP_MPE, EXP_EdgeOOS, EXP_EffN. Weighted PE, statistical complexity and the forbidden-pattern count are retained.

Descriptive complexity oscillator; the signal is one testable interpretation and forward statistics are in-sample and out-of-sample — read the Edge row, not the signal count. Not investment advice.

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。