OPEN-SOURCE SCRIPT
已更新

RSI Levels & Regime Map Heatmap & Cardwell Reversal Signals

509
OVERVIEW

RSI is the most-used oscillator in the world, and almost nobody trades it — because "RSI is 62" is not something you can place an order against.

This tool moves RSI onto price.

RSI IS INVERTIBLE. Wilder's smoothing can be solved backwards, so for any RSI value there is an EXACT price that would produce it on the next bar. Instead of "RSI is 62", the chart tells you:

Close above 24,278 -> RSI 70 (resistance)
Close below 24,193 -> RSI 30 (support)

Those are real levels. You can put a stop there. You can put a target there.

The script draws the full ladder (30 / 40 / 50 / 60 / 70, all configurable), shades the bands between them into a regime heatmap, measures the Cardwell range regime, marks Cardwell positive and negative reversals with projected targets, shows a multi-timeframe strip — and then does the thing nobody else does: IT FORWARD-TESTS WHETHER ANY OF IT ACTUALLY HOLDS.

This is a research and framing tool. It is NOT a strategy, NOT a signal service, and NOT a validated edge.


THE MATHS (exact, not an approximation)

RSI = 100 - 100/(1 + AG/AL), where AG and AL are the Wilder-smoothed average gain and loss.

For a target T, let RSt = T/(100 - T). Solving the next bar's RSI for the move x required:

an UP move needs x = (n-1) * (RSt*AL - AG)
a DOWN move needs x = (n-1) * (AL - AG/RSt)

Level = close + x. The up form applies when it is non-negative; otherwise the down form does.

This is algebra, not curve fitting. Feed the derived price back through RSI and you get the target value back exactly. The levels are not estimates — they are the precise prices at which the RSI state changes, recomputed every bar. The ladder breathes with volatility on its own: it tightens in quiet markets and widens in violent ones, with no smoothing parameter to tune.


WHY THESE PARTS ARE ONE TOOL (mashup rationale)

1. THE INVERSE-RSI LADDER — the core. Every rung is the exact price at which RSI would print a chosen value.

2. THE HEATMAP — the bands between the rungs, shaded by regime. It shows at a glance how far price must travel to change the RSI story, which is the one question the oscillator pane can never answer.

3. THE CARDWELL REGIME — Andrew Cardwell's observation: in a BULL market RSI holds roughly 40-80, and 40 becomes SUPPORT. In a BEAR market it holds 20-60, and 60 becomes RESISTANCE. So "RSI 40" means the OPPOSITE thing in the two regimes. A tool that ignores this will cheerfully tell you to buy oversold all the way down a trend. The regime here is MEASURED over a lookback, not assumed — and the rung the script watches follows the regime rather than a fixed number.

4. CARDWELL REVERSALS — the signal almost nobody implements. A POSITIVE REVERSAL is RSI making a LOWER low while PRICE makes a HIGHER low. That is the mirror image of classic divergence, and it is a CONTINUATION signal, not a trend reversal. A NEGATIVE REVERSAL is the bearish mirror. A measured target is projected from each.

5. THE HONESTY LAYER — everyone says RSI 30 is support. Nobody checks. Every level test and every Cardwell reversal is logged and graded with a triple barrier against an unconditional control.

Remove any one and you are left with a prettier RSI that still cannot tell you whether RSI works.


THE CALIBRATION — AND THE TWO TRAPS IT TOOK A LIVE TEST TO FIND

Two subtle biases can make a level tool look brilliant while it is doing nothing at all. Both are handled explicitly here, and both are worth understanding whichever tool you use.

TRAP 1 — THE FILL ADVANTAGE.
A support test fires when price dips INTO the rung and closes back ABOVE it. If you enter the event AT THE RUNG (below the close) but compare it with a control entered at the CLOSE, the event gets a strictly better fill on EVERY trade. It then "beats" the control by construction — not because the level held, but because it bought lower. That is a rigged comparison, and it produces a large fake edge.
THE FIX: the level test is treated as a SIGNAL, NOT A FILL. The event and the control enter at the SAME reference price — the bar's close. The only thing that differs is which bars were selected.

TRAP 2 — DIRECTIONAL DRIFT.
Indices drift upward. If level tests are mostly LONG while the control is 50/50, the events win on drift alone and prove nothing.
THE FIX: longs are compared only with control longs, shorts only with control shorts, then blended back using the events' OWN direction mix. The panel also reports the baseline drift directly, so you can see whether the instrument is simply going up.

The control is UNCONDITIONAL: the same trade geometry taken on arbitrary bars, selected by no signal at all. If the levels cannot beat that, they carry no edge.

Results are reported as EXPECTANCY IN R, not hit rate. A Welch t-test decides whether the difference is real or luck — the panel does not say PROVEN unless t > 1.96.

Other conventions, all chosen so the tool cannot flatter itself:
· Both barriers touched on one bar -> the STOP is assumed first.
· Expired trades are marked to market, not booked as losses.
· The level tested is the one computed at the END OF THE PREVIOUS BAR — the price a trader could actually have rested an order at. Using the current bar's own level would be a look-ahead.
· Everything is logged and resolved on confirmed bars only.


HOW TO USE IT

1. READ THE REGIME FIRST. In a bull regime the 40 rung is support and you are hunting long tests of it. In a bear regime the 60 rung is resistance. In neutral, the ladder is simply a map.
2. The rungs are LEVELS. Price closing through one changes the RSI state, by definition.
3. A CARDWELL REVERSAL is a continuation signal with a projected target.
4. READ THE CALIBRATION BEFORE YOU WEIGHT ANY OF IT — and read the baseline-drift row next to it. If level tests show no proven edge on your instrument, the ladder is a MAP, not a probability.
5. Entry, stop and target are drawn at the same price the calibration measures. They are arithmetic, not advice.


DATA / SCOPE

Any symbol, any timeframe. No volume required. The source is an input, so the ladder can be built from close, hlc3, or even another indicator's plot.


NON-REPAINTING

The ladder is computed from confirmed values and projects FORWARD — it is a statement about what the NEXT bar would need to do, so it necessarily moves as new bars arrive. That is a projection, not a repaint, and it is stated plainly rather than hidden.

Level tests are evaluated against the PREVIOUS bar's level, so no future information is used. Reversal pivots use ta.pivot* and confirm a few bars after the fact; once printed, they do not move. The calibration harness logs AND resolves on confirmed bars only, so its statistics cannot inflate intrabar.


HONEST LIMITATIONS — PLEASE READ

The ALGEBRA is exact. THE CLAIMS ABOUT RSI ARE NOT.

"RSI 30 is support" is folklore until it is measured, which is exactly why this script measures it — and why it is built to be able to return "not proven".

Calibration figures are IN-SAMPLE, with no costs or slippage, and use overlapping windows. A proven in-sample edge is NOT a guarantee out-of-sample. Real fills, spreads and commissions will all reduce it.

Cardwell's rules are discretionary in origin and are mechanised here in one particular way. A different mechanisation would give different numbers.

Small samples are unreliable even when they look good. If the edge is near zero, negative, or unstable across timeframes, the honest conclusion is that it is not there.

Nothing here predicts price.


CONCEPT CREDITS

Relative Strength Index and its Wilder smoothing — J. Welles Wilder Jr.
Range rules, positive and negative reversals, and the measured-move projection — Andrew Cardwell.
Triple-barrier forward labelling — Marcos López de Prado.
Welch's t-test — B. L. Welch.

The inverse-RSI level engine, the regime map, the unconditional direction-matched control and the significance testing are the author's own. Clean-room implementation; no third-party code is reused. Not affiliated with, nor endorsed by, any of the above.


DISCLAIMER

Research and educational tool only. NOT financial advice, NOT a recommendation, and NO guarantee of results. Indicators describe past behaviour; they do not predict the future. Entry, stop and target output is arithmetic, not advice. Trading carries a risk of loss. Test out-of-sample and make your own decisions. The author accepts no liability for any use of this script.
版本注释
RSI Levels & Regime Map v1.1 — measured-move projection fix

The Cardwell measured-move targets called the highest and lowest functions inside the true branch of a conditional expression. Pine's stateful series functions must be evaluated on every bar; skipped on every bar without a qualifying reversal, their rolling windows accumulated over a broken history — so the projection was wrong on the bars where it actually printed.

The lookback is also a series length, the span between two pivots, which is undefined on bars where no reversal exists. It is now clamped to a valid value before the call, the extremes are computed unconditionally, and the result is masked afterwards. Projected targets on existing charts may shift; the new values are the correct ones.
RSI level detection, the heatmap, regime classification and calibration are unchanged.

免责声明

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