FileReadString csv file

 
void getActiveSignals(){
    row = 0;
    col = 0;
    activeSignalsFileHandle = FileOpen(getActiveFileName(), FILE_CSV|FILE_READ|FILE_WRITE, ',');
    if(activeSignalsFileHandle>0)
    {
        while(True) //loop through each cell
        {
            string temp = FileReadString(activeSignalsFileHandle); //read csv cell
            if(FileIsEnding(activeSignalsFileHandle)) break; //FileIsLineEnding = End of Line
            dataActiveSignals[col][row]=temp; //save reading result to array
            Print(temp);
            if(FileIsLineEnding(activeSignalsFileHandle)) //FileIsEnding = End of File
            {
                col = 0;
                row++; //next row
            }
            else
            {
                col++; //next col of the same row
            }
        }
        FileClose(activeSignalsFileHandle);
    }
    else
    {
        Comment("File "+getActiveFileName()+" not found, thelast error is ", GetLastError());
    }
}

then the value of var dataActiveSignals is written to openSignal-6-2019.csv file by using function code as follows:

void checkNewActiveSignalsData() {

   int totalActive = ArrayRange(dataActiveSignals,1);

   int totalOpened = ArrayRange(dataOpenedSignals,1);

   for(int j = totalActive-1; j>= 0; j--){

       bool isActiveSignalExist = false;

       for(int i = 0; i< totalOpened; i++){

          if(isOpenIsameWithActiveJ(dataOpenedSignals, dataActiveSignals, i, j)){

              isActiveSignalExist = true;

          }

       }

       if(!isActiveSignalExist){

            // trade the signal

            doTrade(dataActiveSignals[2][j], StrToDouble(dataActiveSignals[3][j]), StrToDouble(dataActiveSignals[5][j]), dataActiveSignals[1][j]);

            // save the signal to open

            openedSignalsFileHandle = FileOpen(getOpenFileName(), FILE_CSV|FILE_READ|FILE_WRITE, ',');

            //FileSeek(openedSignalsFileHandle,0,SEEK_END);

            FileWrite(openedSignalsFileHandle, dataActiveSignals[0][j], dataActiveSignals[1][j], dataActiveSignals[2][j], dataActiveSignals[3][j], dataActiveSignals[4][j], dataActiveSignals[5][j], dataActiveSignals[6][j]);

            FileClose(openedSignalsFileHandle);

            getOpenedSignals();

            totalOpened = ArrayRange(dataOpenedSignals,1);

       }

   }

}

I have file activeSignal-6-2019.csv and openSignal-6-2019.csv. 

activeSignal-6-2019.csv, the data is

04 June 01:06 PM GMT+3,GBPNZD,SELL,1.9267,1.9157,1.9117,1.9037


openSignal-6-2019.csv get the data

04 June 01:06 PM GMT+3,GBPNZD,SELL,1.9267,1.9157,1.9117,

the value 1.9037 not written

dataActiveSignals[6][0] shows empty string, how can I get the value from activeSignal-6-2019.csv?

Files:
file.zip  4 kb
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Is the file ANSI or Unicode and which did you use to open the file?
 
William Roeder:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Is the file ANSI or Unicode and which did you use to open the file?
FileOpen(getActiveFileName(), FILE_CSV|FILE_READ|FILE_WRITE, ',');

I use that, it is csv file

 
luxkoman:

then the value of var dataActiveSignals is written to openSignal-6-2019.csv file by using function code as follows:

I have file activeSignal-6-2019.csv and openSignal-6-2019.csv. 

activeSignal-6-2019.csv, the data is

04 June 01:06 PM GMT+3,GBPNZD,SELL,1.9267,1.9157,1.9117,1.9037

openSignal-6-2019.csv get the data

04 June 01:06 PM GMT+3,GBPNZD,SELL,1.9267,1.9157,1.9117,

the value 1.9037 not written

dataActiveSignals[6][0] shows empty string, how can I get the value from activeSignal-6-2019.csv?

The sequence of these 3 lines are wrong:

                :
            if(FileIsEnding(activeSignalsFileHandle)) break; //FileIsLineEnding = End of Line
            dataActiveSignals[col][row]=temp; //save reading result to array
            Print(temp);
                :

Should change to:

                :
            dataActiveSignals[col][row]=temp; //save reading result to array
            Print(temp);
            if(FileIsEnding(activeSignalsFileHandle)) break; //FileIsLineEnding = End of Line
                :

Or else the last field of the last line will never be assigned into your dataActiveSignals array.

 
Seng Joo Thio:

The sequence of these 3 lines are wrong:

Should change to:

Or else the last field of the last line will never be assigned into your dataActiveSignals array.

ok thanks. It works. :)

Reason: