PROTECTED SOURCE SCRIPT

Not only a Supertrend [by Oberlunar]

107
Oberlunar’s Not only Supertrend is designed for traders who need something that stays reactive in fast regimes without collapsing when the tape turns discontinuous—volume gaps, microstructure noise, sudden volatility shocks.

The design goal is to approximate market regime dynamics by combining a probability-like regime score (a bounded Bayesian-style posterior from multiple evidence) with a measure of regime impulse (the Kalman-filtered step/change in evidence).

For ETF-like tapes, it models second-order behaviour: volatility expansion vs contraction, persistence of the expansion, and participation/flow confirmation proxies (via multi-broker OHLCV pressure dominance), to reduce sensitivity to transient spikes.

There is no type of lookahead bias or repaint:
snapshot

More or less 2 R in a 10-minute chart...
snapshot

The core signal is built around two regime proxies that are intentionally different, so they don’t fail in the same way when the tape gets stressed.

The first proxy looks at realised volatility computed from log-returns, then maps it into a rolling percentile range. Framing volatility this way keeps it scale-free and easier to compare across instruments and across very different volatility states, and it also helps avoid the typical warping you can get from raw ATR-like measures when the market produces abrupt jumps.

The second proxy focuses on Bollinger Band width, but not in absolute terms: it measures the width relative to its own EMA baseline, and then compresses that ratio through a logistic mapping. This keeps the regime evidence continuous, smoothly saturating, and far less prone to “threshold artefacts” where a tiny change flips the state.

Put together, these two pieces produce an “expansion base” and a “contraction base” that stay bounded and well-behaved, even when price action prints discontinuities.

Then, directional bias is handled as a soft prior that can lean the model without overpowering it. In practice, a weighted multi-timeframe RSI builds a probability-like prior over long versus short bias, so the engine can express partial conviction and gracefully reconcile conflicts across timeframes instead of forcing a single, binary view.

That separation matters in situations where directional edge and volatility regime edge are related but not the same thing. The design keeps them coupled—so strong direction can reinforce regime confidence—but it does not collapse them into one signal.

For that reason, the system works with four parallel channels—expansion-long, expansion-short, contraction-long, contraction-short—as continuous evidence streams. And when price breaks the Bollinger bands, it’s treated as a conditional boost to the relevant evidence instead of an absolute trigger, which helps reduce false positives during noisy, stop-run style breakouts.

You can use a not only Supertrend line style with signals...
snapshot

...or just follow its planes and their breakout, such in the following example:
snapshot

To keep the system resilient to gaps and one-bar anomalies, the raw evidence doesn’t go straight into decisions: it is first passed through an alpha–beta Kalman update. In practical terms, this acts as a lightweight state-space tracker that follows both the level of the evidence and its drift.

The level is your smoothed, probability-like regime proxy. The drift is the key ingredient for options, because it captures how quickly the regime is changing—what you can reasonably describe as the acceleration of the transition.

Crucially, the script doesn’t just compute that internally and forget it: it explicitly takes the step of the filtered state, normalises it, and uses it as a feature. That lets the engine distinguish between a regime that is high but basically flat, and a regime that is actively ramping. And because one-bar spikes can still happen, the step feature is bounded, so it can react to real transitions without overreacting to a single print.

The final confidence layer is produced with a Bayesian-style update that treats both the prior and the incoming evidence as **pseudo-counts in a Beta distribution**, and then uses the **posterior mean** as the final probability-like score. The prior is derived from the weighted multi-timeframe RSI: the script maps the weighted RSI into a smooth probability via a sigmoid (`rsiPriorLong`), and uses its complement for short bias (`rsiPriorShort`).

The likelihood is built per channel, and it is deliberately simple and bounded. For expansion, the likelihood combines the Bollinger expansion signal with the normalised Kalman step, using user-controlled weights. Contraction does the same with the corresponding contraction signals. Small conditional boosts are then applied when the price breaks the bands (or stays inside them), but these boosts remain incremental rather than flipping the state.

The two strength parameters, `kPrior` and `kLike`, control how “sticky” this posterior is. A higher `kPrior` makes the posterior lean more strongly on the RSI-based belief and therefore move more smoothly. A higher `kLike` gives more authority to the incoming evidence (BB regime + Kalman step), so the posterior adapts faster when conditions change.

In effect, this is a practical calibration layer: instead of stacking indicators and hoping they agree, the script converts each component into bounded evidence, fuses them into a single posterior mean, and exposes explicit controls for stability versus responsiveness—exactly the trade-off you typically care about when dealing with convex instruments, where you want confidence to be reactive, but not fragile.

Bands filled by expansion Bayesian posterior:
snapshot

Because regime detection alone isn’t enough to avoid whipsaws, the script adds an adaptive “lane supertrend” layer. This supertrend layer is not built upon a classic ATR. Instead of operating on price distance, it operates on posterior imbalance: the engine computes a net score as the difference between bullish and bearish posteriors (`netE = postEL - postES` for expansion and `netC = postCL - postCS` for contraction), and that net is what drives direction.

Direction changes are then gated by an adaptive deadband.

In turn, the deadband is not fixed: it expands or contracts based on two things that already exist in the model—posterior confidence (e.g., `confE = max(postEL, postES)`) and regime intensity (e.g., `regE = volPct01`, and the complementary contraction regime). Those are mixed to produce `dbE` and `dbC`, which act like a hysteresis zone around neutrality.

When the posterior is indecisive and the regime is noisy, the deadband effectively widens, so small oscillations around zero don’t cause constant flips. When the posterior becomes decisive, the deadband tightens, and the direction logic becomes more responsive.

On top of that, flips are not allowed instantly: the script uses a flip-confirm counter that requires the net score to stay beyond the deadband for multiple bars before a direction switch is accepted. This prevents the engine from toggling on micro-oscillations and single-bar disturbances.

Visually, the “lane” is explicitly mapped into price space.

In detail, the script builds a lane geometry using ATR as a vertical scale, then projects the net posterior into the expansion and contraction band. With optional trailing enabled, the lane value is further “supertrend-like”, so what you see on the chart reads as a probabilistic supertrend line—a line whose position and persistence reflect posterior imbalance—rather than a raw volatility expression.

Finally, to address real-world tape issues (discontinuities, fragmented liquidity, venue noise), the script integrates a multi-broker Volumetric Dominance filter as an additional gate. It aggregates multi-broker OHLCV, derives a pressure-like proxy, and only allows certain triggers when cross-broker dominance is sufficiently aligned—so the system is less likely to react to isolated prints that aren’t supported by broader participation.

Once dominance is both directional and concentrated, the filter becomes a hard regime-consistency gate. If dominance is meaningfully bearish, the script blocks bullish expansion triggers and symmetrically blocks bearish expansion triggers when dominance is bullish. In other words, it’s not trying to “confirm” signals after the fact; it enforces a consistency constraint between volatility-expansion regime and cross-venue participation direction, specifically to reduce the exact kind of false positives that can wreck options entries: apparent volatility expansion occurring into opposing flow.

Thus, this is not only a Supertrend. It’s a bounded, smooth regime engine with an outlier-resistant “acceleration” step, a Bayesian-style posterior with tunable inertia, and a dominance gate that blocks expansion signals when multi-venue pressure points the other way.

It can still fail—no proxy fully captures the tape, and any filter can lag or miss abrupt turns—but I think it’s a framework worth exploring for more informed entries across assets: responsive in fast regimes, yet less fragile around gaps and volatility shocks.


Enjoy!

by Oberlunar 👁★

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.