OPEN-SOURCE SCRIPT
Updated

Fractional-Diff Momentum Oscillator

410
Fractional-Diff Momentum Oscillator

What it does

The Fractional-Diff Momentum Oscillator is a momentum line, scaled in standard-deviation (σ) units around a zero balance, built on the fractional differencing of price — the smallest amount of differencing that makes price statistically stationary while still keeping its memory.

Why this is different (and original)

Almost every momentum oscillator works on returns — that is, price differenced once (integer order d = 1). Returns are stationary, but differencing once erases the series' memory, throwing away the slow, persistent structure that carries trend information. Raw price (order d = 0) keeps all the memory but is non-stationary and unusable by most statistical tools.

Fractional differencing uses a non-integer order (typically 0.3–0.6) that sits between the two: it removes just enough drift to reach stationarity while retaining long memory. The result is a momentum series that is both well-behaved and information-rich. This transform is standard in quantitative research but rare on retail charts, where oscillators almost universally difference once and discard the signal. That is what makes this original: it is a momentum oscillator built on a memory-preserving transform rather than plain returns.

How it works

The fixed-width fractional-difference weights are generated recursively — w(0) = 1, w(k) = −w(k−1)·(d − k + 1)/k — and truncated once they fall below a tolerance, giving a finite window. Those weights are convolved with log-price to produce the fractionally-differenced series. That series is then z-scored over the normalization window and lightly smoothed into the σ oscillator you see, centred on zero.

How to use it


Zero is the balance line. Above zero = net up-momentum; below = net down-momentum.
Dashed σ bands mark stretched momentum; dotted bands mark extremes prone to exhaustion (red on top, green on the bottom in the standard reading).
Zero-crosses (triangles) are momentum-flip events.
Divergences (circles) warn when price makes a new extreme that momentum does not confirm.
Read the EDGE row. The dashboard runs a live forward-return harness: for every momentum flip it checks whether a favourable move (≥ k×ATR within the horizon) actually occurred, and compares that Hit % against the unconditional Base %. EDGE = Hit − Base is the honest measure of whether the signal adds information on your instrument and timeframe. If EDGE is near zero, the signal is not helping there — and the tool says so.


Settings guide


01 · Data & Differencing — source, log-price toggle, differencing order d, weight tolerance, max window, and a universal price source for the harness.
02 · Normalization — z-score window and output smoothing.
03 · Calibration — horizon, favourable-move threshold (×ATR), base-rate window.
04 · Bands — momentum and extreme σ bands; divergence pivot.
05 · Display & Theme — visual style (gradient area + glow / histogram / line), regime tint, dashboard, colors.


Non-repaint

The weights are fixed and the convolution reads only closed bars — no recalculation of past values, no future leak.

Concept credit


Fixed-width window fractional differentiation — Marcos López de Prado, Advances in Financial Machine Learning (2018).
Fractional integration in time series — Hosking (1981); Granger & Joyeux (1980).


Disclaimer

For research and education only. Not financial advice, not a recommendation, and not a guarantee of future results. All statistics shown are in-sample, close-to-close, and exclude costs — a study aid, not a backtest. Do your own research and manage your own risk.
Release Notes
Fractional-Diff Momentum Oscillator (short name: FracDiff Momentum)

New in this update — a stationarity check. Fractional differencing only works if the chosen differencing order actually makes the series stationary while keeping memory. The dashboard now reports a stationarity proxy (the lag-1 autocorrelation of the differenced series) with a clear ✓ / ✕ verdict, so you can tune the differencing order until the transform is valid on your instrument rather than guessing.


New dashboard rows: Stationary (acf1), Edge floor.
New exports: EXP_Osc, EXP_dEff, EXP_ACF1, EXP_Stationary, EXP_Edge, EXP_EdgeLB, EXP_RunsZ.

Honest note: the check is a fast proxy, not a full statistical stationarity test — it tells you whether the differencing did its job, which is the practical question. The transform is not an edge; the harness measures whether its turns pay.
Release Notes
v2.0 — Auto min-d via a live ADF test, ADF/KPSS stationarity panel, honest out-of-sample harness, and on-price signals

AUTO minimum-d differencing: instead of a fixed order, the tool now searches for the SMALLEST d whose fractionally-differenced series passes an Augmented Dickey-Fuller stationarity test — López de Prado's FFD objective (minimum differencing → maximum memory kept). A live controller nudges d toward the stationarity boundary and rebuilds the fixed-width weights when it changes; a memory-margin setting stops it over-differencing. "Fixed" mode preserves the classic behaviour.
On-panel ADF + KPSS readout: two complementary unit-root tests replace the old lag-1 autocorrelation proxy — ADF (null = unit root; stationary when the t-stat is below its critical value) and KPSS (null = stationary; stationary when below its critical value), each shown with its threshold and a ✓/✕. The ADF t-stat is computed exactly (validated to match statsmodels).
HARNESS+ calibration: the Hit/Base/EDGE record is honest three new ways — a uniqueness-weighted EFFECTIVE sample size (overlapping forward windows aren't independent), a multiple-testing DEFLATED significance bar, and an IN-SAMPLE / OUT-OF-SAMPLE split. The new "EDGE (OOS)" row is the one to trust. Runs-test retained.
On-price signals: the momentum zero-cross turns now also plot on the price chart as tiny directional triangles — green up (below bar) on a bullish flip, red down (above bar) on a bearish flip — in addition to the in-pane markers.
Bug fix: the stationarity autocorrelation was being computed inside a conditional (a stateful ta.* call behind a ternary), which can silently skip bars — it's now hoisted to top level.
New dashboard rows (ADF, KPSS, EDGE OOS, Eff-N) and exports (EXP_ADF, EXP_KPSS, EXP_EdgeOOS, EXP_EffN); EXP_dEff now reports the live effective order. The FFD engine, oscillator, divergences, bands, theme and non-repaint behaviour are unchanged.

Descriptive momentum transform; stationarity and forward statistics are in-sample/on-symbol, not investment advice.
Release Notes
v2.1 — Three optional accuracy upgrades over v2.0: a robust MAD z-score, a lag-minimal smoother, and an opt-in 3-window extreme consensus. The fixed-width fractional differencing, the auto min-d ADF controller, the ADF / KPSS stationarity readout and the full HARNESS+ track-record (effective N, deflated significance, in-sample / out-of-sample split, runs-test) are unchanged — set Z-score mode = "Classic (mean/stdev)" and Output smoother = "EMA" for the original v2.0 read.

1. Robust MAD z-score (default on). The fractionally-differenced series can be standardized with a median/MAD z (median absolute deviation ×1.4826) instead of mean/stdev, so a single fat-tailed bar no longer stretches the whole σ scale and the band readings stay comparable across regimes. Selectable via "Z-score mode".

2. UltimateSmoother (default on). When output smoothing is on (smoothing > 1), it can use Ehlers' lag-minimal UltimateSmoother instead of an EMA, so the σ-oscillator turns with less delay. Selectable via "Output smoother".

3. 3-window extreme consensus (opt-in, default off). The z can be taken as the MEDIAN of the z at half, one and double the normalization window — extreme only when short, medium and long windows agree. "Extreme normalization" = "Single window" (the default) reproduces v2.0.

What is unchanged. The recursive fixed-width fractional-difference weights, the FFD convolution on log-price, the live ADF auto-d controller, the on-panel ADF + KPSS stationarity tests, the confirmed-pivot divergence, the zero-cross momentum signals, and the entire HARNESS+ calibration (uniqueness-weighted effective N, Bonferroni-deflated significance bar, in-sample/out-of-sample split, runs-test) are byte-for-byte v2.0. Every export (EXP_Osc, EXP_dEff, EXP_ACF1, EXP_ADF, EXP_KPSS, EXP_Stationary, EXP_Edge, EXP_EdgeOOS, EXP_EdgeLB, EXP_EffN, EXP_RunsZ) is retained. The new layers only re-standardize and re-smooth an existing series.

Fractional differencing is a transform, not an edge — whether the turns pay is exactly what the harness measures, in-sample, close-to-close, without costs. Non-repaint: weights are fixed; the convolution uses only closed bars; the calibration resolves on confirmed bars. Concept credits unchanged (López de Prado FFD / min-d; Hosking; Granger & Joyeux; Dickey-Fuller; KPSS; Newey-West), plus the median/MAD robust z-score and Ehlers UltimateSmoother for the new layers.

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 TradingView. Read more in the Terms of Use.