#_i_FFT_separate_Close2
Download scriptThe SpecktrAnalis tool is designed to analyze financial market data by breaking down price movements into their underlying frequencies. Instead of looking at price as a simple up-and-down line, this script treats the market like a sound wave or a radio signal, allowing it to identify hidden patterns that are often obscured by "market noise."
How it Works
The core logic relies on a mathematical process known as a Fast Fourier Transform (FFT). In simple terms, think of this as a prism: just as a prism separates white light into individual colors, this tool separates complex price movements into individual frequency components.
Here is the step-by-step breakdown of the logic:
- Data Collection: The script looks at a specific window of recent historical price data (the "Close" prices). It captures two distinct sets of data points to compare different market states or time offsets.
- Frequency Analysis: It processes these price points through the FFT algorithm. This converts the data from the "Time Domain" (where you see price changing over seconds/minutes) into the "Frequency Domain" (where you see how much each specific cycle contributes to the overall trend).
- Filtering: The script allows for a specific range of frequencies to be kept while others are removed. By setting minimum and maximum limits, it filters out the "static" or "jitter" of the market, leaving behind only the most significant cycles.
- Reconstruction: Once the unnecessary noise is filtered out, the script performs an "Inverse Transform." This reconstructs the price data into a smoothed, clarified visual representation.
What this means for the user
The final result provided by the script is a visual representation of the market's primary cycles. By stripping away the minor fluctuations and focusing on the dominant waves, it helps traders see the "true" rhythm of the asset. It essentially cleans up the chart so that the underlying structure of the price action becomes more visible to the naked eye.
//+------------------------------------------------------------------+
//| #_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 Blue
#property indicator_level1 0.0
//#property indicator_level1 0.0
//#property indicator_level1 0.0
//---- buffers
double Buffer1[];
double Buffer2[];
//---
extern int n=7; // Äëèíà ðÿäà
extern int Fmin=2;//80;//2; // Ãðíèöà Ôèëüòðà ïî Í×.
extern int Fmax=128;//128; // Ãðàíèöà Ôèëüòðà ïî Â×.
//extern string sym="GBPUSD";
extern int shift=127;//extern string sym="EURUSD";
double aa[];
double bb[];
int N;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Buffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Buffer2);
//---
N=MathPow(2,n);
ArrayResize(aa,N);
ArrayResize(bb,N);
if( Fmax>=N ) Fmax=N;
if( Fmin<=2 ) Fmin=2;
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if( Bars<N+shift) return(0);
//---
for(int i=N-1; i>=0; i--)
{
aa[i]=iClose(Symbol(),0,i);
bb[i]=iClose(Symbol(),0,i+shift);
}
//---
realfastfouriertransform(aa, N, false);
realfastfouriertransform(bb, N, false);
//---
N=ArraySize(aa);
//Comment("n= ",N);
//---
for( i=0; i<=N-1; i++)
{
if( i<Fmin || i>Fmax) { aa[i]=0.0;bb[i]=0.0; }
}
//---
realfastfouriertransform(aa, N, true);
realfastfouriertransform(bb, N, true);
//---
SetIndexDrawBegin(0,Bars-N);
//SetIndexDrawBegin(1,Bars-N-shift);
SetIndexDrawBegin(1,Bars-N);
//---
for( i=0; i<=N-1; i++)
{
Buffer1[i]=aa[i];
//Buffer2[i+shift]=bb[i];
Buffer2[i]=bb[i];
}
//----
return(0);
}
//-------------------------------------------------------------------+
Comments