tbiktag

Fast Fourier Transform (FFT) Filter

tbiktag Cập nhật   
Dear friends!
I'm happy to present an implementation of the Fast Fourier Transform (FFT) algorithm. The script uses the FFT procedure to decompose the input time series into its cyclical constituents, in other words, its frequency components, and convert it back to the time domain with modified frequency content, that is, to filter it.

Input Description and Usage

Source and Length:
Indicates where the data comes from and the size of the lookback window used to build the dataset.

Standardize Input Dataset:
If enabled, the dataset is preprocessed by subtracting its mean and normalizing the result by the standard deviation, which is sometimes useful when analyzing seasonalities. This procedure is not recommended when using the FFT filter for smoothing (see below), as it will not preserve the average of the dataset.

Show Frequency-Domain Power Spectrum:
When enabled, the results of Fourier analysis (for the last price bar!) are plotted as a frequency-domain power spectrum, where “power” is a measure of the significance of the component in the dataset. In the spectrum, lower frequencies (longer cycles) are on the right, higher frequencies are on the left. The graph does not display the 0th component, which contains only information about the mean value. Frequency components that are allowed to pass through the filter (see below) are highlighted in magenta.

Dominant Cycles, Rows:
If this option is activated, the periods and relative powers of several dominant cyclical components that is, those that have a higher power, are listed in the table. The number of the component in the power spectrum (N) is shown in the first column. The number of rows in the table is defined by the user.

Show Inverse Fourier Transform (Filtered):
When enabled, the reconstructed and filtered time-domain dataset (for the last price bar!) is displayed.

Apply FFT Filter in a Moving Window:
When enabled, the FFT filter with the same parameters is applied to each bar. The last data point of the reconstructed​ and filtered dataset is used to build a new time series. For example, by getting rid of high-frequency noise, the FFT filter can make the data smoother. By removing slowly evolving low-frequency components (including non-periodic constituents), one can reveal and analyze shorter cycles. Since filtering is done in real-time in a moving window (similar to the moving average), the modified data can potentially be used as part of a strategy and be subjected to other technical indicators.

Lowest Allowed N:
Indicates the number of the lowest frequency component used in the reconstructed time series.

Highest Allowed N:
Indicates the number of the highest frequency component used in the reconstructed time series.

Filtering Time Range block:
Specifies the time range over which real-time FFT filtering is applied. The reason for the presence of this block is that the FFT procedure is relatively computationally intensive. Therefore, the script execution may encounter the time limit imposed by TradingView when all historical bars are processed.

As always, I look forward to your feedback!
Also, leave a comment if you'd be interested in the tutorial on how to use this tool and/or in seeing the FFT filter in a strategy.
​​
Phát hành các Ghi chú:
following issues improved:
- consistency in the definition of the lower and upper thresholds
- zeroth element removed from the table in order to avoid artefacts for non-standardized data
Phát hành các Ghi chú:
  • Transferred to Pine Script v.5.
  • The FFT function is now imported from the FFTLibrary.
Problem fixed:
  • The graphs are now correctly redrawn with each new time step.

DISCLAIMER: I am not a financial advisor, and my scripts are for educational purposes only. Any trades you make are at your own risk.
Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?