FileRead from CSV help

 

Hello,

I have an indicator that I use in an EA, which does its calculations using many symbols, which means that while optimizing the EA, the indicator gets different results than on live.

So what I'm trying to do is export the live indicator buffer to a csv file, which I was able to do, and then have another indicator import them, instead of doing the calculations.

I exported them in the following format Time[i];Buffer[i] to the csv, but I wonder how I could import them correctly.

Here's my current code, but I want to know how to get the second value of the row:

   if(FileIsExist(InpDirectoryName+"//"+InpFileName)==true)
   {
      int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV); 
   if(file_handle!=INVALID_HANDLE)
     { 
      PrintFormat("%s file is available for writing",InpFileName); 
      PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH)); 
      //--- read data from the file 
      int i;
      for(i=Bars;i<=0;i--)
      {
         if(Time[i] == StringToTime(FileReadString(file_handle,0))
            break;
      }
      
      for(i;i<=0;i--)
         ChangeofChange[i]=StringToDouble(FileReadString(file_handle,0));


      FileClose(file_handle); 
      PrintFormat("Data is written, %s file is closed",InpFileName); 
     } 
   else 
      PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());

"ChangeofChange" is the buffer of course.


My problem is here:

for(i;i<=0;i--)
         ChangeofChange[i]=StringToDouble(FileReadString(file_handle,0));

I need to assign to it the second value of the csv rows


Thanks.

 
Naim El Hajj: I have an indicator that I use in an EA, which does its calculations using many symbols, which means that while optimizing the EA, the indicator gets different results than on live.
Fix your broken indicator. This is why I recommend:
Do not trade multiple currencies in one EA.
 

I don't use MQ's csv-file options!

I

  1. read the file totally (no error-check!!) and split it into lines:
    ushort SepLine = StringGetCharacter("\n",0),
           SepItem = StringGetCharacter(";",0);
    int hdl  = FileOpen(fName,FILE_READ|FILE_SHARE_READ|FILE_BIN|FILE_COMMON),
        sz = (int)FileSize(hdl),
        nL,i;
    string lines[],cells[],all = FileReadString(hdl,sz);
    nL = i = StringSplit(all,SepLine,lines);
  2. Now I can search on each line if what i need is part of the line
  3. Then I split only this line into cells
  4. But if you want to save everything remember that  StringSplit() has eaten up all the seperators ("\n" and ";")
    You have to add them again!

To me this way is a lot easier to handle and to manage with less code.

Reason: