This custom Pine Script indicator combines Trend Lines with the Triangular Hull Moving Average (THMA) and Volatility analysis. It uses the concept of pivot points for detecting potential trend lines and blends it with the smoothed THMA and volatility to identify market trends and changes.
Key Components:
Trend Lines:
The indicator calculates pivot highs (ph) and pivot lows (pl) based on a period defined by the user (prd).
The number of pivot points to check (PPnum) is also configurable.
Pivot points are used to create trend lines (both uptrend and downtrend lines) based on the highest and lowest values within the given range.
The trend lines are drawn when certain conditions are met, indicating a continuation of a trend.
THMA-Vol:
The Triangular Hull Moving Average (THMA) is a variation of the Hull Moving Average (HMA) that provides smoother results.
Volatility is measured using the difference between high and low prices, then applying an HMA to this range.
The volatility bands around the THMA indicate the market’s volatility.
The indicator plots shapes to represent buy and sell signals when the THMA crosses over or under its previous value:
A buy signal is triggered when the THMA crosses above its past value.
A sell signal is triggered when the THMA crosses below its past value.
Trade Signals:
Uptrend signals are marked with a green triangle above the price, and downtrend signals are marked with a red triangle below the price.
These signals are plotted with respect to the Average True Range (ATR), which helps visualize the volatility.
Visual Representation:
The indicator uses candle plotting with volatility bands around the THMA to represent the market trend.
The trend is color-coded:
Green color for uptrend (when THMA is above its previous value).
Red color for downtrend (when THMA is below its previous value).
Volatility:
A volatility calculation is based on the Hull Moving Average (HMA) applied to the high-low range of the market. This value is then normalized using the percentile of the volatility.
The volatility bands are plotted around the THMA, helping visualize the market's "tightness" or "expansion."
Inputs/Settings:
Pivot Period (prd): Determines how far back the script looks for pivot points.
Number of Pivot Points (PPnum): Defines how many pivot points are checked to form trend lines.
THMA Length (len_): The smoothing period for the Triangular Hull Moving Average.
Volatility Length (len_vol): The period used for calculating volatility.
Volatility Visualization: Allows the user to toggle the visibility of the volatility bands.
How It Works:
Trend Lines:
The script first calculates potential pivot highs and lows, then checks if those points form valid trend lines.
The trend lines are drawn based on the confirmed pivot points that indicate a possible uptrend or downtrend.
THMA and Volatility Bands:
The THMA is calculated by smoothing the price data using weighted moving averages (WMA).
Volatility is calculated based on the difference between the high and low prices over a period, and the bands around THMA show the market's volatility.
The indicator generates buy and sell signals based on the THMA crossover strategy (THMA crossing its previous value).
Visual Signals:
Buy signals are represented by green triangles when the THMA crosses above its past value.
Sell signals are represented by red triangles when the THMA crosses below its previous value.
Usage:
Trend Lines provide a way to visualize support and resistance levels in the market.
THMA-Vol helps to identify the current market direction and potential trend shifts based on smooth moving averages and volatility.
The combination of trend lines with volatility and smoothed averages allows traders to make more informed decisions based on both market trends and volatility levels.