peacefulLizard50262

Sinusoidal High Pass Filter (SHPF)

Sinusoidal High Pass Filter

This script implements a sinusoidal high pass filter, which is a type of digital filter that is used to remove low frequency components from a signal. The filter is defined by a series of weights that are applied to the input data, with the weights being determined by a sinusoidal function. The resulting filtered signal is then plotted on a chart, allowing the user to visualize the effect of the filter on the original signal.

The script begins by defining the sinusoidal_hpf function, which takes three arguments: _series, _period, and _phase_shift. The _series argument is the input data series that will be filtered, and the _period argument determines the length of the filter. The _phase_shift argument is an optional parameter that allows the user to adjust the phase of the sinusoidal function that is used to calculate the filter weights.

The function then initializes a variable ma to 0.0, and loops through each data point in the input series, starting from the most recent and going back in time for the specified _period number of points. For each data point, the function calculates a weight using a sinusoidal function, and adds the weighted data point to the ma variable. Finally, the function returns the average of the weighted data points by dividing ma by the _period.

The script also includes user input fields for the Length and Phase Shift parameters, which allows the user to customize the filter according to their specific needs. The filtered signal is then plotted on a chart, along with a reference line at 0.

Overall, this script provides a useful tool for analyzing and processing financial data, and can be easily customized to fit the needs of the user.

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?