OPEN-SOURCE SCRIPT
Auto-Lensed MACD + Z-Score v8.2

The AL-MACD represents a departure from static technical analysis. While traditional oscillators use fixed mathematical constants, this indicator treats the market as a living, breathing cycle that requires a dynamic "Lens" to view clearly.
1. The Core Innovation: The Adaptive Lens
Standard MACDs are often "too fast" in volatile markets (causing noise) or "too slow" in trending markets (causing lag).
How it works: The script constantly measures the distance between recent price pivots to determine the Market Tempo.
The Result: It automatically recalculates its own Fast, Slow, and Signal lengths. If the market cycle compresses, the MACD tightens to catch the move; if the cycle expands, the MACD smooths out to avoid fakeouts.
2. Statistical Extremity (Z-Score Integration)
We integrated a price-based Z-Score (Standard Deviation) logic to provide a "Mean Reversion" layer.
Normalization: The Z-Score is normalized to the MACD scale so that the threshold bands breathe with the momentum.
Exhaustion Coloring: The histogram turns Aqua or Magenta when the price is statistically overextended (sigma>2.0 SD). This tells you a move is "out of breath" even before a reversal begins.
3. Signal Intelligence & Noise Reduction
To solve the "dot cluster" problem common in divergence indicators, we implemented a Quiet Build architecture:
ATR Magnitude Filter: Divergences are ignored if the price move between pivots is too small to be significant.
Signal Cooldown: A mandatory "rest period" (default 15 bars) prevents the script from firing repeated signals during a slow grind.
Slope Filter: Ignores signals if the MACD momentum is essentially flat.
4. Visual Interface & Dashboard
The Dashboard: Provides a real-time "Flight Deck" including Lens Speed, Price Z-Score, and current Adaptive Lengths.
Timeframe Recommendations: A dynamic "Rec Pivot" feature that tells the user exactly which structural settings to use based on the current chart interval (15s vs. Daily).
Sniper Alerts: A confluence-based alert system that only triggers when a Divergence meets a Z-Score extremity—the "A+ Setup."
5. Strategy Cheat Sheet
Signal
Market Context
Action
Histogram Color Shift
Z-Score sigma> 2.0
Alert: Market is overextended.
"R" Triangle + Magenta/Aqua
Divergence at Extremity
Entry: High-conviction mean reversion (The Sniper).
Rising Lens Speed
Cycle lengths are increasing
Wait: Market is entering a slow, trending grind.
Falling Lens Speed
Cycle lengths are decreasing
Prep: Volatility is coiling; expect a fast move.
1. The Core Innovation: The Adaptive Lens
Standard MACDs are often "too fast" in volatile markets (causing noise) or "too slow" in trending markets (causing lag).
How it works: The script constantly measures the distance between recent price pivots to determine the Market Tempo.
The Result: It automatically recalculates its own Fast, Slow, and Signal lengths. If the market cycle compresses, the MACD tightens to catch the move; if the cycle expands, the MACD smooths out to avoid fakeouts.
2. Statistical Extremity (Z-Score Integration)
We integrated a price-based Z-Score (Standard Deviation) logic to provide a "Mean Reversion" layer.
Normalization: The Z-Score is normalized to the MACD scale so that the threshold bands breathe with the momentum.
Exhaustion Coloring: The histogram turns Aqua or Magenta when the price is statistically overextended (sigma>2.0 SD). This tells you a move is "out of breath" even before a reversal begins.
3. Signal Intelligence & Noise Reduction
To solve the "dot cluster" problem common in divergence indicators, we implemented a Quiet Build architecture:
ATR Magnitude Filter: Divergences are ignored if the price move between pivots is too small to be significant.
Signal Cooldown: A mandatory "rest period" (default 15 bars) prevents the script from firing repeated signals during a slow grind.
Slope Filter: Ignores signals if the MACD momentum is essentially flat.
4. Visual Interface & Dashboard
The Dashboard: Provides a real-time "Flight Deck" including Lens Speed, Price Z-Score, and current Adaptive Lengths.
Timeframe Recommendations: A dynamic "Rec Pivot" feature that tells the user exactly which structural settings to use based on the current chart interval (15s vs. Daily).
Sniper Alerts: A confluence-based alert system that only triggers when a Divergence meets a Z-Score extremity—the "A+ Setup."
5. Strategy Cheat Sheet
Signal
Market Context
Action
Histogram Color Shift
Z-Score sigma> 2.0
Alert: Market is overextended.
"R" Triangle + Magenta/Aqua
Divergence at Extremity
Entry: High-conviction mean reversion (The Sniper).
Rising Lens Speed
Cycle lengths are increasing
Wait: Market is entering a slow, trending grind.
Falling Lens Speed
Cycle lengths are decreasing
Prep: Volatility is coiling; expect a fast move.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.