OPEN-SOURCE SCRIPT

TASC 2024.09 Precision Trend Analysis

PineCodersTASC의
█ 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 lowpass 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 highpass filters with different lengths to remove undesired high-frequency content via cancellation. Highpass 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:
• Green and red arrows that indicate the possible onset or continuation of an uptrend and downtrend, respectively
• Bar and plot colors that signify the sign (direction) of the trend indicator


█ CALCULATIONS

The math behind the trend indicator comes from digital filter design principles. The first step applies a digital highpass 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 highpass 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.
ehlersTrend Analysis
PineCodersTASC
Tools and ideas for all Pine coders: tradingview.com/u/PineCoders/
Pine news broadcasts: t.me/PineCodersSquawkBox or twitter.com/PineCoders
TASC: traders.com/

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?

면책사항