FileReadDatetime and FileReadDouble do not work

 

I need to read dates and values from a CSV file but when I print the values in console it is as if they were not assigned or read.
This is the file to read:

1971/01/01;-18.8551
1971/01/02;-18.8966
1971/01/03;-18.9375
1971/01/04;-18.9780
1971/01/05;-19.179
1971/01/06;-19.0573
1971/01/07;-19.0961
1971/01/08;-19.1345
1971/01/09;-19.1723
1971/01/10;-19.2096
1971/01/11;-19.2464
1971/01/12;-19.2826
1971/01/13;-19.3183
1971/01/14;-19.3535
1971/01/15;-19.3881
1971/01/16;-19.4222
1971/01/17;-19.4558
1971/01/18;-19.4888
1971/01/19;-19.5213
1971/01/20;-19.5532

This is the code:

//+------------------------------------------------------------------+
//|                                          jupiter-declination.mq5 |
//|                                                     canerandagio |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "canerandagio"
#property link      ""
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot declination
#property indicator_label1  "declination"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double declinationBuffer[];
string filename = "jupiter-declination2";
int fileHandle;
class JupiterDeclination{ 
   
   public:
   
      datetime day;
      double value;
};
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(){
//--- indicator buffers mapping
   SetIndexBuffer(0, declinationBuffer, INDICATOR_DATA);
   
   fileHandle = FileOpen(filename,FILE_READ|FILE_CSV, ';');
   if(fileHandle<0){
      Print("Failed to open the file by the absolute path ");
      Print("Error code ",GetLastError());
   }else{
      getValues();
      FileClose(fileHandle);
   }
   return(INIT_SUCCEEDED);
}

void getValues(){

   JupiterDeclination jupiterDeclination[];
   int size = 18698;
   ArrayResize(jupiterDeclination, size);
   
   for(int i=0; i<size; i++){
   
      jupiterDeclination[i].day = FileReadDatetime(fileHandle);
      jupiterDeclination[i].value = FileReadDouble(fileHandle);

   }
   
   for(int i=0; i<size; i++){
      printf(jupiterDeclination[i].day + " " + jupiterDeclination[i].value);
   }
   
}

I get in the console:

2022.02.17 09:50:31.997 jupiter-declination (EURUSD,D1) 1970.01.01 00:00:00 0.0
 
CaneRandagio:

I need to read dates and values from a CSV file but when I print the values in console it is as if they were not assigned or read.
This is the file to read:

This is the code:

I get in the console:

Did you only dare to read the documentation ?

FileReadDatetime

Reads from the file of CSV type a string of one of the formats: "YYYY.MM.DD HH:MI:SS", "YYYY.MM.DD" or "HH:MI:SS" - and converts it into a value of datetime type.

You are the one who "doesn't work".
 
Alain Verleyen #:

Did you only dare to read the documentation ?

You are the one who "doesn't work".
I need a break, sorry.
 

LoL I have to use the points!
yes, I read the documentation but in a hurry, and the cat in haste made her children blind.

I was really convinced that slashes were needed but thanks to your emphasis I could see the opposite.

thank you and don't die laughing

 

ok, no more chatter and let's be serious.
I changed the file from which to read the data like this:

1971.01.01;-18.8551
1971.01.02;-18.8966
1971.01.03;-18.9375
1971.01.04;-18.9780
1971.01.05;-19.179
1971.01.06;-19.0573
1971.01.07;-19.0961
1971.01.08;-19.1345
1971.01.09;-19.1723
1971.01.10;-19.2096
1971.01.11;-19.2464
1971.01.12;-19.2826
1971.01.13;-19.3183
1971.01.14;-19.3535
1971.01.15;-19.3881
1971.01.16;-19.42022
1971.01.17;-19.4558
1971.01.18;-19.4888
1971.01.19;-19.52013
1971.01.20;-19.5532

the problem remains the same, on the console it print 1970.01.01 00:00:00 0.0

I also tried to insert this code in the for loop:

FileSeek(fileHandle, i, SEEK_SET);
in this case it prints me today's date


now what is the solution?

 
CaneRandagio #:

ok, no more chatter and let's be serious.
I changed the file from which to read the data like this:

the problem remains the same, on the console it print 1970.01.01 00:00:00 0.0

I also tried to insert this code in the for loop:

in this case it prints me today's date


now what is the solution?

Seriously ?

Seems I have to say you to read the documentation again. This time about FileReadDouble().

Please consider you have to read the documentation for all what you are using in MQL, we will win some time

 
Alain Verleyen #:

Seriously ?

Seems I have to say you to read the documentation again. This time about FileReadDouble().

Please consider you have to read the documentation for all what you are using in MQL, we will win some time

the documentation on FileReadDouble () speaks only of binary files, not of csv, for the rest it is very short, there is not much to read.
 
CaneRandagio #: the documentation on FileReadDouble () speaks only of binary files, not of csv, for the rest it is very short, there is not much to read.

Exactly! You can't use FileReadDouble() with CSV Text files. You can only use it with Binary files where the "doubles" are stored in Binary format, not in a textual format.

Instead use FileReadNumber().

Documentation on MQL5: File Functions / FileReadNumber
Documentation on MQL5: File Functions / FileReadNumber
  • www.mql5.com
FileReadNumber - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
CaneRandagio:

I need to read dates and values from a CSV file but when I print the values in console it is as if they were not assigned or read.
This is the file to read:

This is the code:

I get in the console:

Your file handle is not opened correctly, double quotes for the separator.
 
thanks to everybody but I solved using FileReadString()
Reason: