#_i_FFT_separate_Volume2_W_D_diff
Download scriptThis script is a sophisticated technical analysis tool designed to decode the underlying "heartbeat" of market volume. Rather than simply looking at how much trading is happening at a specific moment, it uses advanced mathematical principles to identify hidden cycles and patterns within that data.
Core Logic Overview
The tool functions by breaking down complex market movement into its fundamental frequencies—much like how a prism splits white light into different colors or how a tuner isolates a specific radio station from background noise.
Here is the step-by-step logic of how the script processes information:
1. Data Collection and Synchronization The script monitors the volume of trades over a specific period. It captures two sets of data simultaneously:
- A primary set of current volume figures.
- A secondary set of historical volume figures, offset by a specific timeframe (a "shift").
2. Frequency Transformation (The "Spectral Analysis") This is the core engine of the script. It applies a mathematical process called a Fast Fourier Transform (FFT). This takes the raw, messy timeline of trading volume and converts it into a frequency map. Instead of seeing when a trade happened, it identifies the rhythm of the trades—detecting recurring cycles that are often invisible to the naked eye on a standard chart.
3. Targeted Filtering Not all frequencies are useful for trading; some are just "noise." The script allows you to set specific boundaries (minimum and maximum limits) to ignore irrelevant data. By filtering out these distractions, the tool isolates the most meaningful market cycles.
4. Comparative Analysis After the frequency data is processed and cleaned, the script compares the current market rhythm against the historical rhythm it captured earlier. It looks for discrepancies between the two:
- It calculates the difference between the "now" cycle and the "past" cycle.
- If there is a significant shift in these rhythms, the script highlights this variance.
5. Smoothing and Visualization To ensure the data is readable and not erratic, the final output is smoothed using a Moving Average. This provides a cleaner line on your chart that represents the momentum of the frequency shifts.
Visual Output
The indicator provides four distinct visual elements:
- Lines: Represent the primary calculated difference between current and historical cycles.
- Histograms: These act as "momentum bars." When they move in one direction, they indicate a positive divergence; when they move in the opposite direction, they show a negative divergence.
In essence, this script tells you if the market's underlying "pulse" is changing compared to its recent past, helping traders identify potential shifts in trend before they become obvious on standard price charts.
//+------------------------------------------------------------------+
//| #_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 4
#property indicator_color1 Yellow
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Lime
#property indicator_level1 0.0
//#property indicator_level1 0.0
//#property indicator_level1 0.0
//---- buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
//---
extern int n=7; // Äëèíà ðÿäà
extern int Fmin=2;//2; // Ãðíèöà Ôèëüòðà ïî Í×.
extern int Fmax=60;//128; // Ãðàíèöà Ôèëüòðà ïî Â×.
extern int shift=6;//127;
extern int MaPeriod=10;
//extern string sym="GBPUSD";
//extern string sym="EURUSD";
double aa[];
double bb[];
int N;
//+------------------------------------------------------------------+
//| ???????????? ???????? ???????? |
//+------------------------------------------------------------------+
void Normalize2(double& aa[])
{
int n=ArraySize(aa);
double sum_sqrt=0;
for(int i=0; i<=n-1; i++)
{
sum_sqrt+=MathPow(aa[i],2);
}
sum_sqrt=MathSqrt(sum_sqrt);
//---
if (sum_sqrt!=0)
{
for( i=0; i<=n-1; i++)
{
aa[i]=aa[i]/sum_sqrt;
}
}
//---
return;
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,0,1);
SetIndexBuffer(0,Buffer1);
SetIndexEmptyValue(0,0);
SetIndexStyle(1,DRAW_HISTOGRAM,0,1);
SetIndexBuffer(1,Buffer2);
SetIndexEmptyValue(1,0);
SetIndexStyle(2,DRAW_HISTOGRAM,0,1);
SetIndexBuffer(2,Buffer3);
SetIndexEmptyValue(2,0);
SetIndexStyle(3,DRAW_LINE,2,1);
SetIndexBuffer(3,Buffer4);
SetIndexEmptyValue(3,0);
//---
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);
//Normalize2(aa);
bb[i]=iVolume(Symbol(),0,i+shift);
//Normalize2(bb);
}
//---
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)
{
Buffer3[i]=0;//red
Buffer2[i]=-diff1;//blue
//Buffer2[i+shift]=bb[i];
}
else if (diff1>0)
{
Buffer3[i]=-diff1;//red
Buffer2[i]=0; //blue
}
Buffer1[i]=-diff1;
}
//----
for( i=0; i<=N-1; i++)
{
Buffer4[i]=iMAOnArray(Buffer1,0,MaPeriod,0,MODE_SMA,i);
}
return(0);
}
//-------------------------------------------------------------------+
Comments