This indicator is designed to analyze market price action by breaking down complex price movements into their underlying frequencies. Rather than simply looking at where the price is moving, it uses a mathematical process similar to how sound engineers analyze audio waves or how radio stations isolate specific signals.
How the Logic Works
1. Data Collection and Comparison The script captures two different sets of price data from the market history. It looks at the current price movement and compares it against a "shifted" version of that same data (a set of prices from a predetermined period in the past). This allows the tool to identify how current market behavior differs from previous patterns.
2. Frequency Analysis The core of the script is a process called a "Fast Fourier Transform." In simple terms, this takes the messy, zig-zagging lines of a price chart and deconstructs them into different frequencies (cycles).
- Think of a musical chord: it's made of several different notes played at once. This tool identifies those individual "notes" within the price action.
3. Filtering the Noise Not every frequency is useful for trading; some are just market "noise." The script allows you to set specific boundaries (minimum and maximum limits). It effectively acts as a filter, removing the very high-frequency jitter (short-term noise) and the very low-frequency trends that might be too slow to be relevant. It keeps only the specific "middle" frequencies that represent the most meaningful cycles in the current market.
4. Reconstructing the Signal After filtering out the unwanted noise, the script performs an inverse calculation to rebuild the price data. This results in a "cleaned" version of the market movement.
5. Visualizing the Difference Finally, the tool calculates the difference between the current cleaned signal and the shifted past signal. It displays this difference on your chart using three different visual elements:
- Histogram Bars: These show the magnitude and direction of the difference between the two signals.
- Line Graph: This provides a continuous view of the divergence, helping you see how much the current market cycle is pulling away from or aligning with its historical counterpart.
Summary for the User
Essentially, this tool helps you see the "hidden" cycles in the market. By stripping away market noise and comparing the current rhythmic behavior of the price to a past version of itself, it highlights shifts in momentum that are not easily visible on a standard price chart.
//+------------------------------------------------------------------+
//| #_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;//80;//2; // Ãðíèöà Ôèëüòðà ïî Í×.
extern int Fmax=30;//128; // Ãðàíèöà Ôèëüòðà ïî Â×.
//extern string sym="GBPUSD";
extern int shift=30;//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