OPEN-SOURCE SCRIPT
Diupdate Trend Bias Oscillator

**Trend Bias Oscillator (TBO)**
---
The Trend Bias Oscillator tracks where price sits within its current trend — not just whether it's bullish or bearish, but *how far along* it is within that move. It normalizes that position to a clean ±100 scale, so readings are consistent across any instrument or timeframe.
When the market is in a bullish structure, the oscillator rises toward +100 as price pushes toward the top of the established range, and pulls back toward zero on retracements. When structure is bearish, it falls toward -100 as price drops, and recovers toward zero on bounces. If price breaks beyond the known range entirely, the oscillator pins at ±100 — a sign of extension.
Structure shifts when price closes decisively above a prior swing high (bullish flip) or below a prior swing low (bearish flip). Once flipped, the bias holds until the opposite level is broken — so the oscillator stays on one side of zero for the entire duration of a trend, not just the bar the signal fired on.
The optional signal line smooths the raw oscillator, making it easier to spot when momentum is building or fading within the current bias. A widening gap between the histogram and signal line suggests continuation. Compression back toward the line suggests a pause or potential reversal ahead.
---
**What makes TBO different**
Most oscillators measure momentum or price position in isolation — they have no awareness of whether the market is in a defined trend or not. RSI, Stochastic, and similar tools will oscillate freely regardless of structure, which means a reading of 70 looks the same in a strong uptrend as it does in the middle of a range.
TBO is different because the oscillator only activates and measures depth *after* a confirmed structural break. Until price breaks a prior swing high or low with a closed bar, the oscillator stays at zero — explicitly signaling that no defined bias exists. Once a break is confirmed, TBO then continuously measures how deep price has traveled into that trend, using the opposing swing level as its reference point rather than an arbitrary lookback window or moving average.
This means TBO doesn't just tell you which direction the market is leaning — it tells you *how committed* it is to that direction at any given moment. A reading compressing back toward zero during an uptrend is a retracement warning. A reading pushing toward +100 is trend continuation. The context is structural, not statistical.
There are indicators on TradingView that normalize price within a range, and others that detect market structure breaks. TBO combines both into a single, continuously updated reading — making it a genuinely different tool rather than a variation on existing oscillator formulas.
---
**Inputs**
**Bars Left** *(default: 20)*
How many bars to the left define a swing point. Higher values find bigger, more meaningful swings. Lower values are more sensitive and react faster.
**Bars Right** *(default: 5)*
How many bars to the right are needed before a swing is confirmed. Lower values confirm faster but can be noisier. This setting also controls how much lag the indicator has — a value of 5 means pivots confirm 5 bars after they form.
**Non-Repaint Mode** *(default: on)*
Ensures structure bias can only flip on a fully closed bar — a signal triggered intrabar will never fire and then disappear before the candle closes. The oscillator value itself will still update in real time as price moves within the current bar, which is normal and expected. What non-repaint protects is the structural flip — that moment when bias switches from bullish to bearish or vice versa. Turning this off allows real-time bias changes but signals may repaint on unclosed candles.
**Show Signal Line** *(default: on)*
Toggles the smoothed line over the histogram on or off.
**Signal Type** *(default: EMA)*
The smoothing method used for the signal line. EMA reacts fastest, SMA is straightforward, WMA weights recent bars more heavily, and RMA (Wilder's) is the smoothest and slowest. Personal preference — try EMA or RMA first.
**Signal Length** *(default: 5)*
How many bars the signal line looks back over. Shorter values follow the oscillator closely. Longer values produce a smoother line that only moves on sustained shifts.
**Signal Color** *(default: blue)*
The color of the signal line, adjustable via the color picker.
**Signal Line Width** *(default: 1)*
The thickness of the signal line. Ranges from 1 to 4.
---
**Reference Lines**
| Level | What it means |
|---|---|
| +100 | Price fully extended in bullish structure |
| +50 | Price in the upper half of the bullish range |
| 0 | No bias established, or structural midpoint |
| -50 | Price in the lower half of the bearish range |
| -100 | Price fully extended in bearish structure |
---
**A few things worth knowing**
Swing pivots confirm with a small natural delay — this is intentional and keeps the indicator from repainting. On very choppy or ranging markets, structure will flip frequently and the oscillator will hover near zero. This is the indicator working as designed, not a malfunction — it simply means no clean trend structure exists at that time. Stepping up to a higher timeframe usually clarifies the picture.
The oscillator value moving on the live bar is normal behavior and not repainting. Non-Repaint Mode specifically prevents structure bias from flipping until a bar fully closes, ensuring signals are never triggered and then taken back within the same candle.
---
The Trend Bias Oscillator tracks where price sits within its current trend — not just whether it's bullish or bearish, but *how far along* it is within that move. It normalizes that position to a clean ±100 scale, so readings are consistent across any instrument or timeframe.
When the market is in a bullish structure, the oscillator rises toward +100 as price pushes toward the top of the established range, and pulls back toward zero on retracements. When structure is bearish, it falls toward -100 as price drops, and recovers toward zero on bounces. If price breaks beyond the known range entirely, the oscillator pins at ±100 — a sign of extension.
Structure shifts when price closes decisively above a prior swing high (bullish flip) or below a prior swing low (bearish flip). Once flipped, the bias holds until the opposite level is broken — so the oscillator stays on one side of zero for the entire duration of a trend, not just the bar the signal fired on.
The optional signal line smooths the raw oscillator, making it easier to spot when momentum is building or fading within the current bias. A widening gap between the histogram and signal line suggests continuation. Compression back toward the line suggests a pause or potential reversal ahead.
---
**What makes TBO different**
Most oscillators measure momentum or price position in isolation — they have no awareness of whether the market is in a defined trend or not. RSI, Stochastic, and similar tools will oscillate freely regardless of structure, which means a reading of 70 looks the same in a strong uptrend as it does in the middle of a range.
TBO is different because the oscillator only activates and measures depth *after* a confirmed structural break. Until price breaks a prior swing high or low with a closed bar, the oscillator stays at zero — explicitly signaling that no defined bias exists. Once a break is confirmed, TBO then continuously measures how deep price has traveled into that trend, using the opposing swing level as its reference point rather than an arbitrary lookback window or moving average.
This means TBO doesn't just tell you which direction the market is leaning — it tells you *how committed* it is to that direction at any given moment. A reading compressing back toward zero during an uptrend is a retracement warning. A reading pushing toward +100 is trend continuation. The context is structural, not statistical.
There are indicators on TradingView that normalize price within a range, and others that detect market structure breaks. TBO combines both into a single, continuously updated reading — making it a genuinely different tool rather than a variation on existing oscillator formulas.
---
**Inputs**
**Bars Left** *(default: 20)*
How many bars to the left define a swing point. Higher values find bigger, more meaningful swings. Lower values are more sensitive and react faster.
**Bars Right** *(default: 5)*
How many bars to the right are needed before a swing is confirmed. Lower values confirm faster but can be noisier. This setting also controls how much lag the indicator has — a value of 5 means pivots confirm 5 bars after they form.
**Non-Repaint Mode** *(default: on)*
Ensures structure bias can only flip on a fully closed bar — a signal triggered intrabar will never fire and then disappear before the candle closes. The oscillator value itself will still update in real time as price moves within the current bar, which is normal and expected. What non-repaint protects is the structural flip — that moment when bias switches from bullish to bearish or vice versa. Turning this off allows real-time bias changes but signals may repaint on unclosed candles.
**Show Signal Line** *(default: on)*
Toggles the smoothed line over the histogram on or off.
**Signal Type** *(default: EMA)*
The smoothing method used for the signal line. EMA reacts fastest, SMA is straightforward, WMA weights recent bars more heavily, and RMA (Wilder's) is the smoothest and slowest. Personal preference — try EMA or RMA first.
**Signal Length** *(default: 5)*
How many bars the signal line looks back over. Shorter values follow the oscillator closely. Longer values produce a smoother line that only moves on sustained shifts.
**Signal Color** *(default: blue)*
The color of the signal line, adjustable via the color picker.
**Signal Line Width** *(default: 1)*
The thickness of the signal line. Ranges from 1 to 4.
---
**Reference Lines**
| Level | What it means |
|---|---|
| +100 | Price fully extended in bullish structure |
| +50 | Price in the upper half of the bullish range |
| 0 | No bias established, or structural midpoint |
| -50 | Price in the lower half of the bearish range |
| -100 | Price fully extended in bearish structure |
---
**A few things worth knowing**
Swing pivots confirm with a small natural delay — this is intentional and keeps the indicator from repainting. On very choppy or ranging markets, structure will flip frequently and the oscillator will hover near zero. This is the indicator working as designed, not a malfunction — it simply means no clean trend structure exists at that time. Stepping up to a higher timeframe usually clarifies the picture.
The oscillator value moving on the live bar is normal behavior and not repainting. Non-Repaint Mode specifically prevents structure bias from flipping until a bar fully closes, ensuring signals are never triggered and then taken back within the same candle.
Catatan Rilis
The Trend Bias Oscillator answers a question most indicators don't ask: is the trend actively earning its bias right now, or is it living off credit from past moves?Most oscillators treat a trend as a binary condition — either bullish or bearish — and stay that way until price reverses. TBO is different. It tracks whether the market is continuously confirming its trend through new structural breaks, or whether it has gone quiet and is slowly losing conviction. A trend that stops making new structure doesn't just hold its reading — it bleeds toward zero until structure proves itself again.
---
## How it works
Every time price breaks a prior swing high or low with meaningful conviction, TBO registers that event and scores it. Not every break is equal — a powerful momentum break scores higher than a barely-squeaking close beyond the level. That score is weighted by how far price actually moved past the pivot relative to recent volatility, so outlier candles don't hijack the reading.
That score gets added to a running credit balance. The critical part: that credit decays every single bar that no new structural break occurs. The trend must keep proving itself to maintain a high reading. The moment structure goes quiet, the oscillator starts falling — even if price hasn't reversed yet. This is the early warning most indicators simply don't give you.
The final oscillator value is the rate of change of that credit balance. A rising reading means structural conviction is building. A falling reading means it's amortizing. The oscillator is normalized to a fixed -100 to +100 scale so it reads the same way on any instrument or timeframe.
---
## The five states
Rather than just showing a number, TBO classifies the market into one of five actionable states at all times:
**LONG** — The trend is actively compounding. New structural breaks are printing with conviction and the oscillator is accelerating. Highest-confidence environment for trend continuation trades.
**HOLD LONG** — The bullish bias is still intact but structural confirmation has slowed down. Credit is decaying. The trend is real but running on older fuel. Not the time to add to positions — manage what you have and watch for the next structural confirmation or a fade toward neutral.
**STAND ASIDE** — No meaningful structural bias exists in either direction. The oscillator is near zero. This is not a failure state — it's the indicator correctly identifying that there is nothing to trade from a trend perspective. Sit on your hands.
**HOLD SHORT** — The mirror of HOLD LONG. A bearish trend is present but losing conviction. Structural breaks to the downside have slowed and credit is fading. If you're short, manage the position tighter. Don't initiate new shorts here.
**SHORT** — The mirror of LONG. Structure is actively breaking to the downside with conviction and the oscillator is accelerating lower. Highest-confidence environment for bearish continuation.
---
## The signal line
A smoothed line sits over the histogram. When the oscillator is above the signal line and pulling away, momentum is building. When it compresses back toward the line, momentum is fading. When it crosses below, the environment is shifting. It can be configured as an EMA, SMA, WMA, or RMA with adjustable length and color.
---
## Reference levels
| Level | What it means |
|---|---|
| +75 | Strong bullish structural conviction |
| +25 | Minimum threshold for a bullish bias to register |
| 0 | No bias — structural vacuum |
| -25 | Minimum threshold for a bearish bias to register |
| -75 | Strong bearish structural conviction |
Readings between -25 and +25 are effectively neutral regardless of which direction the histogram is pointing. The ±75 lines mark where conviction is genuinely strong.
---
## How this is different from the original
The original Trend Bias Oscillator measured where price sat within the range between the last swing high and swing low. When structure was bullish, it showed how close price was to the top of that range. When bearish, how close to the bottom. Clean and useful, but it answered a static question — position within a range — not a dynamic one.
This version replaces that range-position model entirely with a structural conviction engine. The key differences:
**Break events are scored, not just detected.** The original treated every Break of Structure as an equal binary event. This version weights each break by how convincingly price moved past the pivot, normalized to volatility. A weak break and a strong break are no longer the same signal.
**The trend must keep proving itself.** The original held its bullish or bearish reading for as long as that structure remained intact. This version decays that reading every bar that no new structure prints. A trend that goes quiet loses its oscillator reading over time — automatically flagging that conviction is fading before price actually reverses.
**The oscillator measures structural momentum, not position.** The original measured where price was within a range. This version measures the rate of change of accumulated structural conviction — whether that conviction is building, holding, or amortizing. The result is an oscillator that can stay on one side of zero during a trend while still communicating whether that trend is strengthening or running out of fuel.
**Five states instead of a continuous reading.** Rather than just a number, TBO translates the oscillator into five actionable states — LONG, HOLD LONG, STAND ASIDE, HOLD SHORT, SHORT — that tell you not just the direction but the quality and trajectory of the current structural environment.
The original was a structure position indicator. This is a structure conviction indicator. They're measuring different things.
---
## A few things worth knowing
Pivot points confirm with a small natural delay — this is intentional and prevents the indicator from repainting. The Bars Right setting controls how many bars must pass before a swing is confirmed, so a setting of 5 means pivots are confirmed 5 bars after they form.
The oscillator value will move on the live bar as price changes — this is normal and not repainting. Non-Repaint Mode specifically protects the structural flip (the moment bias switches direction) from firing and reversing on an unclosed candle. The live reading updating in real time is expected behavior.
On choppy or ranging markets, the oscillator will spend more time near zero and STAND ASIDE will appear frequently. This is the indicator working correctly — it's telling you there is no clean structural trend to trade. Moving to a higher timeframe usually provides more clarity.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.