OPEN-SOURCE SCRIPT

Nasan Hull-smoothed envelope

The Nasan Hull-Smoothed Envelope indicator is a sophisticated overlay designed to track price movement within an adaptive "envelope." It dynamically adjusts to market volatility and trend strength, using a series of smoothing and volatility-correction techniques. Here's a detailed breakdown of its components, from the input settings to the calculated visual elements:

Inputs
look_back_length (500):

Defines the lookback period for calculating intraday volatility (IDV), smoothing it over time. A higher value means the indicator considers a longer historical range for volatility calculations.

sl (50):

Sets the smoothing length for the Hull Moving Average (HMA). The HMA smooths various lines, creating a balance between sensitivity and stability in trend signals.

mp (1.5):

Multiplier for IDV, scaling the volatility impact on the envelope. A higher multiplier widens the envelope to accommodate higher volatility, while a lower one tightens it.
p (0.625):

Weight factor that determines the balance between extremes (highest high and lowest low) and averages (sma of high and sma of low) in the high/low calculations. A higher p gives more weight to extremes, making the envelope more responsive to abrupt market changes.
Volatility Calculation (IDV)
The Intraday Volatility (IDV) metric represents the average volatility per bar as an exponentially smoothed ratio of the high-low range to the close price. This is calculated over the look_back_length period, providing a base volatility value which is then scaled by mp. The IDV enables the envelope to dynamically widen or narrow with market volatility, making it sensitive to current market conditions.

Composite High and Low Bands
The high and low bands define the upper and lower bounds of the envelope.

High Calculation
a_high:

Uses a multi-period approach to capture the highest highs over several intervals (5, 8, 13, 21, and 34 bars). Averaging these highs provides a more stable reference for the high end of the envelope, capturing both immediate and recent peak values.
b_high:

Computes the average of shorter simple moving averages (5, 8, and 13 bars) of the high prices, smoothing out fluctuations in the recent highs. This generates a balanced view of high price trends.
high_c:

Combines a_high and b_high using the weight p. This blend creates a composite high that balances between recent peaks and smoothed averages, making the upper envelope boundary adaptive to short-term price shifts.
Low Calculation
a_low and b_low:

Similar to the high calculation, these capture extreme lows and smooth low values over the same intervals. This approach creates a stable and adaptive lower bound for the envelope.
low_c:

Combines a_low and b_low using the weight p, resulting in a composite low that adjusts to price fluctuations while maintaining a stable trend line.
Volatility-Adjusted Bands
The final composite high (c_high) and composite low (c_low) bands are adjusted using IDV, which accounts for intraday volatility. When volatility is high, the bands expand; when it’s low, they contract, providing a visual representation of volatility-adjusted price bounds.

Basis Line
The basis line is a Hull Moving Average (HMA) of the average of c_high and c_low. The HMA is known for its smoothness and responsiveness, making the basis line a central trend indicator. The color of the basis line changes:

Green when the basis line is increasing.
Red when the basis line is decreasing.
This color-coded basis line serves as a quick visual reference for trend direction.

Short-Term Trend Strength Block
This component analyzes recent price action to assess short-term bullish and bearish momentum.

Conditions (green, red, green1, red1):

These are binary conditions that categorize price movements as bullish or bearish based on the close compared to the open and the close’s relationship with the exponential moving average (EMA). This separation helps capture different types of strength (above/below EMA) and different bullish or bearish patterns.
Composite Trend Strength Values:

Each of the bullish and bearish counts (above and below the EMA) is normalized, resulting in the following values:
green_EMAup_a and red_EMAup_a for bullish and bearish strength above the EMA.
green_EMAdown_a and red_EMAdown_a for bullish and bearish strength below the EMA.
Trend Strength (t_s):

This calculated metric combines the normalized trend strengths with extra weight to conditions above the EMA, giving more relevance to trends that have momentum behind them.
Enhanced Trend Strength
avg_movement:

Calculates the average absolute price movement over the short_term_length, providing a measurement of recent price activity that scales with volatility.
enhanced_t_s:

Multiplies t_s by avg_movement, creating an enhanced trend strength value that reflects both directional strength and the magnitude of recent price movement.
min and max:

Minimum and maximum percentile thresholds, respectively, based on enhanced_t_s for controlling the color gradient in the fill area.
Fill Area
The fill area between plot_c_high and plot_c_low is color-coded based on the enhanced trend strength (enhanced_t_s):

Gradient color transitions from blue to green based on the strength level, with blue representing weaker trends and green indicating stronger trends.
This visual fill provides an at-a-glance assessment of trend strength across the envelope, with color shifts highlighting momentum shifts.

Summary
The indicator’s purpose is to offer an adaptive price envelope that reflects real-time market volatility and trend strength. Here’s what each component contributes:

Basis Line: A trend-following line in the center that adjusts color based on trend direction.
Envelope (c_high, c_low): Adapts to volatility by expanding and contracting based on IDV, giving traders a responsive view of expected price bounds.
Fill Area: A color-gradient region representing trend strength within the envelope, helping traders easily identify momentum changes.
Overall, this tool helps to identify trend direction, market volatility, and strength of price movements, allowing for more informed decisions based on visual cues around price boundaries and trend momentum.
Bands and ChannelsVolatility

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?

免责声明