#_i_FFT_separate_Close2_4H_diff
Download scriptThis tool is designed to analyze price movements by breaking down market data into different frequencies, similar to how sound waves are analyzed in music or radio. Instead of just looking at the raw price on a chart, this script identifies the underlying "cycles" and "noises" within the market to help visualize specific patterns.
Core Logic and Methodology
1. Data Collection and Processing The script looks at a specific number of historical closing prices from the current chart. It organizes this data into two distinct sets based on a small time offset (a "shift"). By comparing these two sets, the tool can detect slight discrepancies or shifts in momentum between very recent price action and the immediate past.
2. Frequency Analysis (The Fourier Transform) The heart of this script is a mathematical process known as a Fast Fourier Transform. In simple terms, this takes a complex, jagged price line and decomposes it into individual waves. It identifies which "speeds" or "frequencies" are driving the market at any given moment—separating long-term trends from short-term fluctuations.
3. Filtering the Noise Not all market movement is useful for trading; some of it is just random "noise." The script allows for specific boundaries (minimum and maximum frequencies). It effectively "mutes" the data outside of these bounds, focusing only on the specific range of price cycles that the user deems significant. This helps clean the visual data so that only the relevant market rhythms are highlighted.
4. Comparison and Visualization Once the data has been cleaned and analyzed, the script compares the two sets of processed price waves. It calculates the difference between them to produce three different visual outputs:
- Two Histograms: These represent the direction and magnitude of the divergence between the price cycles. They show whether the "rhythm" of the market is moving in one direction or the other.
- A Trend Line: This provides a continuous view of the difference between these two datasets, helping to visualize the overall "tension" or separation between different price frequencies.
Summary for the User
Essentially, this indicator acts as a "spectrogram" for trading. Rather than showing you where the price is, it shows you the underlying frequency of the price's movement. By filtering out irrelevant noise and highlighting the differences between recent cycles, it aims to provide a clearer picture of the market's internal momentum and structural rhythm.
//+------------------------------------------------------------------+
//| #_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=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_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]=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++)
{
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