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. اقرأ المزيد في شروط الاستخدام.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟