Help with Fourier - page 7

 
eugenk1 писал (а):
ANG3110, I'm sorry, I've read all your posts and the impression is this. Either you are seriously hiding something (I'm not judging, money is an intimate thing), or you have an idea, need help, but don't want to open up to the end (this is not good), or you are talking about times of the order of months. I myself started to master all this precisely with the idea of applying the Fourier transform. And pretty quickly became disillusioned.

Neither one, or the other, or the third. I just had the urge to do a bit of writing yesterday and today. I didn't actually intend to say much on the subject. I was rather asked to show and tell and I went along with it. I know what I know and what I don't know at the moment. Maybe someone can help me, but firstly, he must at least understand what I am writing about, and secondly, have good knowledge and experience in the field, and most importantly, relate well to me, and to the very essence of the subject. I think there is no need and most likely there is no need to talk about it any more. Something to hide? I just don't have a lot of time and I don't want to waste it on clever rubbish and empty scholarly chatter, there are plenty of such amateurs on forums. I've exhibited some of my earlier work on Spider and it's been well reviewed. At the very beginning of the thread, see, someone cited one of my early raw codes. So - how, who, what, perceive and what he is fascinated or disappointed in, I'm not really interested, for me, what I do - mostly works.
 
eugenk1 писал (а):
YraZ, excuse me, can you explain what is actually shown on the picture? As for what works in the flat, to be honest, I always thought that it works perfectly on a perfectly phoned (say heads - buy, tails - sell) opening, with a stop greater than the spread of the flat. Yes, it may not be optimal in terms of drawdown, but it works...

I agree - everything works,
unless you go low and go to sell again and buy at the top.
But if we're in the middle, we may go either buy or sell.

in the picture, i chose the middle main levels according to the following principle

1+2 = 3
3 + 2 = 5
5 + 3 = 8
8 + 5 = 13
13 + 8 = 21
21 + 13 = 34
34 + 21 = 55
etc
.... FIBO principle

something like this
there are dotted lines between the patterns - it seems to be enough of a baseline
if you look at the grid in Flat on all TFs, you can clearly see the waves - reversals visually - nothing more
+ some well-known traders "secrets" of the averages such as the 8th EMA when the candle closes below the -8th , candlestick analysis + EMA, the 3rd EMA
for example if the candlestick is completely closed outside the 3rd EMA it's usually a great entry
and in the flat and not only that, it is usually a spike entry


just the idea of a sine wave in the future is very close
 
How can I extrapolate a Fourier series using the functions found in the #_lib_FFT.mq4 library?
It would be interesting to see what the line shows in the future.
Maybe someone can upgrade the functions from this library to be able to display the line into the future.
Files:
y_lib_fft.mq4  28 kb
 
Frankfurt:

It would be interesting to observe what the line shows for the future.

It will show exactly the same thing that is already drawn.
 
Integer писал (а):
Frankfurt:

It would be interesting to observe what the line shows for the future.

It will show exactly the same as what is already drawn.

In the case of a full fft it will repeat what is already drawn,
and in the case of cosine transformation, mirrored backwards from the end.


 

Interestingly, cosine-based FFT has a derivative equal to zero for the last bar, i.e. it will show that a price bend (max or min) occurs on the last bar even if there is no such bend in fact. FFT based on sine will always show the trend at its peak (derivative has maximum value on the last bar). A Fourier series based on cosine and sine is more acceptable for constructing a moving average.

Here is the code of the moving average based on the code written by Klot, who used cosine FFT.

//+------------------------------------------------------------------+
//|                                                       FFT_MA.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_width1 2
#property indicator_color1 Red
//Imorting library #_lib_FFT.ex4. It must be in the expert directory. 
#import "#_lib_FFT.ex4"
void realfastfouriertransform(double& a[], int tnn, bool inversefft);
#import
//Input parameters
extern int n      =8;   // Sets the number of data points as 2^n.
extern int hmax   =2;   // Max number of harmonics including dc.
//Global variables
int N;                  //N is number of data points.
//Indicator buffer
double FFTMA[];
int init()
{
   N=MathPow(2,n);
   if(hmax>N) hmax=N;
   IndicatorBuffers(1);
   SetIndexBuffer(0,FFTMA);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   IndicatorShortName("FFTMA");
   return(0);
}
int deinit(){return(0);}

int start()
{
   double data[];
   ArrayResize(data,N);
   for(int i=0;i<N;i++) data[i]=Close[i];
   realfastfouriertransform(data,N,false);
   if(hmax>0) for(i=hmax;i<N;i++) data[i]=0.0;
   realfastfouriertransform(data,N,true);
   ArrayInitialize(FFTMA,EMPTY_VALUE);
   for(i=0;i<N;i++)FFTMA[i]=data[i];
   return(0);
}
//+------------------------------------------------------------------+

 
With hmax =2; there will be a simple MA, for a given period, it is not quite clear why a full FFT is needed?
 
ANG3110 писал (а):
With hmax =2; there will be a simple MA, for a given period, it is not quite clear why we need a full FFT?

No, I also noticed, full FFT is much more stable (less redrawing).
In general, I think we should use the following filter
if(hmax>0) for(i=hmax;i<N;i++) data[i]=0.0;
to make up some smart filter. We need it to selectively leave the necessary harmonics, and zero out the unnecessary ones. Then it may have some sense and stability.

Also, NeuroshellDayTrader uses five or six different filters in FFTadon, sorry I don't have formulas, I could tinker with them.
And if you limit frequencies not only from above but also from below, you can select a certain band of oscillations. The indicator looks nice, it reminds of a stochastic.
 
ANG3110 писал (а):
With hmax =2; there will be a simple MA, for a given period, it is not quite clear why a full FFT is needed?

Frankly speaking, I don't advocate application of FFT (full or cosine) for construction of moving averages for the reason that FFT breaks prices series by frequencies 2*pi*k*l/N, i.e. frequencies are known in advance though prices series can have stronger harmonics at adjacent frequencies different from 2*pi*k*l/N. The FFT idea is based on fitting a trigonometric series to a real series using the method of least squares. This way any orthogonal functions (orthogonal polynomials, in the simplest case) can be fitted. The advantage of the FFT is that the amplitudes of the trigonometric functions are samples of the frequency response of the process with a constant step of 2*pi/N. By using FFT it is possible to reject high frequency harmonics and thus construct a moving average. But such filtering is much more complicated than digital filtering such as simple moving average or FIR filter. Take a look at my moving average indicators based on FIR filter:

'FIR MA'.
AFIRMA'.
 
klot писал (а):
ANG3110 wrote (a):
With hmax =2; there will be a simple MA, on a given period, it's not quite clear, why bother with a full FFT then?

Nah, I noticed it too, full FFT is much more stable (less redrawing).
In general, I think we should use the following filter
if(hmax>0) for(i=hmax;i<N;i++) data[i]=0.0;
to make up some smart filter. We need it to selectively leave the necessary harmonics, and zero out the unnecessary ones. Then it may have some sense and stability.

Also, NeuroshellDayTrader uses five or six different filters in FFTadon, sorry I don't have formulas, I could tinker with them.
And if you limit frequencies not only at the top but also at the bottom, you can select a certain band of oscillations. The indicator looks nice looking, it reminds of a stochastic.
The goodness with it let it redraw. The Fourier's value is that if it is appropriately tuned, it shows well the times where turning points are probable. It's not so bad that amplitude trajectory does not coincide, on the contrary it is good, the phase change velocity can be taken into account. Here is a drawing made 2 days ago using the minimum of RMS.
It shows that the main oscillations in time subsequently, more or less coincided.

Reason: