Kalman RSI

Two different Kalman filters driving one 0-100 oscillator — and the measurement
instrument that was used to judge them, running live on your chart. Pick the
alpha-beta velocity engine or the recursive-regression engine, and the same
bands, signals and scoring run on whichever you choose.
The unusual part is not the filters. It is that this build reports, on your
symbol and your history, whether its own signals lead price at all — including
when the answer is no.
The source is protected; the indicator is free to add and use on your charts.
─────────────────────────────────────────────────────────────
WHY THE SCORING IS DIFFERENT (this is the point)
─────────────────────────────────────────────────────────────
Almost every oscillator study scores itself by asking whether the line reached
the far band after crossing the near one. That question can be answered
entirely by the oscillator's own AUTOCORRELATION. A heavily smoothed series
that crosses its lower band is very likely to continue to the upper band
simply because smooth series do not reverse abruptly — no prediction about
PRICE is required anywhere in that test.
So "smoother engine" and "higher score" are confounded, and the smoothest
thing in any lineup wins a contest that never involved price. In development
this exact trap produced a 95% score on an engine whose measured price edge
was NEGATIVE. Optimising toward that score would have meant making the
oscillator more sinusoidal and watching the number climb while the edge fell.
This build runs both scorers at once and shows them next to each other:
• The HARNESS scores the oscillator — the band-cross test above, kept
deliberately, and labelled as measuring the oscillator.
• The EDGE BLOCK scores PRICE. For every armed signal it measures how far
price actually travelled over the next H bars in ATR units, subtracts the
unconditional move over the same horizon, and divides by the standard error:
EDGE = mean forward move after signal - mean forward move over all bars
t = EDGE / ( SD(post-signal forward moves) / sqrt(n) )
When the two disagree, the harness is the one that is wrong. A high harness
rate sitting on a t near zero is autocorrelation, and the panel says so in
words. That disagreement, made visible on your own data, is what makes this
build different from an oscillator you are asked to trust by eye.
─────────────────────────────────────────────────────────────
HOW IT WORKS
─────────────────────────────────────────────────────────────
LAYER 1 -- ENGINE A, KALMAN ALPHA-BETA VELOCITY. A two-state constant-velocity
tracker: predict level + velocity, measure the residual against the close,
correct level by alpha times the residual and velocity by beta. The oscillator
is NOT the level — it is the velocity's signal-to-noise ratio through a
logistic, so the line reads as "how fast, relative to how noisy."
LAYER 2 -- GAIN COUPLING. Alpha and beta are not independent knobs; choosing
them separately is how you get a filter that is either sluggish or ringing.
Three couplings ship: Manual, Benedict-Bordner (beta = alpha^2/(2-alpha), the
minimum-transient pair), and Kalata self-tune, which measures the tracking
index L = process noise / measurement noise bar by bar and solves for the
optimal steady-state pair — r = (4 + L - sqrt(8L + L^2))/4, alpha = 1 - r^2,
beta = 2(1 - r)^2. Kalata opens the filter when price is genuinely
accelerating and clamps it when the move is noise.
LAYER 3 -- ENGINE B, KALMAN REGRESSION. A two-state recursive least squares
filter in the classic pairs form, run on one instrument: bar range regressed
on a fractal-dimension measure of the last n bars. State is [slope,
intercept], the covariance P is a full 2x2 updated by the Kalman gain, and the
process noise is delta/(1-delta) times either the identity or the high/low
correlation matrix. Measurement noise is fixed or adapts to the rolling
spread of range changes. Two update modes: pure RLS, and a phase accelerator
that puts an EMA on the state itself. The panel reports slope, intercept and
RMSE, so fit quality is visible rather than implied.
LAYER 4 -- SCALING AND BANDS. Raw output, adaptive bands (rolling mean +/- one
sigma of the oscillator itself, so triggers follow the engine's own
distribution rather than a fixed 30/70), or a full percentile rescale against
the last N bars. Signals are band crosses; both scorers consume them.
─────────────────────────────────────────────────────────────
SESSION POLARITY GATE
─────────────────────────────────────────────────────────────
The same oscillator has OPPOSITE predictive sign in different parts of the
session. The opening hour behaves as momentum; the overnight and European
sessions behave as reversion; midday measures as approximately nothing.
Averaged together they very nearly cancel — which is why full-sample
statistics on oscillators of this family so often read as noise even when
something is there.
The gate flips the oscillator's sign per session bucket and can mute the
bucket where it has nothing to say, so the engine stops generating entries in
the window where it provably says nothing.
IMPORTANT: the gate is OFF by default, so what you see on first load is the
unmodified engine. Turn it on only after you have looked at the edge rows
with it off — otherwise you cannot tell which of the two you are reading.
─────────────────────────────────────────────────────────────
WHAT YOU SEE ON THE CHART
─────────────────────────────────────────────────────────────
Oscillator four-state colour — red overbought, green oversold,
cyan above the midline, amber below
Trigger lines the live bull/bear bands, which move with the band mode
Zone shading overbought and oversold blocks
Gradient cloud synthwave fill between the line and the midline
Arrows triangle at each band cross, up on bull, down on bear
Muted bars dimmed background where the session gate is set to zero
Info panel engine and its LIVE gains, current velocity or slope /
intercept and RMSE, band mode and levels, session bucket
and polarity, harness rates with sample size and bars to
resolve, four edge rows with t and hit rate, and a verdict
Alerts one per bar on a bullish / bearish / either band cross
─────────────────────────────────────────────────────────────
HOW TO USE
─────────────────────────────────────────────────────────────
1 START ON ENGINE A, Benedict-Bordner, adaptive bands. Read the panel before
the line: harness and edge rows together, not either one alone.
2 TRADE SMOOTHNESS FOR SAMPLE SIZE with beta mode. Benedict-Bordner is very
smooth and fires rarely; Manual at beta 0.02 gives several times the sample.
An edge that survives the larger n is a far stronger result than one that
does not.
3 SET THE HORIZONS to suit the engine. Judge a cycle-flavoured filter at a
quarter to a half of its natural period — measuring a 25-bar cycle 25 bars
forward lands you back where you started and guarantees a null.
4 CHECK THE SIGN. A strongly negative t means the instrument reads backwards;
Invert engine tests that directly. Confirm the sign is stable, not fitted.
5 THEN TRY THE SESSION GATE, and see whether a signal that measures as nothing
in aggregate measures as something inside one bucket.
─────────────────────────────────────────────────────────────
HOW TO READ THE PANEL (it measures — it never places orders)
─────────────────────────────────────────────────────────────
-- |t| BELOW 2 IS NOT EVIDENCE, no matter how large the edge next to it
looks. 2 to 3 is suggestive and worth growing the sample. Above 3 is worth
building on.
-- A LARGE EDGE WITH A SMALL t means a handful of outliers carried it. Read
the two numbers as a pair, never the edge on its own.
-- HIGH HARNESS, FLAT EDGE is the confound doing its work: you are looking at
the autocorrelation of a smooth curve, not a forecast.
-- SAMPLE SIZE IS ON THE PANEL for a reason. Both blocks accumulate from the
first bar loaded, so a short history gives small n and unstable t. Load more
bars before concluding anything.
-- SWEEPING INPUTS UNTIL SOMETHING CLEARS t = 2 will always eventually
succeed. Anything found that way is a hypothesis, not a result, and belongs
on data you have not looked at yet.
─────────────────────────────────────────────────────────────
IMPORTANT NOTES
─────────────────────────────────────────────────────────────
-- Ported from working ThinkScript implementations and checked against them
before publishing: the band-cross rate reproduces the original study's figure
on a separate window of data, and the edge block was verified to accumulate
an identical sample to the ThinkScript version.
-- Measurement and research tool — NOT a turnkey entry/exit system. There is
no strategy, no position sizing and no backtest in this script.
-- The edge block reports GROSS numbers. It says nothing about whether an
effect survives spread, commission and slippage, and effects of this size
frequently do not.
-- All statistics are computed from closed bars with no future references, so
signals do not repaint. The statistics themselves grow as bars load.
-- Not backtested or forward tested as a trading system.
-- This is not financial advice. Trading involves substantial risk of loss.
Use for educational and research purposes only.

