Predicting the future with Fourier transforms - page 5

 

Here are the frequencies that stood out in the interval of just over a week (shown in days)

4.58.

2.58.

1.63 (the strongest, shown in the graph in the middle)

1.04

0.52.

0.26.


Any suggestions what causes the period of 1.63 days (third harmonic of the week)?

 

Here is the first forecast


There's still a lot of work to be done

ANG3110, what is your forecast for tomorrow?

 
m_keeper:

Here is the first forecast


There's still a lot of work to be done

ANG3110, what's your forecast for tomorrow?

I haven't actually made a forecast specifically. I can just give you a drawing by eye.

And what do you see on the graph, describe it in more detail.


 
Maybe someone has a non-fast Fourier transform to mq4? A C or Pascal implementation is also possible.
 
vaa20003:
Maybe someone has a non-fast Fourier transform to mq4? C or Pascal implementation is also possible.

On the second page see

 
m_keeper:
vaa20003:
Maybe someone has a non-fast Fourier transform to mq4? A C or Pascal implementation is also possible.

See page two.

Thanks, missed it...

 

Here's what we've got so far

We search for the main market frequencies, determine their amplitude and phase, define trnd, and add and normalize the whole thing.

I don't like the way local maxima are searched for on the periodogram, the search is based on the harmonic distribution

and there's no sign of it, of course you can isolate them by playing with the parameters, but it's still unstable, and often very microlocal

of the maxima.

The second drawback is that everything is displayed in one window, it is necessary to spread all this pleasure over several charts in the main window,

and 2-3 additional windows.


Who knows how to make all calculations be performed in one place and all others - indicators, experts - have access to the results?

The selection of appropriate frequencies of market fluctuations should still be done manually. It would be very convenient to select maxima with a mouse or a line like ANG3110


ANG3110, how have you implemented the work with the line? Through scripts?



A couple of words on what to do with what I have now posted.

Lenght=560;//set the window size in bars
Period_count=2;//How many periods we will consider, accordingly, the lenght should be period_count times more than what you see on the market
Garmonic=9;// This parameter and the next one are determined by the method of terribly complicated fitting (I will write about it in details)
GarmonicControl=1.7;

iMAperiod=4;//if the fit didn't help, try to smooth the graph a bit

Futur=100;//for how many bars to make the forecast
InPast=200;// operation on previous bars, for estimation of forecasting, using already existing data

Actually what do you see on the indicator (the forecast for today by the way)

All graphs should lie in a range from 0 to Lenght (well +/- 5%)

If the range is different it's just a glitch. Press Refresh and it will work fine (I don't understand what's wrong here)

Thin pink chart - prepared time series, should be similar to the course.

Thick orange - periodogram, period value is equal to the corresponding value of blue line

position and amount of red bars feeding into the blue line are determined by Garmonic and GarmonicControl

The green bars propping up the periodogram - the detected periods depend strongly on the red lines. Having discerned the most significant periods, you should start adjusting the Garmonic* until you get the result

The thin green curve is the phasogram, it looks like if the frequency is stable then the phasogram is smooth, but if it fluctuates then the oscillation of that frequency has been recently disturbed and cannot be trusted. (0 corresponds to -pi/2 ; Lenght --- 3*pi/2)


And actually the most important thing is the thick pink line - it is a forecast. The forecast doesn't have to coincide with the initial graph by elevation and repeat the previous one. The most important thing to see is the pivot points and their possible intensity (the predicted pivot time will surely be different)


 
m_keeper:

The selection of appropriate market fluctuation frequencies has to be done manually after all. It would be very convenient to select maxima with a mouse, or with a line, as ANG3110 has


ANG3110, how have you implemented the work with the line? Through scripts?

For your case, I think the most suitable is the following option:

You make a script to control the indicator:


//==============================================================
#import "user32.dll"
int      PostMessageA(int hWnd,int Msg,int wParam,int lParam);
#import
#define WM_COMMAND   0x0111
//==============================================================
int i0,ip,T;
int t0,tp,t0n,tpn;
string Symb;
int Per;
//**************************************************************
int init() 
{ 
   Symb=Symbol();
   Per=Period();
   
   t0=WindowTimeOnDropped();
   T=64; 

   i0=iBarShift(Symbol(),Period(),t0);
   ip=i0+T;
   tp=Time[ip];
   t0n=t0;
   tpn=tp;
   
   ObjectCreate("RCh",4,0,tp,0,t0,0);
   ObjectSet("RCh",OBJPROP_COLOR,DodgerBlue); 
}
//**************************************************************
int start() 
{
   int hwnd=WindowHandle(Symb,Per);        
   if (hwnd!=0) 
   {
      PostMessageA(hwnd,WM_COMMAND,33324,0); 
      GlobalVariableSet("gi0",i0);
      GlobalVariableSet("gip",ip);
   } else return(0);
   //---- 
   while(IsStopped()==false) 
   {
      t0=ObjectGet("RCh",OBJPROP_TIME2); 
      if (t0>Time[0]) t0=Time[0]; 
      tp=ObjectGet("RCh",OBJPROP_TIME1); 
      i0=iBarShift(NULL,Per,t0);
      ip=iBarShift(NULL,Per,tp);
      
      T=ip-i0;
      if (T<2) {T=2; ip=i0+T; tp=Time[ip];}
      
      if (t0n!=t0 || tpn!=tp) 
      {
         GlobalVariableSet("gi0",i0);
         GlobalVariableSet("gip",ip);
         PostMessageA(hwnd,WM_COMMAND,33324,0);
         t0n=t0;
         tpn=tp;
      } 
      
      Sleep(200);
   }
   //=============================================
   return(0);
}
//**************************************************************
void deinit() 
{
   ObjectDelete("RCh"); 
   GlobalVariableDel("gi0");
   GlobalVariableDel("gip");
}
//**************************************************************

You insert it after int start() in the indicator:

   if (GlobalVariableCheck("gi0")) 
   {
      i0=GlobalVariableGet("gi0"); 
      ip=GlobalVariableGet("gip");
      T=ip-i0;
      SetIndexShift(2,T/2);
      SetIndexShift(3,T/2);
   }
   else 
   {
      i0=0; T=T0; SetIndexShift(2,T/2); SetIndexShift(3,T/2);
   }


First you put the indicator on the chart, then throw out the script and use the LR channel to move the chart.

I hope you can do it yourself, or I can give you a hint.

 

Thank you, the lines are sorted out.


May I ask one more question?

I now have information in 3 charts, one in the main window and two in my window.

The parameters are set only in one of them and stored in global variables

The parameters are set only in one of them and stored in global variables with the keys "PF_"+Symbol()+"_"+DoubleToStr(Period(),0)+"_key".

I also store information about maxima in global variables

The problem is that I have to perform the calculations three times for each chart.

In the beginning I tried iCustom, but in my opinion it doesn't take

the data from the previously added charts, but calculates them again, at least init

and sees that it's already started (by global variables)

and doesn't do calculations, and iCustom returns an Empty.

Is there any way to make the arrays global?

It seems to me that if you cram thousands of values into GlobalVariable, it'll be a lot slower to work.

it will be much slower to work, because the search on the string goes

 
m_keeper:

Is there any way to make arrays global?

I'm not quite sure what you need, but when you need to save a lot of data and then read it again, it's easier to use writing to an intermediate file, for example:

int handle=FileOpen("Test.dat",FILE_BIN|FILE_WRITE);

FileWriteArray(handle,arr,0,Narr);

And then read back from another program:

int handle=FileOpen("Test.dat",FILE_BIN|FILE_READ);

FileReadArray(handle,arr,0,Narr);

Please refer to the MT4 Help for more details.