Spinn29

Ehlers SuperSmoother

John F. Ehlers has provided the SuperSmoother filter in several of his works, including his book "Cyclical Analytics for Traders", Chapter 3.

The SuperSmoother filter is utilized whenever one might typically apply a moving average of any kind. The outcome is that the output signal from the SuperSmoother filter displays significantly less lag compared to an equivalent amount of smoothing from a moving average. The lag difference between a moving average and the SuperSmoother filter becomes even more pronounced when critical periods are extended.

Market data contains noise, and the purpose of smoothing filters is to mitigate this noise. In fact, there are various types of noise inherent in market data. One type of noise is systemic, originating from random trading activities. Another type is aliasing noise, which arises due to the use of discrete data. Aliasing noise dominates the data when considering shorter cycle durations.

It's tempting to perceive market data as a continuous wave, but that's a misconception. Taking the closing price as representative of a bar provides just a single data point. Whether you opt for the midpoint between the high and low instead of the closing price, you're still limited to one sample per bar. Given the discrete nature of this data, certain spectral implications must be considered. For instance, the shortest feasible analysis period (without aliasing) is a two-bar cycle. This is referred to as the Nyquist frequency, at 0.5 cycles per sample.

An ideally sampled two-beat sinusoidal cycle becomes rectified when discretized. However, peak sampling for the cycle isn't always guaranteed, and interference between the sampling rate and the data frequency results in aliasing noise. This noise decreases as the data period lengthens. For example, a four-beat cycle implies four samples per cycle. With more samples, the sampled data provides a better representation of the sinusoidal component. The replica becomes even more accurate for an eight-bar data component. The increased precision of discrete data signifies that aliasing noise decreases as cycle durations expand.

A smoothing filter should possess the selectivity to reduce the aliasing noise below systemic noise levels. Given that aliasing noise increases by 6 dB per octave above the filter's selected cutoff frequency and the SuperSmoother's attenuation rate is 12 dB per octave, the SuperSmoother filter emerges as an effective tool to virtually eliminate aliasing noise in its output signal.

There are already several SuperSmoother indicators on Tradingview, but I like to structure the code and highlight the main components as functions rather than hiding them in the code. I hope this is useful for those who are starting to learn Pine Script.
開源腳本

本著真正的TradingView精神,該腳本的作者將其開源發布,以便交易者可以理解和驗證它。為作者喝彩吧!您可以免費使用它,但在出版物中重複使用此代碼受網站規則的約束。 您可以收藏它以在圖表上使用。

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?