OPEN-SOURCE SCRIPT

Path Signature Regime Engine

287
# Path Signature Regime Engine (PSRE)

**What it does**

Path Signature Regime Engine reads the *geometry* of recent price action and
labels the current market state as **Trending up**, **Trending down**,
**Range / chop**, or **Turning (reversion)**. Instead of smoothing price with a
moving average, it measures the shape of the path itself using the low-order
**path signature** — a description of a curve by its iterated integrals from
rough-path theory.

Two terms do the work:

- **Level 1 — drift:** the net displacement of the path over a lookback window.
- **Level 2 — Lévy area:** the signed area the path sweeps relative to its own
chord. A path that keeps curling the same way (a trend) accumulates area; a
path that oscillates back and forth (a range) cancels it out. The sign and
size of this area is the core regime signal.

Both terms are turned into 0–100 percentiles over a rolling window, so the read
adapts to each symbol and timeframe automatically.

**How it works (one method, three views — not a mashup)**

This is deliberately **not** a bundle of independent indicators stitched
together. Every component calls the same internal routine that computes the
drift + Lévy-area read. The "extra" layers are that single computation pointed
at different data:

- **Chart timeframe** — the primary regime read.
- **Multi-timeframe confluence** — the *identical* read evaluated on two higher
timeframes (default 1H and 4H). It is reported as **agreement** ("aligned
2/3"), explicitly *not* as independent confirmation, because nested
timeframes share information. "Aligned" requires at least two of the three
views to agree with the chart.
- **Cross-asset comparison** — the same iterated-integral area computed between
*two return streams* (your symbol and a benchmark) instead of price-vs-time.
This yields a geometric lead/lag read plus a relative-strength sign.

Because the higher-timeframe and cross-asset views are projections of one
geometric primitive rather than separate tools, they reinforce a single
conclusion: what is the path doing, and does that hold up when seen from a
slower clock or against a related instrument.

**The honesty layer (why this differs from a typical regime indicator)**

Markets are noisy, so the engine carries its own reality checks rather than
asking you to take the colours on faith:

- **In-sample base rates** — for each regime it tracks, on the history loaded
on your chart, how often price actually continued over a chosen horizon, with
sample counts shown.
- **"Aligned vs not"** — a side-by-side that can reveal the multi-timeframe
layer adding *nothing* on a given instrument (if the two numbers are equal,
alignment isn't helping — and the panel will tell you so).
- **Transition log** — a table of recent regime flips with their realised
forward return (in ATR units) and a ✓/✗ result. With one toggle it also
emits `log:*` series so you can right-click → *Export chart data* and study
the full transition history offline.

These are descriptive statistics on past data, not predictions.

**How to use it**

1. Add it to any chart. It reads the chart's own symbol, so it works on any
market — equities, futures, FX, crypto, indices.
2. Defaults are tuned for **NIFTY** (benchmark `NSE:BANKNIFTY`, same trading
session). For any other asset, open settings group **4 · Cross-asset
comparison** and set a benchmark that trades in the *same hours* as your
instrument, and adjust the two higher timeframes in group **3** relative to
your working timeframe.
3. Read the panel top-down: regime → strength → bias → path quality →
timeframe agreement → relative strength → flow tilt → base rates.
4. Treat the output as **context**, not a trade trigger. The base-rate rows are
there so you can judge, per instrument and timeframe, whether the read has
any historical edge before relying on it.
5. Optional alerts fire on a new reversion setup and on any regime change.

**Inputs are organised in workflow order:** Data & source, Signature engine,
Multi-timeframe confluence, Cross-asset comparison, Regime base-rate study,
Transition log, Appearance. The panel theme adapts to your chart background
luminance for readability on light or dark themes.

**Concept credits**

The mathematics is not mine; the implementation and the regime/honesty
framework are. Path signatures and the Lévy-area interpretation come from the
rough-path and signature-method literature:

- K.-T. Chen — iterated integrals (1957).
- T. Lyons — rough-path theory and the path signature (1998).
- I. Chevyrev & A. Kormilitzin — *A Primer on the Signature Method in Machine
Learning*.
- J. Morrill, A. Fermanian, P. Kidger & T. Lyons — *A Generalised Signature
Method for Time Series* (the basepoint + time augmentation used here).

Only the interpretable Levels 1–2 are computed directly from cumulative sums.
This is a descriptive geometric read, not a full signature and not a machine-
learning model.

---

## Disclaimer (include at the end of the description)

This script is an educational and analytical tool. It is **not financial
advice**, not a recommendation to buy or sell, and not a signal service. All
statistics it shows (base rates, transition forward returns) are **in-sample**,
computed close-to-close on the history loaded on your chart, with no execution
costs or slippage, and are **not** a backtest and **not** a forecast. Past
behaviour does not guarantee future results. Test thoroughly and trade your own
plan and risk.

免責聲明

這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。