#_i_FFT_separate_Close2_4H
Download scriptThis technical tool is designed to perform a sophisticated mathematical analysis of price movements by breaking down complex market data into its fundamental components. Instead of simply looking at the price as a single moving line, this script uses a technique called "Fast Fourier Transform" (FFT) to analyze the underlying frequencies and cycles within the market.
How the Logic Works
1. Data Collection and Comparison The tool starts by collecting a specific set of historical closing prices from the market chart. It captures two distinct sets of data points simultaneously. By comparing these two sets, the script can identify how price behavior is shifting or evolving over a specific window of time.
2. Frequency Decomposition Once the data is collected, the script applies a mathematical process that converts the "time-based" price movements into "frequency-based" information. Think of this like a music equalizer: while you hear a song as a single melody (the price chart), an equalizer breaks that melody down into various bass, mid-range, and treble tones. This allows the tool to see the hidden rhythms and repeating patterns in the market that aren't visible to the naked eye.
3. Filtering the Noise The market is often filled with "noise"—random price fluctuations that don't carry significant meaning. To handle this, the script uses a filtering system. You can define specific boundaries (minimum and maximum frequencies) to ignore the irrelevant noise and focus only on the specific cycles that matter most for your trading strategy.
4. Reconstruction of Cleaned Data After the "noise" has been filtered out, the tool performs an inverse process. It reconstructs a new version of the price data based only on the important frequencies it identified. This results in two visual lines plotted in a separate window on your chart.
Key Takeaways for the User
- Visual Clarity: The output provides a smoothed representation of market trends, helping to strip away erratic price jumps.
- Customizable Analysis: Through the settings, you can adjust the number of data points analyzed and the range of frequencies captured, allowing you to tune the tool to different types of market conditions (e.g., identifying long-term cycles vs. short-term momentum).
- Comparative Insight: By providing two distinct buffers, the script allows for a side-by-side comparison of processed data, helping traders spot divergences or convergences in price behavior more effectively.
//+------------------------------------------------------------------+
//| #_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=60;//80;//2; // Ãðíèöà Ôèëüòðà ïî Í×.
extern int Fmax=90;//128; // Ãðàíèöà Ôèëüòðà ïî Â×.
//extern string sym="GBPUSD";
extern int shift=1;//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