OPEN-SOURCE SCRIPT
AetherEdge - Bayesian Changepoint Shift

🖊️ Overview
AE-SHIFT detects trend reversals as a probability using Bayesian Online Changepoint Detection (BOCPD, Adams & MacKay 2007). Rather than "did a moving average cross?", it asks "what is the probability that the current price regime just ended?" — computing a full posterior distribution over how long the current trend has lasted (run-length). An adaptive layer learns the hazard (reversal frequency) online from the spacing between changepoints, auto-adapting to each instrument's rhythm.
🔶 Key Features
Faithful BOCPD: sequential Bayesian update of the run-length posterior
Gaussian predictive likelihood + Welford online statistics: probabilistic evaluation of each regime hypothesis
Adaptive hazard learning: auto-estimates expected run-length λ from changepoint intervals
Quantifies changepoint probability 0-100%: clear reversal signal
Multi-layer glow rendering: luminous vertical lines at changepoints
Run-length distribution mini-heatmap: visualizes the distribution shape in the HUD
Probability-linked background pulse and segment trend line
BUY/SELL markers + per-event alerts
🧠 Technical Architecture
This implements the core BOCPD algorithm. Each bar maintains P(run-length = r | data) for r = 0..Rmax, with each hypothesis carrying Welford online statistics (mean/variance) of returns inside the segment. For each new observation, a Gaussian predictive likelihood π(x|r) is computed, weighted by the hazard function H = 1/λ, propagated forward (growth: r→r+1), with changepoint mass collapsed to r=0 and normalized. P(r=0) is the changepoint probability. Observations are ATR-normalized returns for scale stability. Adaptive hazard re-estimates λ from a moving average of detected changepoint intervals, dynamically adjusting the hazard. Signals fire when changepoint probability exceeds threshold + peaks + new segment direction. State updates occur on confirmed bars only to avoid repainting.
⚙️ Recommended Settings & Tuning Guide
Expected Run Length (λ) 50 is a starting point — larger for rare-reversal instruments and higher timeframes, smaller for frequently-flipping ones. Adaptive Hazard Learning ON is recommended to auto-learn the instrument's rhythm. Max Run Length Tracked 60 is a compute trade-off; raise to track longer regimes at higher cost. Changepoint Probability Threshold 0.25 baseline; 0.15 more sensitive, 0.4 stricter. Prior Variance / Observation Noise Variance tune the predictive distribution; raise Observation Noise for noisy instruments. Direction Confirmation 3 sets reversal-direction sensitivity.
💡 How to Use in Practice
Apply to chart and changepoints print luminous vertical lines with BUY/SELL labels. The glowing sub-band below price shows changepoint probability in real time — the hotter it glows, the nearer a reversal. The HUD's RUN-LENGTH DIST section is most important: high r=0 (reset) probability means a reversal is imminent, while dense r=21+ means a stable trend continues — read market state from the distribution shape. A sudden drop in expected run-length is a reversal precursor. The adaptive λ value tells you how many bars, on average, this instrument runs between reversals. Combining with other trend indicators and entering only when changepoint probability is high is effective.
⚠️ Important Notes
This is a truncated approximation of BOCPD (run-length truncated at Max) using a Gaussian predictive likelihood (a simplification of the full Student-t conjugate). The adaptive hazard is a heuristic estimate. It is classical sequential Bayesian inference — not deep Bayesian methods or machine learning — but the core BOCPD recursion is faithful to the original paper. Changepoint probability indicates the "possibility" of a reversal, not a certain prediction. Estimates become unstable in extreme volatility or with little initial data. Compute scales with the run-length limit; lower Max Run Length Tracked if it's heavy.
🚨 Disclaimer
This indicator is provided for educational and informational purposes only and does not constitute financial or investment advice. No signal guarantees future profit, and past performance does not indicate future results. All trading decisions are made at your own risk.
AE-SHIFT detects trend reversals as a probability using Bayesian Online Changepoint Detection (BOCPD, Adams & MacKay 2007). Rather than "did a moving average cross?", it asks "what is the probability that the current price regime just ended?" — computing a full posterior distribution over how long the current trend has lasted (run-length). An adaptive layer learns the hazard (reversal frequency) online from the spacing between changepoints, auto-adapting to each instrument's rhythm.
🔶 Key Features
Faithful BOCPD: sequential Bayesian update of the run-length posterior
Gaussian predictive likelihood + Welford online statistics: probabilistic evaluation of each regime hypothesis
Adaptive hazard learning: auto-estimates expected run-length λ from changepoint intervals
Quantifies changepoint probability 0-100%: clear reversal signal
Multi-layer glow rendering: luminous vertical lines at changepoints
Run-length distribution mini-heatmap: visualizes the distribution shape in the HUD
Probability-linked background pulse and segment trend line
BUY/SELL markers + per-event alerts
🧠 Technical Architecture
This implements the core BOCPD algorithm. Each bar maintains P(run-length = r | data) for r = 0..Rmax, with each hypothesis carrying Welford online statistics (mean/variance) of returns inside the segment. For each new observation, a Gaussian predictive likelihood π(x|r) is computed, weighted by the hazard function H = 1/λ, propagated forward (growth: r→r+1), with changepoint mass collapsed to r=0 and normalized. P(r=0) is the changepoint probability. Observations are ATR-normalized returns for scale stability. Adaptive hazard re-estimates λ from a moving average of detected changepoint intervals, dynamically adjusting the hazard. Signals fire when changepoint probability exceeds threshold + peaks + new segment direction. State updates occur on confirmed bars only to avoid repainting.
⚙️ Recommended Settings & Tuning Guide
Expected Run Length (λ) 50 is a starting point — larger for rare-reversal instruments and higher timeframes, smaller for frequently-flipping ones. Adaptive Hazard Learning ON is recommended to auto-learn the instrument's rhythm. Max Run Length Tracked 60 is a compute trade-off; raise to track longer regimes at higher cost. Changepoint Probability Threshold 0.25 baseline; 0.15 more sensitive, 0.4 stricter. Prior Variance / Observation Noise Variance tune the predictive distribution; raise Observation Noise for noisy instruments. Direction Confirmation 3 sets reversal-direction sensitivity.
💡 How to Use in Practice
Apply to chart and changepoints print luminous vertical lines with BUY/SELL labels. The glowing sub-band below price shows changepoint probability in real time — the hotter it glows, the nearer a reversal. The HUD's RUN-LENGTH DIST section is most important: high r=0 (reset) probability means a reversal is imminent, while dense r=21+ means a stable trend continues — read market state from the distribution shape. A sudden drop in expected run-length is a reversal precursor. The adaptive λ value tells you how many bars, on average, this instrument runs between reversals. Combining with other trend indicators and entering only when changepoint probability is high is effective.
⚠️ Important Notes
This is a truncated approximation of BOCPD (run-length truncated at Max) using a Gaussian predictive likelihood (a simplification of the full Student-t conjugate). The adaptive hazard is a heuristic estimate. It is classical sequential Bayesian inference — not deep Bayesian methods or machine learning — but the core BOCPD recursion is faithful to the original paper. Changepoint probability indicates the "possibility" of a reversal, not a certain prediction. Estimates become unstable in extreme volatility or with little initial data. Compute scales with the run-length limit; lower Max Run Length Tracked if it's heavy.
🚨 Disclaimer
This indicator is provided for educational and informational purposes only and does not constitute financial or investment advice. No signal guarantees future profit, and past performance does not indicate future results. All trading decisions are made at your own risk.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.