Problem of data storage

 

Hello,

I would like to know how is it possible in MQL5 to store/save the quote of currency for a given value of an indicator.

For example, for the last highest value of the MACD indicator, I would like that my EA return me the quote of the currency at the same time and save the both in a variable

So how can I save them and reload their values when it's necessary? 

 
Antoine:

Hello,

I would like to know how is it possible in MQL5 to store/save the quote of currency for a given value of an indicator.

For example, for the last highest value of the MACD indicator, I would like that my EA return me the quote of the currency at the same time and save the both in a variable

So how can I save them and reload their values when it's necessary? 

You can  use the FIleWrite() functions to record values to a data file. Then use FileRead() to reload the values as needed.

//--- Write data to a file --------
int handle=0;
string name=_Symbol+" FileData";
int data1=value1; 
double data2=value2;
double data3=value3;
               
handle=FileOpen(name,FILE_WRITE|FILE_BIN);
   if(handle>0)
      {
         FileWriteInteger(handle,data1,INT_VALUE);
         FileWriteDouble(handle,data2);
         FileWriteDouble(handle,data3);
         FileClose(handle);
      }
   else Print("File ",name," failed to open");
//-- Read data from file -------

int handle=0;
string name=_Symbol+" FileData";

handle=FileOpen(name,FILE_READ|FILE_BIN);
   if(handle1>0)
     {
       value1=FileReadInteger(handle1);
       value2=FileReadDouble(handle);
       value3=FileReadDouble(handle);
       FileClose(handle);
     }
   else Print("File ",name," failed to open");
Documentation on MQL5: File Functions / FileWrite
  • www.mql5.com
File Functions / FileWrite - Documentation on MQL5
 

In fact it's a little bit complicate (for me...).

I would like that when the MACD cross his signal, the program search his max/min value with his time from now to the last cross. It should return me the value of the currency at this time and store them (time, Max(MACD) and quote of currency) in a handle (we can call all these values Values1).

It should also, when there is a new cross, store the oldest in an other handle (Values2) and save them.

How can I do and in which part of my code?? 

 

I think I can do this with a value like MAXMACD which store the value of MACD when MACDVal[1] > MACDVal[2], and doing the same thing for the other values.

However with which parameter can I store the Time (CurTime for example)??

I tried to do this with an int (int DateMACD and after DateMACD = CurTime) but it doesn't work...

How can I do?? 

 

I did a code which compile without error but when I try it with the strategy tester there is no result...

Am i getting something wrong ?

Please help and advise.

Thank you.

Files:
DIV.ex5  13 kb