OPEN-SOURCE SCRIPT
AetherEdge - Flow Anomaly Markov

🖊️ Overview
AE-FAM detects abnormal large-participant activity statistically and forecasts what follows (continuation or reversal) with a learned Markov chain. Abnormal large activity can't be captured by a fixed volume threshold — what is abnormal depends on the joint distribution of volume and price movement, and that drifts over time. AE-FAM detects it adaptively with a 2D Mahalanobis distance and answers, via a conditional Markov chain, "after this kind of event, what has the market actually done?"
🔶 Key Features
2D Mahalanobis-distance anomaly detection — judges joint volume/movement anomalies against the recent covariance (not a fixed threshold)
Conditional Markov chain — learns 5-state transition probabilities online, modeled separately for anomaly vs normal bars
Post-event continuation / reversal probabilities and an expected-direction score
The same event reads as continuation or trap depending on the learned transitions
Anomaly-bar background highlight, bull/bear anomaly markers, and BUY/SELL signals from the expected direction
A gold HUD with Mahalanobis D², event type, current state, continuation/reversal %, expected score, and predicted next state
Stats and transitions update on closed bars — no repaint
🧠 Technical Architecture
Anomaly (Mahalanobis): the mean vector and 2×2 covariance of features [log(volume), |range|/ATR] are estimated online by EWMA, and each bar's Mahalanobis distance D² is computed with a closed-form 2×2 inverse (no matrix library). When D² exceeds a threshold and volume is above average, it is an "anomaly event"; direction is the return sign (bull/bear).
States (5 buckets): the return z-score is discretized into strong-down / down / flat / up / strong-up.
Markov chain (ML): a first-order Markov chain's transition counts (2×5×5 = [anomaly?][from][to]) are tallied online with a Laplace prior and aged by a decay factor for adaptation. The current state's transition row (conditioned on the current anomaly status) is normalized into a next-state distribution; the expected-direction score = Σ (state value) × probability, with continuation/reversal probabilities from the same row.
Honest scope: Mahalanobis anomaly detection plus a count-based first-order Markov chain. Not deep learning, and not a guarantee of the future.
⚙️ Recommended Settings & Tuning Guide
Key parameters: anomaly threshold (D²), covariance EWMA, transition memory (decay), expected-score threshold (thrScore), warmup.
Raise the D² threshold → only rarer, more extreme events (~9 is a strong 2-DoF outlier)
Raise the covariance EWMA → faster-adapting distribution estimate; lower → steadier
Lower decay → adapts faster to recent transition behavior; 1.0 → never forgets
Crypto starting points (tune on your chart):
BTC / ETH (15m–1H): defaults are the baseline (D² 9, decay 0.999)
SOL / XRP and high-vol alts: raise the D² threshold to ~11 to exclude noisy spikes
Scalping (1–5m): raise covariance EWMA (0.05) for fast adaptation, decay 0.995
Swing (4H–daily): longer warmup to fill the transition statistics, decay 1.0 to learn long-run tendencies
Raising thrScore narrows signals to events where the Markov expected direction is clear
💡 How to Use in Practice
Read intent: bull anomaly + high continuation = accumulation (follow), bull anomaly + high reversal = possible trap / liquidity grab (consider fading)
Expected-direction score: sign is the bias, magnitude the confidence; signals fire when this score and an anomaly event agree
Continuation/reversal %: quantifies the post-event tone — trend-follow when continuation dominates, stay cautious when reversal does
Mode display: post-event (just after an anomaly) vs normal switches which transition model is being read
Combinations: pair with AE-AMF's big-picture momentum or AE-IRM's mean-reversion probability, and use FAM's anomaly + transition forecast to judge entry quality
⚠️ Important Notes
Learning period: no signals until warmup bars; the covariance and transition matrix need time to spin up
Learning reset: changing inputs, symbol, or timeframe re-learns the internal state (covariance and transition counts)
Probability, not a guarantee: the Markov model is first-order (depends only on the latest state) and simple — it cannot capture complex dependencies
Depends on rare events: anomalies are rare, so a given state×anomaly transition statistic can be coarse until it accumulates
🚨 Disclaimer
This indicator is for educational and informational purposes only and is not financial advice or a recommendation to buy or sell. No method guarantees future profits; past performance does not indicate future results, and trading carries the risk of loss. All trading decisions are your own — use proper backtesting and disciplined risk management.
AE-FAM detects abnormal large-participant activity statistically and forecasts what follows (continuation or reversal) with a learned Markov chain. Abnormal large activity can't be captured by a fixed volume threshold — what is abnormal depends on the joint distribution of volume and price movement, and that drifts over time. AE-FAM detects it adaptively with a 2D Mahalanobis distance and answers, via a conditional Markov chain, "after this kind of event, what has the market actually done?"
🔶 Key Features
2D Mahalanobis-distance anomaly detection — judges joint volume/movement anomalies against the recent covariance (not a fixed threshold)
Conditional Markov chain — learns 5-state transition probabilities online, modeled separately for anomaly vs normal bars
Post-event continuation / reversal probabilities and an expected-direction score
The same event reads as continuation or trap depending on the learned transitions
Anomaly-bar background highlight, bull/bear anomaly markers, and BUY/SELL signals from the expected direction
A gold HUD with Mahalanobis D², event type, current state, continuation/reversal %, expected score, and predicted next state
Stats and transitions update on closed bars — no repaint
🧠 Technical Architecture
Anomaly (Mahalanobis): the mean vector and 2×2 covariance of features [log(volume), |range|/ATR] are estimated online by EWMA, and each bar's Mahalanobis distance D² is computed with a closed-form 2×2 inverse (no matrix library). When D² exceeds a threshold and volume is above average, it is an "anomaly event"; direction is the return sign (bull/bear).
States (5 buckets): the return z-score is discretized into strong-down / down / flat / up / strong-up.
Markov chain (ML): a first-order Markov chain's transition counts (2×5×5 = [anomaly?][from][to]) are tallied online with a Laplace prior and aged by a decay factor for adaptation. The current state's transition row (conditioned on the current anomaly status) is normalized into a next-state distribution; the expected-direction score = Σ (state value) × probability, with continuation/reversal probabilities from the same row.
Honest scope: Mahalanobis anomaly detection plus a count-based first-order Markov chain. Not deep learning, and not a guarantee of the future.
⚙️ Recommended Settings & Tuning Guide
Key parameters: anomaly threshold (D²), covariance EWMA, transition memory (decay), expected-score threshold (thrScore), warmup.
Raise the D² threshold → only rarer, more extreme events (~9 is a strong 2-DoF outlier)
Raise the covariance EWMA → faster-adapting distribution estimate; lower → steadier
Lower decay → adapts faster to recent transition behavior; 1.0 → never forgets
Crypto starting points (tune on your chart):
BTC / ETH (15m–1H): defaults are the baseline (D² 9, decay 0.999)
SOL / XRP and high-vol alts: raise the D² threshold to ~11 to exclude noisy spikes
Scalping (1–5m): raise covariance EWMA (0.05) for fast adaptation, decay 0.995
Swing (4H–daily): longer warmup to fill the transition statistics, decay 1.0 to learn long-run tendencies
Raising thrScore narrows signals to events where the Markov expected direction is clear
💡 How to Use in Practice
Read intent: bull anomaly + high continuation = accumulation (follow), bull anomaly + high reversal = possible trap / liquidity grab (consider fading)
Expected-direction score: sign is the bias, magnitude the confidence; signals fire when this score and an anomaly event agree
Continuation/reversal %: quantifies the post-event tone — trend-follow when continuation dominates, stay cautious when reversal does
Mode display: post-event (just after an anomaly) vs normal switches which transition model is being read
Combinations: pair with AE-AMF's big-picture momentum or AE-IRM's mean-reversion probability, and use FAM's anomaly + transition forecast to judge entry quality
⚠️ Important Notes
Learning period: no signals until warmup bars; the covariance and transition matrix need time to spin up
Learning reset: changing inputs, symbol, or timeframe re-learns the internal state (covariance and transition counts)
Probability, not a guarantee: the Markov model is first-order (depends only on the latest state) and simple — it cannot capture complex dependencies
Depends on rare events: anomalies are rare, so a given state×anomaly transition statistic can be coarse until it accumulates
🚨 Disclaimer
This indicator is for educational and informational purposes only and is not financial advice or a recommendation to buy or sell. No method guarantees future profits; past performance does not indicate future results, and trading carries the risk of loss. All trading decisions are your own — use proper backtesting and disciplined risk management.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.