Fourier Transform

Category: Indicators By: gabri Created: September 5, 2019, 8:57 AM
September 5, 2019, 8:57 AM
Indicators
1 Comment

This code is the translation from an indicator made by Ehler and found on TradingView. It returns the Fourier wave for a specific period of time. The period of time should be a multiple of a measured historical cycle.

Blue skies!!

src3 = (close)
Period = 20
Bandwidth = 0.1//don't change this setting too much
X1 = src3 - src3[2]
L1 = cos(360/period)
L2 = cos(360/(period/2))
L3 = cos(360/(period/3))
G1 = cos((Bandwidth*360/Period))
G2 = cos(Bandwidth*360/(Period/2))
G3 = cos(Bandwidth*360/(Period/3))
S1 = 1/G1 - sqrt(1/(G1*G1)-1)
S2 = 1/G2 - sqrt(1/(G2*G2)-1)
S3 = 1/G3 - sqrt(1/(G3*G3)-1)
// - - - - - Band-Pass Filter - - - - - //
if barindex <= period then
 F1 = 0
else
 F1 = 0.5*(1-S1)*X1 + L1*(1+S1)*F1[1] - S1*F1[2]
endif
// - - - - - Quadrature - - - - - //
if barindex <= period then
 Q1 = 0
else
 Q1 = (Period/360) * (F1-F1[1])
endif
// - - - - - 2nd Harmonic Band-Pass Filter - - - - - //
if barindex <= period then
 F2 = 0
else
 F2 = 0.5*(1-S2)*X1 + L2*(1+S2)*F2[1] - S2*F2[2]
endif
// - - - - - 2nd Harmonic Quadrature - - - - - //
if barindex <= period then
 Q2 = 0
else
 Q2 = (Period/360) * (F2-F2[1])
endif
// - - - - - 3rd Harmonic Band-Pass Filter - - - - - //
if barindex <= period then
 F3 = 0
else
 F3 = 0.5*(1-S3)*X1 + L3*(1+S3)*F3[1] - S3*F3[2]
endif
// - - - - - 3rd Harmonic Quadrature - - - - - //
if barindex <= period then
 Q3 = 0
else
 Q3 = (Period/360) * (F3-F3[1])
endif
// - - - - - Harmonic Sum - - - - - //
if barindex > period then
 once P1 = 0
 once P2 = 0
 once P3 = 0
 for i = 0 to (Period-1)
  P1 = P1 + F1[i]*F1[i] + Q1[i]*Q1[i]
  P2 = P2 + F2[i]*F2[i] + Q2[i]*Q2[i]
  P3 = P3 + F3[i]*F3[i] + Q3[i]*Q3[i]
 next
 // - - - - - Harmonic Sum (combined) - - - - - //
 if P1 = 0 then
  Wave = 0
 else
  Wave = F1 + sqrt(P2/P1)*F2 + sqrt(P3/P2)*F3
 endif
endif

return wave,0

Download
Filename: PRT-fourier.itf
Downloads: 222
gabri Master
Currently debugging life, so my bio is on hold. Check back after the next commit for an update.
Author’s Profile

Comments

Logo Logo
Loading...