#_i_FFT_separate3_EURUSD_4h

Download script
Author: Copyright � 2006, klot.
#_i_FFT_separate3_EURUSD_4h

This script is a specialized technical analysis tool designed to decompose financial price movements into their underlying mathematical frequencies. Rather than looking at price action simply as a series of ups and downs, this tool treats the market data like a sound wave or a complex signal, attempting to isolate specific "notes" or cycles that drive the trend.

How the Logic Works

1. Data Collection and Preparation The script begins by gathering a specific set of recent closing prices from the market. Before analyzing these prices, it performs a normalization process. This ensures that the magnitude of the price data is balanced relative to its total energy, preventing extreme price outliers from disproportionately skewing the mathematical results.

2. Frequency Transformation (The "Spectrum" Analysis) The core of the script utilizes a method known as a Fast Fourier Transform (FFT). In simple terms, imagine taking a complex musical chord and breaking it down into its individual instruments. The FFT does this with market prices: it converts the chronological price data (time) into a frequency spectrum. This allows the tool to identify which cycles (fast vibrations versus slow trends) are most dominant in the current market environment.

3. Targeted Filtering Not every frequency is useful for trading; some may be "noise." The script includes a sophisticated filtering system where users can define specific "zones" of interest. By setting minimum and maximum boundaries, the logic effectively mutes the frequencies that are not relevant to the desired strategy. For example, it can ignore very high-frequency "jitter" while focusing only on the medium-term cycles that represent the true market direction.

4. Signal Reconstruction After filtering out the unwanted noise, the script performs an inverse transformation. It takes the remaining significant frequencies and reconstructs them back into a visual format. The final output is a smoothed representation of the price action that has been "cleaned" of erratic fluctuations, highlighting the underlying momentum and structural trends of the asset.

Summary for the User

Essentially, this tool acts as a high-pass and low-pass filter combined into one sophisticated system. It strips away the market's "static" to show you the core signals. By isolating specific frequency bands, it helps traders identify the primary drivers behind price movements, making it easier to see the broader trend while ignoring minor, insignificant price fluctuations.

Price Data Components
Series array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
6 Views
0 Downloads
0 Favorites
#_i_FFT_separate3_EURUSD_4h
//+------------------------------------------------------------------+
//|                                            #_i_SpecktrAnalis.mq4 |
//|                                          Copyright © 2006, klot. |
//|                                                     klot@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, klot."
#property link      "klot@mail.ru"



#import "#_lib_FFT.ex4"
void realfastfouriertransform(double& a[], int tnn, bool inversefft);
#import

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_level1 0.0
//#property indicator_level1 0.0
//#property indicator_level1 0.0
//---- buffers
double Buffer1[];
double Buffer2[];
//---
/*
EURUSD 4h
0. frequency zone = 2 ( Fmin=2; Fmax=128)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//1. frequency zone = 8 ( Fmin=6; Fmax=10)
//2. frequency zone = 14 (Fmin=12;Fmax=16)
//3. frequency zone = 18 (Fmin=17;Fmax=19)
//4. frequency zone = 22 (Fmin=21;Fmax=23)
//5. frequency zone = 26 (Fmin=25;Fmax=27)
//6. frequency zone = 35 (Fmin=33;Fmax=37)
//7. frequency zone = 48 (Fmin=46;Fmax=50)
//8. frequency zone = 76 (Fmin=74;Fmax=78)
//9. frequency zone = 118 (Fmin=115;Fmax=121)
*/
extern int n=9; // Äëèíà ðÿäà

//extern int Fmin0=2;
//extern int Fmax0=128;
//1. frequency zone = 8 ( Fmin=6; Fmax=10)
extern int Fmin1=1;
extern int Fmax1=3;
//2. frequency zone = 14 (Fmin=12;Fmax=16)
extern int Fmin2=7;
extern int Fmax2=9;
//3. frequency zone = 18 (Fmin=17;Fmax=19)
extern int Fmin3=27;
extern int Fmax3=28;
//4. frequency zone = 22 (Fmin=21;Fmax=23)
extern int Fmin4=34;
extern int Fmax4=35;
//5. frequency zone = 26 (Fmin=25;Fmax=27)
extern int Fmin5=0;
extern int Fmax5=0;
//6. frequency zone = 35 (Fmin=33;Fmax=37)
extern int Fmin6=0;
extern int Fmax6=0;
//7. frequency zone = 48 (Fmin=46;Fmax=50)
extern int Fmin7=0;
extern int Fmax7=0;
//8. frequency zone = 76 (Fmin=74;Fmax=78)
extern int Fmin8=0;
extern int Fmax8=0;
//9. frequency zone = 118 (Fmin=115;Fmax=121)
extern int Fmin9=0;
extern int Fmax9=0;
//extern string sym="GBPUSD";
//extern string sym="EURUSD";

double aa[];
double bb[];
int N;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
SetIndexStyle(0,DRAW_LINE,0,5);
SetIndexBuffer(0,Buffer1);
SetIndexStyle(1,DRAW_LINE,0,5);
SetIndexBuffer(1,Buffer2);
//---
   N=MathPow(2,n);
   ArrayResize(aa,N);
   //ArrayResize(bb,N);
/*
if( Fmax1>=N ) Fmax1=N;
if( Fmin1<=2 ) Fmin1=2;
if( Fmax2>=N ) Fmax2=N;
if( Fmin2<=2 ) Fmin2=2;
if( Fmax3>=N ) Fmax3=N;
if( Fmin3<=2 ) Fmin3=2;
if( Fmax4>=N ) Fmax4=N;
if( Fmin4<=2 ) Fmin4=2;
if( Fmax5>=N ) Fmax5=N;
if( Fmin5<=2 ) Fmin5=2;
if( Fmax6>=N ) Fmax6=N;
if( Fmin6<=2 ) Fmin6=2;
if( Fmax7>=N ) Fmax7=N;
if( Fmin7<=2 ) Fmin7=2;
if( Fmax8>=N ) Fmax8=N;
if( Fmin8<=2 ) Fmin8=2;
if( Fmax9>=N ) Fmax9=N;
if( Fmin9<=2 ) Fmin9=2;
*/
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   if( Bars<N) return(0);
   
   //---
   for(int i=N-1; i>=0; i--) 
   { 
     aa[i]=iClose(Symbol(),0,i); 
     //bb[i]=iClose(Symbol(),0,i);
   }
   //---
   InSigNormalize(aa);
   InSigNormalize(bb);
   realfastfouriertransform(aa, N, false);
   //realfastfouriertransform(bb, N, false);
   //---
   N=ArraySize(aa);
   //Comment("n= ",N);
   //---
   for( i=0; i<=N-1; i++) 
   { 
      if( 
          (i<Fmin1 || i>Fmax1) &&
          (i<Fmin2 || i>Fmax2) &&
          (i<Fmin3 || i>Fmax3) &&
          (i<Fmin4 || i>Fmax4) &&
          (i<Fmin5 || i>Fmax5) &&
          (i<Fmin6 || i>Fmax6) &&
          (i<Fmin7 || i>Fmax7) &&
          (i<Fmin8 || i>Fmax8) &&
          (i<Fmin9 || i>Fmax9)
      
        ) { aa[i]=0.0; }
      //if( i<Fmin0 || i>Fmax0) { bb[i]=0.0; }  
   }
   //---
   realfastfouriertransform(aa, N, true);
   //realfastfouriertransform(bb, N, true);
   //---
   SetIndexDrawBegin(0,Bars-N);
   SetIndexDrawBegin(1,Bars-N);
   //---
   for( i=0; i<=N-1; i++)
   {
      Buffer1[i]=aa[i];
      //Buffer2[i]=bb[i];
   }
   //----
   return(0);
  }
//-------------------------------------------------------------------+

//--------------------------------------------------------------------+
void InSigNormalize(double& aa[])
{
   double sum_sqrt;
   int element_count=ArraySize(aa);
   sum_sqrt=0;
   for( int i=0; i<=element_count-1; i++)
   {
      sum_sqrt+=MathPow(aa[i],2);
   }
   sum_sqrt=MathSqrt(sum_sqrt);
   
   if (sum_sqrt!=0)
   {
      for( i=0; i<=element_count-1; i++)
      {
         aa[i]=aa[i]/sum_sqrt;
      }
   }
   return;
}

Comments