에디터즈 픽
OPEN-SOURCE SCRIPT

Fast Fourier Transform (FFT) Filter

업데이트됨
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.
​​
릴리즈 노트
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
릴리즈 노트
  • 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.
cycleanalysisCyclesfilterfouriertransformTrend AnalysisVolatility

오픈 소스 스크립트

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

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


DISCLAIMER: I am not a financial advisor, and my scripts are for educational purposes only. Any trades you make are at your own risk.

면책사항