OPEN-SOURCE SCRIPT
Hazel nut BB Strategy, volume base- lite version

Hazel nut BB Strategy, volume base — lite version
Having knowledge and information in financial markets is only useful when a trader operates with a well-defined trading strategy. Trading strategies assist in capital management, profit-taking, and reducing potential losses.
This strategy is built upon the core principle of supply and demand dynamics. Alongside this foundation, one of the widely used technical tools — the Bollinger Bands — is employed to structure a framework for profit management and risk control.
In this strategy, the interaction of these tools is explained in detail. A key point to note is that for calculating buy and sell volumes, a lower timeframe function is used. When applied with a tick-level resolution, this provides the most precise measurement of buyer/seller flows. However, this comes with a limitation of reduced historical depth. Users should be aware of this trade-off: if precise tick-level data is required, shorter timeframes should be considered to extend historical coverage.
The strategy offers multiple configuration options. Nevertheless, it should be treated strictly as a supportive tool rather than a standalone trading system. Decisions must integrate personal analysis and other instruments. For example, in highly volatile assets with narrow ranges, it is recommended to adjust profit-taking and stop-loss percentages to smaller values.
◉ Volume Settings
• Buyer and seller volume (up/down volume) are requested from a lower timeframe, with an option to override the automatic resolution.
• A global lookback period is applied to calculate moving averages and cumulative sums of buy/sell/delta volumes.
• Ratios of buyers/sellers to total volume are derived both on the current bar and across the lookback window.

◉ Bollinger Band
• Bands are computed using configurable moving averages (SMA, EMA, RMA, WMA, VWMA).
• Inputs allow control of length, standard deviation multiplier, and offset.
• The basis, upper, and lower bands are plotted, with a shaded background between them.

◉ Progress & Proximity
• Relative position of the price to the Bollinger basis is expressed as percentages (qPlus/qMinus).
• “Near band” conditions are triggered when price progress toward the upper or lower band exceeds a user-defined threshold (%).
• A signed score (sScore) represents how far the close has moved above or below the basis relative to band width.
◉ Info Table
• Optional compact table summarizing:
• - Upper/lower band margins
• - Buyer/seller volumes with moving averages
• - Delta and cumulative delta
• - Buyer/seller ratios per bar and across the window
• - Money flow values (buy/sell/delta × price) for bar-level and summed periods
• The table is neutral-colored and resizable for different chart layouts.

◉ Zone Event Gate
• Tracks entry into and exit from “near band” zones.
• Arming logic: a side is armed when price enters a band proximity zone.
• Trigger logic: on exit, a trade event is generated if cumulative buyer or seller volume dominates over a configurable window.
◉ Trading Logic
• Orders are placed only on zone-exit events, conditional on volume dominance.
• Position sizing is defined as a fixed percentage of strategy equity.
• Long entries occur when leaving the lower zone with buyer dominance; short entries occur when leaving the upper zone with seller dominance.
◉ Exit Rules
• Open positions are managed by a strict priority sequence:
• 1. Stop-loss (% of entry price)
• 2. Take-profit (% of entry price)
• 3. Opposite-side event (zone exit with dominance in the other direction)
• Stop-loss and take-profit levels are configurable

◉ Notes
• This lite version is intended to demonstrate the interaction of Bollinger Bands and volume-based dominance logic.
• It provides a framework to observe how price reacts at band boundaries under varying buy/sell pressure, and how zone exits can be systematically converted into entry/exit signals.
When configuring this strategy, it is essential to carefully review the settings within the Strategy Tester. Ensure that the chosen parameters and historical data options are correctly aligned with the intended use. Accurate back testing depends on applying proper configurations for historical reference. The figure below illustrates sample result and configuration type.

Having knowledge and information in financial markets is only useful when a trader operates with a well-defined trading strategy. Trading strategies assist in capital management, profit-taking, and reducing potential losses.
This strategy is built upon the core principle of supply and demand dynamics. Alongside this foundation, one of the widely used technical tools — the Bollinger Bands — is employed to structure a framework for profit management and risk control.
In this strategy, the interaction of these tools is explained in detail. A key point to note is that for calculating buy and sell volumes, a lower timeframe function is used. When applied with a tick-level resolution, this provides the most precise measurement of buyer/seller flows. However, this comes with a limitation of reduced historical depth. Users should be aware of this trade-off: if precise tick-level data is required, shorter timeframes should be considered to extend historical coverage.
The strategy offers multiple configuration options. Nevertheless, it should be treated strictly as a supportive tool rather than a standalone trading system. Decisions must integrate personal analysis and other instruments. For example, in highly volatile assets with narrow ranges, it is recommended to adjust profit-taking and stop-loss percentages to smaller values.
◉ Volume Settings
• Buyer and seller volume (up/down volume) are requested from a lower timeframe, with an option to override the automatic resolution.
• A global lookback period is applied to calculate moving averages and cumulative sums of buy/sell/delta volumes.
• Ratios of buyers/sellers to total volume are derived both on the current bar and across the lookback window.
◉ Bollinger Band
• Bands are computed using configurable moving averages (SMA, EMA, RMA, WMA, VWMA).
• Inputs allow control of length, standard deviation multiplier, and offset.
• The basis, upper, and lower bands are plotted, with a shaded background between them.
◉ Progress & Proximity
• Relative position of the price to the Bollinger basis is expressed as percentages (qPlus/qMinus).
• “Near band” conditions are triggered when price progress toward the upper or lower band exceeds a user-defined threshold (%).
• A signed score (sScore) represents how far the close has moved above or below the basis relative to band width.
◉ Info Table
• Optional compact table summarizing:
• - Upper/lower band margins
• - Buyer/seller volumes with moving averages
• - Delta and cumulative delta
• - Buyer/seller ratios per bar and across the window
• - Money flow values (buy/sell/delta × price) for bar-level and summed periods
• The table is neutral-colored and resizable for different chart layouts.
◉ Zone Event Gate
• Tracks entry into and exit from “near band” zones.
• Arming logic: a side is armed when price enters a band proximity zone.
• Trigger logic: on exit, a trade event is generated if cumulative buyer or seller volume dominates over a configurable window.
◉ Trading Logic
• Orders are placed only on zone-exit events, conditional on volume dominance.
• Position sizing is defined as a fixed percentage of strategy equity.
• Long entries occur when leaving the lower zone with buyer dominance; short entries occur when leaving the upper zone with seller dominance.
◉ Exit Rules
• Open positions are managed by a strict priority sequence:
• 1. Stop-loss (% of entry price)
• 2. Take-profit (% of entry price)
• 3. Opposite-side event (zone exit with dominance in the other direction)
• Stop-loss and take-profit levels are configurable
◉ Notes
• This lite version is intended to demonstrate the interaction of Bollinger Bands and volume-based dominance logic.
• It provides a framework to observe how price reacts at band boundaries under varying buy/sell pressure, and how zone exits can be systematically converted into entry/exit signals.
When configuring this strategy, it is essential to carefully review the settings within the Strategy Tester. Ensure that the chosen parameters and historical data options are correctly aligned with the intended use. Accurate back testing depends on applying proper configurations for historical reference. The figure below illustrates sample result and configuration type.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.