OPEN-SOURCE SCRIPT
已更新 Darvas Box Theory [Alpha Extract]

A sophisticated momentum breakout and trend-continuation framework based on Nicolas Darvas’ classic box theory, rebuilt with modern confirmation filters, adaptive risk management, and real-time trade-state tracking. This indicator identifies consolidation ranges, validates breakout conditions through volume and trend confirmation, manages long-side breakout entries, trails stops through higher boxes, and displays a live status dashboard for complete market structure awareness. By combining box compression, volatility filtering, breakout validation, and structured stop logic, the system provides a clean and disciplined framework for trading momentum expansion after consolidation.
🔶 Advanced Darvas Box Detection Engine
Implements a dynamic Darvas box construction model that identifies price consolidation ranges using configurable confirmation bars. The system continuously scans recent market structure, defines the highest high as the box ceiling, the lowest low as the box floor, and validates the range only when the box meets minimum volatility-adjusted height requirements.
Pine Script®
This ensures boxes are not created from meaningless low-range noise and instead represent tradable compression zones with enough structure to support breakout analysis.
🔶 ATR-Filtered Box Quality Control
Features an adaptive box validation system using Average True Range to measure whether a box has enough height relative to current market volatility. Traders can adjust the Minimum Box Height setting to control how selective the indicator becomes.
A lower ATR threshold creates more boxes and more frequent signals, while a higher threshold filters out weak consolidations and focuses only on larger, cleaner market structures.
🔶 Optional Rising Box Requirement
Includes an optional rising-box filter designed for classic Darvas-style momentum trading. When enabled, the system only accepts new boxes if their ceiling is higher than the previous box top, helping traders focus on progressive bullish structure and avoid lower-quality sideways chop.
This is useful for traders who want to trade continuation setups only when the market is forming higher price ranges.
🔶 Breakout Confirmation Framework
Provides flexible breakout detection using either candle close confirmation or wick-based confirmation. Close mode requires price to close beyond the box boundary for stronger confirmation, while Wick mode reacts as soon as price trades beyond the box level for faster but more aggressive signals.
Pine Script®
This allows traders to choose between conservative confirmation and faster momentum detection depending on their strategy style.
🔶 Volume Breakout Validation
Integrates volume confirmation to help filter weak breakouts and highlight expansion moves supported by stronger market participation. The system compares current volume against a moving average baseline and requires breakout volume to exceed a configurable multiplier.
This helps identify breakouts with real participation rather than low-volume fakeouts.
🔶 Trend Filter Integration
Uses a configurable EMA trend filter to align breakout signals with the broader market direction. When enabled, long breakout signals are only accepted when price is trading above the selected trend EMA.
This keeps the system focused on momentum continuation setups rather than counter-trend breakouts with weaker follow-through potential.
🔶 Automated Darvas Trade State Engine
Transforms box breakouts into a structured trade-management framework. When price breaks above a completed box with valid trend and volume confirmation, the system enters a long trade state, stores the entry price, initializes the stop level, and begins live trade tracking.
The indicator then monitors whether price continues into higher boxes, generates add signals, or exits when the stop or downside breakdown condition is triggered.
🔶 Add Signal & Higher Box Continuation Logic
Features higher-box continuation logic that identifies additional momentum opportunities while already in a long position. If a new confirmed breakout occurs above the original entry price while the trade is active, the system generates an Add signal and updates the trade structure.
This helps traders scale into trending moves as the market builds new Darvas boxes above the previous structure.
🔶 Adaptive Stop Management System
Provides three different stop modes for flexible risk management:
• Box Floor — places the stop at the bottom of the Darvas box.
• Breached Ceiling — uses the breakout ceiling as the protective reference.
• ATR — applies a volatility-adjusted trailing stop based on ATR.
Pine Script®
This allows traders to choose between structural, breakout-level, or volatility-based protection depending on their trading approach.
🔶 Trail Stop To Higher Boxes
Includes automatic stop advancement as price confirms higher boxes. When enabled, the stop trails upward with stronger box structures, helping lock in gains while allowing the trend to continue.
This creates a disciplined trend-following system that protects profits without exiting too early during strong momentum phases.
🔶 Breakdown & Exit Logic
Implements clean exit handling when price falls below the active trailing stop or breaks down through the box floor. This gives the system a defined invalidation structure and prevents trades from remaining active after momentum has failed.
Exit markers are displayed directly on the chart for fast visual confirmation.
🔶 Real-Time Status Dashboard
Features a compact live dashboard displaying the most important Darvas trade and box information in real time. The table shows:
• Current trade state
• Box top
• Box floor
• Volume ratio
• Trend filter status
• Distance to breakout
• Box height relative to ATR
• Open R multiple
This gives traders an immediate overview of whether the market is forming a box, preparing for breakout, actively in a trade, or filtered by trend/volume conditions.
🔶 Clean Visual Box Architecture
Creates a clear visual representation of forming and completed Darvas boxes using configurable colors, transparency, top and bottom level lines, breakout markers, exit markers, and optional grey candle overlay. Forming boxes are displayed separately from completed bullish or bearish boxes, making it easy to distinguish live consolidation from confirmed breakout structure.
The system also manages historical box limits automatically to keep charts clean and prevent visual overload.
🔶 Performance Optimization & Historical Box Management
Uses efficient array-based storage and automatic cleanup logic to manage historical boxes, lines, and chart objects. Traders can control how many completed boxes remain visible, allowing the indicator to preserve historical context while maintaining smooth TradingView performance.
This makes the tool suitable for both short-term and long-term chart analysis.
🔶 Comprehensive Alert System
Includes alert conditions for the most important Darvas events:
• Darvas Box Buy
• Darvas Box Add
• Darvas Box Exit
These alerts allow traders to monitor breakout opportunities, continuation setups, and invalidation events without watching the chart constantly.
🔶 Why Choose Darvas Box Theory [Alpha Extract]?
This indicator modernizes the classic Darvas Box strategy by combining traditional breakout structure with advanced confirmation logic, volatility filtering, dynamic stop management, and real-time trade monitoring. Instead of simply drawing static boxes, the system evaluates whether each range has enough volatility, confirms whether breakouts are backed by volume, checks whether price is aligned with the broader trend, and then manages the trade through structured stop logic.
The result is a clean momentum trading framework designed to help traders identify compression, wait for confirmed expansion, manage entries with discipline, scale into higher-box continuation, and exit when the structure fails. Perfect for trend-following traders, breakout traders, swing traders, and systematic momentum traders looking for a more complete version of the classic Darvas Box methodology.
🔶 Advanced Darvas Box Detection Engine
Implements a dynamic Darvas box construction model that identifies price consolidation ranges using configurable confirmation bars. The system continuously scans recent market structure, defines the highest high as the box ceiling, the lowest low as the box floor, and validates the range only when the box meets minimum volatility-adjusted height requirements.
This ensures boxes are not created from meaningless low-range noise and instead represent tradable compression zones with enough structure to support breakout analysis.
🔶 ATR-Filtered Box Quality Control
Features an adaptive box validation system using Average True Range to measure whether a box has enough height relative to current market volatility. Traders can adjust the Minimum Box Height setting to control how selective the indicator becomes.
A lower ATR threshold creates more boxes and more frequent signals, while a higher threshold filters out weak consolidations and focuses only on larger, cleaner market structures.
🔶 Optional Rising Box Requirement
Includes an optional rising-box filter designed for classic Darvas-style momentum trading. When enabled, the system only accepts new boxes if their ceiling is higher than the previous box top, helping traders focus on progressive bullish structure and avoid lower-quality sideways chop.
This is useful for traders who want to trade continuation setups only when the market is forming higher price ranges.
🔶 Breakout Confirmation Framework
Provides flexible breakout detection using either candle close confirmation or wick-based confirmation. Close mode requires price to close beyond the box boundary for stronger confirmation, while Wick mode reacts as soon as price trades beyond the box level for faster but more aggressive signals.
This allows traders to choose between conservative confirmation and faster momentum detection depending on their strategy style.
🔶 Volume Breakout Validation
Integrates volume confirmation to help filter weak breakouts and highlight expansion moves supported by stronger market participation. The system compares current volume against a moving average baseline and requires breakout volume to exceed a configurable multiplier.
This helps identify breakouts with real participation rather than low-volume fakeouts.
🔶 Trend Filter Integration
Uses a configurable EMA trend filter to align breakout signals with the broader market direction. When enabled, long breakout signals are only accepted when price is trading above the selected trend EMA.
This keeps the system focused on momentum continuation setups rather than counter-trend breakouts with weaker follow-through potential.
🔶 Automated Darvas Trade State Engine
Transforms box breakouts into a structured trade-management framework. When price breaks above a completed box with valid trend and volume confirmation, the system enters a long trade state, stores the entry price, initializes the stop level, and begins live trade tracking.
The indicator then monitors whether price continues into higher boxes, generates add signals, or exits when the stop or downside breakdown condition is triggered.
🔶 Add Signal & Higher Box Continuation Logic
Features higher-box continuation logic that identifies additional momentum opportunities while already in a long position. If a new confirmed breakout occurs above the original entry price while the trade is active, the system generates an Add signal and updates the trade structure.
This helps traders scale into trending moves as the market builds new Darvas boxes above the previous structure.
🔶 Adaptive Stop Management System
Provides three different stop modes for flexible risk management:
• Box Floor — places the stop at the bottom of the Darvas box.
• Breached Ceiling — uses the breakout ceiling as the protective reference.
• ATR — applies a volatility-adjusted trailing stop based on ATR.
This allows traders to choose between structural, breakout-level, or volatility-based protection depending on their trading approach.
🔶 Trail Stop To Higher Boxes
Includes automatic stop advancement as price confirms higher boxes. When enabled, the stop trails upward with stronger box structures, helping lock in gains while allowing the trend to continue.
This creates a disciplined trend-following system that protects profits without exiting too early during strong momentum phases.
🔶 Breakdown & Exit Logic
Implements clean exit handling when price falls below the active trailing stop or breaks down through the box floor. This gives the system a defined invalidation structure and prevents trades from remaining active after momentum has failed.
Exit markers are displayed directly on the chart for fast visual confirmation.
🔶 Real-Time Status Dashboard
Features a compact live dashboard displaying the most important Darvas trade and box information in real time. The table shows:
• Current trade state
• Box top
• Box floor
• Volume ratio
• Trend filter status
• Distance to breakout
• Box height relative to ATR
• Open R multiple
This gives traders an immediate overview of whether the market is forming a box, preparing for breakout, actively in a trade, or filtered by trend/volume conditions.
🔶 Clean Visual Box Architecture
Creates a clear visual representation of forming and completed Darvas boxes using configurable colors, transparency, top and bottom level lines, breakout markers, exit markers, and optional grey candle overlay. Forming boxes are displayed separately from completed bullish or bearish boxes, making it easy to distinguish live consolidation from confirmed breakout structure.
The system also manages historical box limits automatically to keep charts clean and prevent visual overload.
🔶 Performance Optimization & Historical Box Management
Uses efficient array-based storage and automatic cleanup logic to manage historical boxes, lines, and chart objects. Traders can control how many completed boxes remain visible, allowing the indicator to preserve historical context while maintaining smooth TradingView performance.
This makes the tool suitable for both short-term and long-term chart analysis.
🔶 Comprehensive Alert System
Includes alert conditions for the most important Darvas events:
• Darvas Box Buy
• Darvas Box Add
• Darvas Box Exit
These alerts allow traders to monitor breakout opportunities, continuation setups, and invalidation events without watching the chart constantly.
🔶 Why Choose Darvas Box Theory [Alpha Extract]?
This indicator modernizes the classic Darvas Box strategy by combining traditional breakout structure with advanced confirmation logic, volatility filtering, dynamic stop management, and real-time trade monitoring. Instead of simply drawing static boxes, the system evaluates whether each range has enough volatility, confirms whether breakouts are backed by volume, checks whether price is aligned with the broader trend, and then manages the trade through structured stop logic.
The result is a clean momentum trading framework designed to help traders identify compression, wait for confirmed expansion, manage entries with discipline, scale into higher-box continuation, and exit when the structure fails. Perfect for trend-following traders, breakout traders, swing traders, and systematic momentum traders looking for a more complete version of the classic Darvas Box methodology.
發行說明
Fixed minor error 開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
Access more of our systems and insights at alphaextract.xyz
All analysis provided by Alpha Extract is for educational and informational purposes only.
All analysis provided by Alpha Extract is for educational and informational purposes only.
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
Access more of our systems and insights at alphaextract.xyz
All analysis provided by Alpha Extract is for educational and informational purposes only.
All analysis provided by Alpha Extract is for educational and informational purposes only.
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。