OPEN-SOURCE SCRIPT

Probabilistic Bias Engine [JOAT]

1 138
Probabilistic Bias Engine [JOAT]

Introduction

The Probabilistic Bias Engine (PBE) is an advanced open-source directional bias indicator that combines Bayesian probability analysis, historical for-loop pattern recognition, multi-timeframe confluence detection, and ensemble learning to quantify market directional bias with statistical confidence. This indicator transforms raw price action into probabilistic bias scores (0-100%), helping traders identify high-probability directional setups through systematic analysis of historical price behavior across multiple timeframes.

Unlike simple trend indicators that use moving averages or momentum oscillators, PBE employs a sophisticated for-loop analysis system that compares current price against historical price points across customizable lookback periods, applies Bayesian probability theory to calculate directional likelihood, and aggregates signals across multiple timeframes to generate confidence-weighted bias scores. The indicator provides both current timeframe bias and multi-timeframe confluence analysis for comprehensive directional assessment.

cuplikan

Why This Indicator Exists

This indicator addresses the challenge of quantifying directional bias with statistical rigor. Traditional trend indicators provide binary signals (bullish/bearish) without probability quantification. PBE systematically analyzes historical price behavior to reveal:

  • Bayesian Probability Calculation: Converts for-loop analysis into probabilistic bias scores using Bayesian inference
  • Historical Pattern Recognition: Analyzes price position relative to 1-70 historical bars to identify directional patterns
  • Multi-Timeframe Confluence: Confirms bias across short (5m), medium (15m), and long (60m) timeframes
  • Ensemble For-Loop Analysis: Combines multiple lookback periods (30, 70, 150 bars) for robust bias calculation
  • Volatility Regime Scaling: Adjusts probability scores based on current volatility environment
  • Divergence Confirmation Layer: Detects RSI divergences to enhance signal quality
  • Confidence Heatmap: Visualizes setup quality through multi-factor confidence scoring (0-100%)


Each component provides unique intelligence. For-loop analysis shows historical price position, Bayesian calculation quantifies probability, MTF confluence shows conviction, ensemble analysis adds robustness, volatility scaling adjusts for regime, divergence layer confirms reversals, and confidence scoring synthesizes all factors.

Core Components Explained

1. For-Loop Historical Analysis

PBE's core innovation is systematic comparison of current price against historical price points:

Pine Script®


This function iterates through historical bars, adding +1 when current price is above historical price and -1 when below. The normalized result ranges from -1.0 (price below all historical points) to +1.0 (price above all historical points).

2. Bayesian Probability Calculation

The for-loop score is converted to probability using Bayesian inference:

Pine Script®


This calculates the posterior probability of bullish bias given the for-loop evidence. Positive loop values increase bullish probability, negative values increase bearish probability. The result is scaled to 0-100% for display.

image]cuplikan

3. Multi-Timeframe Confluence Detection

PBE requests bias data from three timeframes and counts alignment:

Pine Script®


Confluence is calculated by counting how many timeframes agree:
  • Strong Aligned (4/4): All timeframes bullish or bearish - highest conviction
  • Aligned (3/4): Majority alignment - moderate conviction
  • Weak (2/4): Split alignment - low conviction
  • No Alignment (1/4 or 0/4): Conflicting signals - no conviction


4. Ensemble For-Loop Analysis

Multiple lookback periods are combined for robust bias calculation:

Pine Script®


Short-term bias (30 bars) receives 50% weight, medium-term (70 bars) receives 30%, and long-term (150 bars) receives 20%. This creates a balanced view across multiple time horizons.

5. Volatility Regime Scaling

Probability scores are adjusted based on volatility environment:

Pine Script®


High volatility reduces probability scores (more uncertainty), while low volatility increases scores (more predictable).

6. Divergence Confirmation Layer

RSI divergences are detected to enhance signal quality:

Pine Script®


Divergences add 20 points to confidence score and trigger enhanced signals when combined with probability alignment.

cuplikan

7. Confidence Heatmap Visualization

Multi-factor confidence scoring (0-100%) based on:

  • Probability Strength (0-40 points): Distance from 50% neutral (max 40 points at 100% or 0%)
  • MTF Alignment (0-30 points): 30 points for 4/4 alignment, 20 for 3/4, 10 for 2/4
  • Divergence Confirmation (0-20 points): 20 points when divergence detected
  • Regime Favorability (0-10 points): 10 points for Normal/Low vol, 5 for Very Low, 0 for High vol


Total confidence score determines background heatmap intensity:
  • 80-100%: Strong signal (bright color, low transparency)
  • 60-79%: Moderate signal (medium color, medium transparency)
  • 40-59%: Weak signal (dim color, high transparency)
  • 0-39%: No signal (neutral color)


Visual Elements

  • Probability Line: Main plot showing smoothed probability (0-100%) with dynamic coloring
  • Zero-Lag Line: Circles overlay showing zero-lag probability for early signals
  • Histogram: Gradient-colored histogram showing probability deviation from 50% neutral
  • Reference Lines: 70% (strong bullish), 50% (neutral), 30% (strong bearish)
  • Background Zones: Strong bullish (>70%), strong bearish (<30%) with transparency
  • Confidence Heatmap: Background intensity based on multi-factor confidence score
  • Signal Shapes: High conviction bull/bear setups, regime shifts, divergence confirmations
  • Dashboard: Real-time metrics including current probability, strength, MTF alignment, ensemble score, volatility regime, confidence, and divergence status


Input Parameters

Bayesian Parameters:
  • Price Source: Data source for calculations (default: hlc3)
  • Bayesian Period: Smoothing period for probability (default: 14)
  • Signal Smoothing: EMA smoothing for final probability (default: 2)


Historical Analysis:
  • Loop Start: Starting bar for for-loop analysis (default: 1)
  • Loop Lookback: Ending bar for for-loop analysis (default: 70)


Multi-Timeframe Confluence:
  • Enable MTF Confluence: Toggle multi-timeframe analysis (default: enabled)
  • Short Timeframe: Fast timeframe for confluence (default: 5m)
  • Medium Timeframe: Medium timeframe for confluence (default: 15m)
  • Long Timeframe: Slow timeframe for confluence (default: 60m)
  • Confluence Requirement: Minimum timeframes required (default: 2)


Visualization:
  • Show Probability Bands: Toggle 70%/30% reference lines
  • Show Bias Zones: Toggle background coloring for strong bias
  • Show Histogram: Toggle probability deviation histogram


How to Use This Indicator

Step 1: Monitor Probability Level
Watch the main probability line. >70% indicates strong bullish bias, <30% indicates strong bearish bias, 40-60% is neutral.

Step 2: Check MTF Confluence
Verify dashboard shows "Strong Aligned" or "Aligned" status. Higher alignment = higher conviction.

Step 3: Assess Confidence Score
Dashboard confidence >70% indicates high-quality setup. >80% is exceptional.

Step 4: Confirm with Ensemble
Ensemble probability should align with current probability. Divergence suggests conflicting time horizons.

Step 5: Consider Volatility Regime
"Normal" or "Low Vol" regimes have higher reliability. "High Vol" regimes require extra caution.

Step 6: Wait for High Conviction Signals
Best setups occur when:
- Probability >65% or <35%
- Confidence >70%
- MTF alignment 3/4 or 4/4
- Cooldown period passed (12+ bars since last signal)

Best Practices

  • Use probability crossovers of 50% as regime shift signals
  • Combine with price action - probability shows bias, price shows execution
  • MTF alignment is most reliable during trending markets
  • Confidence heatmap provides quick visual assessment of setup quality
  • Divergence signals add significant edge when combined with probability alignment
  • Ensemble probability provides longer-term context - use for position bias
  • Volatility regime scaling is critical - reduce size in high vol environments
  • Zero-lag line provides early warning of probability shifts
  • Histogram intensity shows conviction - larger bars = stronger bias


cuplikan

Indicator Limitations

  • For-loop analysis is computationally intensive - may slow on lower-end devices
  • Probability scores are based on historical patterns - unprecedented events can invalidate
  • MTF confluence requires sufficient data on all timeframes
  • Bayesian calculation assumes price behavior follows historical patterns
  • High volatility reduces probability reliability - regime scaling helps but doesn't eliminate
  • Divergence detection requires clear pivot formation - may lag in choppy markets
  • Confidence scoring is multi-factor but still probabilistic - not deterministic
  • Zero-lag calculation can produce whipsaws during consolidation


Technical Implementation

Built with Pine Script v6 using:
  • Custom for-loop historical analysis across 1-70 bars
  • Bayesian probability calculation with evidence-based inference
  • Multi-timeframe security requests for 5m, 15m, 60m confluence
  • Ensemble for-loop analysis with weighted averaging (30, 70, 150 bars)
  • ATR-based volatility regime classification with percentile ranking
  • RSI divergence detection using pivot analysis
  • Multi-factor confidence scoring (probability, MTF, divergence, regime)
  • Zero-lag EMA calculation for early signal detection
  • Gradient histogram with dynamic coloring based on probability
  • Confidence heatmap background with intensity scaling
  • Signal cooldown system (12 bars minimum) to prevent overtrading


The code is fully open-source and can be modified to suit individual trading styles.

Originality Statement

This indicator is original in its probabilistic bias quantification approach. While for-loop analysis and Bayesian probability are established concepts, this indicator is justified because:

  • It combines systematic for-loop historical analysis with Bayesian probability theory for statistical rigor
  • The ensemble for-loop system (30, 70, 150 bars) with weighted averaging is unique
  • Multi-timeframe confluence detection provides conviction measurement across 4 timeframes
  • Volatility regime scaling adjusts probability scores based on market environment
  • Divergence confirmation layer adds reversal detection to directional bias
  • Multi-factor confidence scoring (probability + MTF + divergence + regime) synthesizes all components
  • Zero-lag overlay provides early warning system for probability shifts
  • Confidence heatmap visualization makes setup quality immediately apparent


Each component contributes unique information: for-loop shows historical position, Bayesian quantifies probability, MTF shows conviction, ensemble adds robustness, volatility scales for regime, divergence confirms reversals, confidence synthesizes quality, and zero-lag provides early warning. The indicator's value lies in presenting these complementary perspectives simultaneously with unified probabilistic framework.

Disclaimer

This indicator is provided for educational and informational purposes only. It is not financial advice. Probability scores do not guarantee outcomes. Trading involves substantial risk of loss. Past performance does not guarantee future results. Always use proper risk management and never risk more than you can afford to lose.

-Made with passion by officialjackofalltrades

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.