From here
TASC 2024.09 Precision Trend Analysis — Indicator by PineCodersTASC — TradingView
and here
TRADERS’ TIPS - SEPTEMBER 2024 OVERVIEW:
This script introduces an approach for detecting and confirming trends in price series based on digital signal processing principles, as presented by John Ehlers in the "Precision Trend Analysis" article from the
September 2024 edition of TASC's Traders' Tips.
CONCEPTS:
Traditional trend-following indicators, such as
moving averages, are
low pass filters that pass low-frequency components in a series and remove high-frequency components. Because lowpass filters preserve lengthy cycles in the data while attenuating shorter cycles, such filters have unavoidable
lag that impacts the timeliness of trading signals.
In his article, John Ehlers presents an alternative approach that combines two
high pass filters with different lengths to remove undesired high-frequency content via
cancellation. High pass filters have nearly zero lag. As such, the resulting
trend indicator from this approach is very responsive to changes in the price series, with peaks and valleys that closely align with those of the price data. The indicator signifies an uptrend when its value is positive (i.e., above the balance point) and a downtrend when it is negative.
Subsequently, John Ehlers demonstrates that one can use the trend indicator's rate of change (ROC) to determine the onset of new trend movements. The ROC is zero at peaks and valleys in the trend indicator. Therefore, when the ROC crosses above zero, it signifies the onset or continuation of an uptrend. Likewise, the ROC crossing below zero indicates the onset or continuation of a downtrend. Note, however, that because the ROC does not preserve lower-frequency information, it can produce whipsaw trading signals in sideways or continuously trending price series.
This script implements both the trend indicator and its ROC along with the following on-chart signals:
CALCULATIONS:
The math behind the trend indicator comes from
digital - filter design principles. The first step applies a digital high pass filter that attenuates long cycles with periods above the user-specified critical period. The default value is 250 bars, representing roughly one year for instruments such as stocks on the daily timeframe. The next step applies a high pass filter with a shorter period (40 bars by default). The difference between these filters determines the trend indicator, which preserves cyclic components between 40 and 250 bars by default while attenuating and eliminating others. The ROC represents the scaled one-bar difference in the trend indicator.
Attached Image (click to enlarge)