OPEN-SOURCE SCRIPT
Directional Bias by Ibramiho

Description: Optimized Directional Bias (PySR Engineered)
Overview
The Directional Bias indicator is a sophisticated trend-identification tool designed to filter out market noise and establish a high-conviction directional "anchor." Unlike standard moving averages that often lag or react haphazardly to volatility, this script utilizes a custom bias kernel derived through Symbolic Regression (PySR).
The goal of this indicator is to provide the stability of a higher-timeframe regression model while maintaining the responsiveness required for live trading.
The Engineering Behind the Bias
Most directional filters suffer from instability when attempting to incorporate momentum and acceleration. To solve this, this script calculates the Distance, Momentum, and Acceleration of three distinct moving average types:
The core "Bias" value is calculated using a non-linear equation discovered via PySR. This formula intelligently weights the TMA Momentum against the EMA Acceleration and SMA Distance, normalized by the Average True Range (ATR) to ensure the bias adapts to current market volatility.
The final result is a smoothed "Bias Line" that acts as a definitive trend filter:
Bullish Bias (Orange): Indicates the engineered kernel is sloping upward, suggesting long-term accumulation or momentum.
Bearish Bias (Purple): Indicates the kernel is sloping downward, suggesting distribution or selling pressure.
Accumulation/Consolidation: When the market enters a period of compression, price is often very close to the Bias Line, signaling a phase of extreme indecision. In this zone, the calculated momentum and acceleration components of the kernel reach a near-neutral state, causing the indicator to become highly sensitive to minor fluctuations. Traders should exercise caution during these "tight" clusters, as the equilibrium between the SMA, EMA, and TMA derivatives makes the script prone to quick bias flips.
Key Features
How to Use
Trend Filter: Only look for Long opportunities when the Bias Line is Orange and Short opportunities when it is Purple.
Mean Reversion: Large gaps between the price and the Bias Line often signal an overextended market, suggesting a potential snap-back to the mean.
Trend Reversals: A color change in the Bias Line serves as an early warning that the higher-timeframe structural momentum is shifting.
Settings
Smooth Length: Controls the final smoothing of the bias plot. Increase for a "slower" feel; decrease for more sensitivity.
MA Length: The lookback period for the underlying SMA, EMA, and TMA components. (Defaulted to 558 for deep-trend analysis, optimized for capturing institutional-grade cycles).
Overview
The Directional Bias indicator is a sophisticated trend-identification tool designed to filter out market noise and establish a high-conviction directional "anchor." Unlike standard moving averages that often lag or react haphazardly to volatility, this script utilizes a custom bias kernel derived through Symbolic Regression (PySR).
The goal of this indicator is to provide the stability of a higher-timeframe regression model while maintaining the responsiveness required for live trading.
The Engineering Behind the Bias
Most directional filters suffer from instability when attempting to incorporate momentum and acceleration. To solve this, this script calculates the Distance, Momentum, and Acceleration of three distinct moving average types:
- Simple Moving Average (SMA): For baseline structural trend.
- Exponential Moving Average (EMA): For price sensitivity.
- Triangular Moving Average (TMA): For ultra-smooth directional flow.
The core "Bias" value is calculated using a non-linear equation discovered via PySR. This formula intelligently weights the TMA Momentum against the EMA Acceleration and SMA Distance, normalized by the Average True Range (ATR) to ensure the bias adapts to current market volatility.
The final result is a smoothed "Bias Line" that acts as a definitive trend filter:
Bullish Bias (Orange): Indicates the engineered kernel is sloping upward, suggesting long-term accumulation or momentum.
Bearish Bias (Purple): Indicates the kernel is sloping downward, suggesting distribution or selling pressure.
Accumulation/Consolidation: When the market enters a period of compression, price is often very close to the Bias Line, signaling a phase of extreme indecision. In this zone, the calculated momentum and acceleration components of the kernel reach a near-neutral state, causing the indicator to become highly sensitive to minor fluctuations. Traders should exercise caution during these "tight" clusters, as the equilibrium between the SMA, EMA, and TMA derivatives makes the script prone to quick bias flips.
Key Features
- Volatility Normalized: By using ATR in the core calculation, the indicator remains consistent across different assets and timeframes.
- Multi-Derivative Analysis: It doesn't just look at price; it analyzes the speed and rate of change of the trend.
- No Repainting: Unlike traditional regression-based kernels that shift when new data arrives, this equation is calculated purely on historical bars, making it stable for live execution.
How to Use
Trend Filter: Only look for Long opportunities when the Bias Line is Orange and Short opportunities when it is Purple.
Mean Reversion: Large gaps between the price and the Bias Line often signal an overextended market, suggesting a potential snap-back to the mean.
Trend Reversals: A color change in the Bias Line serves as an early warning that the higher-timeframe structural momentum is shifting.
Settings
Smooth Length: Controls the final smoothing of the bias plot. Increase for a "slower" feel; decrease for more sensitivity.
MA Length: The lookback period for the underlying SMA, EMA, and TMA components. (Defaulted to 558 for deep-trend analysis, optimized for capturing institutional-grade cycles).
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.