#_i_FFT_separate_Volume2_W_diff
Download scriptThis tool is designed to analyze market data by decomposing price action into different cycles and frequencies. Rather than looking at standard price movements alone, it uses a mathematical approach similar to how sound engineers analyze audio waves to identify specific hidden notes or background noise.
How the Logic Works
1. Data Collection The script captures "Volume" data—the amount of trading activity occurring at specific moments. It collects two distinct sets of these volume figures:
- One set represents the most recent market activity.
- The second set is captured from a historical point further back in time (determined by a specific "shift" setting).
2. Frequency Analysis (The Fourier Transform) The core logic employs a mathematical process called a Fast Fourier Transform. This takes the raw, messy sequence of trading volume and breaks it down into its component cycles. It identifies which frequencies (fast vibrations vs. slow movements) are driving the current market behavior.
3. Filtering the Noise Not all data is useful for analysis. The script uses specific "Minimum" and "Maximum" boundaries to filter out irrelevant information. By doing this, it ignores the "noise" of very small, insignificant fluctuations and focuses only on the specific range of cycles that are most relevant to the user's trading strategy.
4. Comparative Analysis After analyzing both the current volume and the historical volume, the script compares the two. It looks for the differences between how the market is currently behaving versus how it behaved in the past.
5. Visual Representation The final output is displayed in a separate window as three distinct visual elements:
- Red Histogram: Shows instances where the historical volume pattern was stronger than the current one.
- Blue Histogram: Shows instances where the current market volume pattern is stronger than the historical one.
- Yellow Line: Provides a continuous view of the mathematical difference between these two time periods.
Summary for the User
In simple terms, this tool acts as a "spectral analyzer" for trading volume. It helps you see if the current momentum of the market is gaining strength, losing strength, or shifting in character compared to a previous period, by filtering out the market's background noise and highlighting the most significant underlying cycles.
//+------------------------------------------------------------------+
//| #_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 3
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Yellow
#property indicator_level1 0.0
//#property indicator_level1 0.0
//#property indicator_level1 0.0
//---- buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
//---
extern int n=7; // Äëèíà ðÿäà
extern int Fmin=2;//2; // Ãðíèöà Ôèëüòðà ïî Í×.
extern int Fmax=30;//128; // Ãðàíèöà Ôèëüòðà ïî Â×.
extern int shift=30;//127;
//extern string sym="GBPUSD";
//extern string sym="EURUSD";
double aa[];
double bb[];
int N;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,0,2);
SetIndexBuffer(0,Buffer1);
SetIndexStyle(1,DRAW_HISTOGRAM,0,2);
SetIndexBuffer(1,Buffer2);
SetIndexStyle(2,DRAW_LINE,0,2);
SetIndexBuffer(2,Buffer3);
//---
//---
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]=iVolume(Symbol(),0,i);
bb[i]=iVolume(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(double& a[], int tnn, bool inversefft);
realfastfouriertransform(aa, N, true);
realfastfouriertransform(bb, N, true);
//tworealffts(double a1[], double a2[], double& a[], double& b[], int tn);
//---
SetIndexDrawBegin(0,Bars-N);
//SetIndexDrawBegin(1,Bars-N-shift);
SetIndexDrawBegin(1,Bars-N);
//---
for( i=0; i<=N-1; i++)
{
double diff1=bb[i]-aa[i];
if (diff1>0)
Buffer2[i]=diff1;
//Buffer2[i+shift]=bb[i];
else if (diff1<0)
Buffer1[i]=diff1;
Buffer3[i]=diff1;
}
//----
return(0);
}
//-------------------------------------------------------------------+
Comments