PulseHub
OPEN-SOURCE SCRIPT

Transfer Entropy

453
Transfer Entropy

A directional information flow detector for two assets, based on Thomas Schreiber's 2000 formulation. Transfer Entropy measures how much knowing the recent past of one series reduces uncertainty about the next move of another — beyond what the second series' own past already explains. Unlike correlation, it's asymmetric: TE(Y → X) and TE(X → Y) are different quantities, so it can speak to lead-lag in a way correlation can't.

How it works

Log returns from both series are symbolized into binary up/down moves. Over a rolling window of N bars, the script estimates the joint distribution of past pairs and future moves, then computes the conditional mutual information that defines TE in bits.
To separate genuine information flow from finite-sample noise, the same calculation is repeated with the reference series circularly shifted by various offsets within the window — surrogates that preserve each series' marginal distribution but break the temporal coupling between them. The mean of those surrogate estimates is the noise floor, which gets subtracted from the raw value to produce Effective Transfer Entropy (Marschinski & Kantz, 2002).
Both directions — Y→X and X→Y — are computed every bar. The main plot is net flow: inflow minus outflow.

How to read it

The colored area is net information flow.
  • Above zero in cyan: the reference symbol's recent moves carry useful information about the chart symbol's next move.
  • Below zero in amber: the chart symbol is leading the reference.

The thinner lines on either side are the individual directional components — inflow plotted positive, outflow plotted as its negative for visual symmetry around zero.
The dotted band is the average noise floor. Flow inside the band is statistically indistinguishable from chance; flow outside it isn't. A faint background tint marks bars where net flow has cleared the band.

Inputs

  • Reference symbol — the second asset (Y). Information flow is measured between this and the chart symbol (X). Default AMEX:SPY.
  • Window length — number of triplets feeding the joint-distribution estimate. The 8-cell histogram needs many times that to stabilize; 150–300 is reasonable for most markets. Default 200.
  • Source — input series for the chart symbol's log returns. Default close.
  • Significance surrogates — number of circular-shift surrogates averaged into the noise floor. More = more stable significance test at modestly higher compute. Default 3.
  • Visuals — toggles for net flow, directional flows, noise floor band, glow, and regime tint, plus customizable colors for inflow, outflow, and neutral states.

Built-in alerts
  • Lead flip — Reference leading — net flow crosses above zero
  • Lead flip — Chart leading — net flow crosses below zero
  • Significant inflow — net flow rises above the noise floor
  • Significant outflow — net flow drops below the negative noise floor

Notes

Pick reference symbols with overlapping trading hours. When one series is closed and the other isn't, the closed series' price forward-fills, which shows up as a run of zero returns and biases the estimate.
The binary symbolization (up vs not-up) is intentionally crude. It's robust, requires no parameter tuning, and matches Schreiber's original formulation — but it discards magnitude. For pairs where the size of a move matters more than its direction, this measure won't capture it.
This is a diagnostic tool, not a signal generator. It tells you which side of a pair is leading.

Five years of work on a trading system left me with dozens of indicators that ultimately didn't earn a place in the final build. They're not failures — they're tools that solved problems I no longer needed solved. So instead of shelving them, I'm publishing the majority of them open-source.
If you're a discretionary trader, take what's useful. If you're a systems builder, the source is yours to dissect, modify, and improve. The best return on five years of work is for it to keep working — for someone.
If you use this script — or part of it — in your own work, please credit the original with a link back to my profile.
Note: these indicators have been updated to Pine Script v6 — some manually, some with AI assistance.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by PulseWire. Read more in the Terms of Use.