Problems with FileIsEnding()

 

I am reading data from a csv file but not all of the data is being read. The code I am using is below:

#property strict
#include <stderror.mqh>
#include <stdlib.mqh>

datetime   open_time;
string     symb;
string     type;
double     lots;
double     price;

void ReadTradeData()
{
 int i = 0;
 
 int file_handle=FileOpen(file,FILE_READ|FILE_CSV,',');
 
 if(file_handle!=INVALID_HANDLE)
 {
  while(!FileIsEnding(file_handle))
  {
   open_time = FileReadDatetime(file_handle);
   symb = FileReadString(file_handle);
   type = FileReadString(file_handle);
   lots = FileReadNumber(file_handle);
   price = FileReadNumber(file_handle);
  
   
   //only choose the data that matches the chart symbol
   if(symb == ChartSymbol())
   {
    Print("Raw data ---  " + string(symb) + "   count = " + string(i) + "   Type = " + string(type));
    i++;
   }
  } 
   Print(File size = ",FileSize(file_handle),"   File pointer = ",FileTell(file_handle));
   FileClose(file_handle);
 }
  else
   {
    {Alert("Failed to open file, Error = ",ErrorDescription(GetLastError()));return;}
   }

As an example I read the data file from a chart of "GBPJPY" - this returned 21 entries in the Print statement. If I look at the number of entries in the raw csv file there are 95.

I have checked over every entry individually in the csv file and the code seems to skip entries before picking up again down the list of "GBPJPY".

Has anybody else had similar experience?

 

A code can't "skip entries", it does what is coded using the input you provided (the file).

Can you post the csv file ?

 
Alain Verleyen:

A code can't "skip entries", it does what is coded using the input you provided (the file).

Can you post the csv file ?

Here is the file.

Files:
test.csv  107 kb
 
2020.05.18 20:29,XAUUSD,Sell,,"1,728.07"

2020.05.18 20:29,XAUUSD,Sell,,"1,728.10"

You said it is a comma separated file and are reading five (5) items per line. Those two lines, for example, have six (6) items and the last two are not numbers. «"1» is not a number, as is «728.07"»

 
William Roeder:
2020.05.18 20:29,XAUUSD,Sell,,"1,728.07"

2020.05.18 20:29,XAUUSD,Sell,,"1,728.10"

You said it is a comma separated file and are reading five (5) items per line. Those two lines, for example, have six (6) items and the last two are not numbers. «"1» is not a number, as is «728.07"»

1. My example I quoted was for "GBPJPY" not "XAUUSD".

2. The last number is One thousand seven hundred and twenty eight (point) zero seven. It has a comma separator for the thousand. So there are 5 items.

 
sd59: 2. The last number is One thousand seven hundred and twenty eight (point) zero seven. It has a comma separator for the thousand. So there are 5 items.

That is what a Human would read it as. The machine reads quote1 which is not a number! Your reading is bogus from the first quote read.

 
William Roeder:

That is what a Human would read it as. The machine reads quote1 which is not a number! Your reading is bogus from the first quote read.

mmm..so how does it read it and print it out. What is quote1? What do you mean my reading is bogus? Please back up comments like this with an explanation?

It reads the file and prints it fine so what am I to expect! It should therefore handle it as well.