write to file

 

Hi

in this code only line Specified in file is write

why lines next not write?

please help me

   filehandle=FileOpen("fractals1.csv",FILE_WRITE|FILE_READ|FILE_CSV|FILE_SHARE_READ|FILE_ACCESS_DATE|FILE_IS_WRITABLE|FILE_IS_READABLE);
   if(filehandle!=INVALID_HANDLE)
     {
      FileWrite(filehandle,TimeCurrent()," - ",Symbol()," - ",PERIOD_CURRENT);
      FileWriteInteger(filehandle,100,INT_VALUE);
      FileWriteDouble(filehandle,60.8);
      FileWriteDouble(filehandle,23.4);
      FileClose(filehandle);
      Print("FileOpen OK");
     }
 
No idea, but I would try removing "|FILE_ACCESS_DATE|FILE_IS_WRITABLE|FILE_IS_READABLE" from your FileOpen() call.
 
removed, But did not Difference
 
Maryam:

Hi

in this code only line Specified in file is write

why lines next not write?

please help me

Here's what one should do when having problem like this

1. Read the manual one more time. In this case, look at definition of FileOpenFileWriteIntegerFileWriteDouble - click that.

2. If number 1 above still does not help in finding the problem. Print the return value of every function and every error we could find. Something like this ...

int filehandle;
   filehandle=FileOpen("fractals1.csv",FILE_WRITE|FILE_READ|FILE_CSV|FILE_SHARE_READ|FILE_ACCESS_DATE|FILE_IS_WRITABLE|FILE_IS_READABLE);
   if(filehandle!=INVALID_HANDLE)
     {
      ResetLastError();
      Print (FileWrite(filehandle,TimeCurrent()," - ",Symbol()," - ",PERIOD_CURRENT));
      Print ("err ",GetLastError()); ResetLastError();

      Print (FileWriteInteger(filehandle,100,INT_VALUE));
      Print ("err ",GetLastError()); ResetLastError();

      Print (FileWriteDouble(filehandle,60.8));
      Print ("err ",GetLastError()); ResetLastError();

      Print (FileWriteDouble(filehandle,23.4));
      Print ("err ",GetLastError()); ResetLastError();

      FileClose(filehandle);
      Print("FileOpen OK");
     }

You will find there an error 5011 or "The file must be opened as a binary one".

In your case, FileWriteIntegerFileWriteDouble , is intended for writing to a bin file (or binary file), not to a csv file, while you are trying to write to a .csv file. So the explanation is that file function for binary file can not be used for csv file.

So the code should be like this

   int filehandle;
   filehandle=FileOpen("fractals1.csv",FILE_WRITE|FILE_READ|FILE_CSV|FILE_SHARE_READ|FILE_ACCESS_DATE|FILE_IS_WRITABLE|FILE_IS_READABLE);
   if(filehandle!=INVALID_HANDLE)
     {
      FileWrite(filehandle,TimeCurrent()," - ",Symbol()," - ",PERIOD_CURRENT));
      FileWrite(filehandle,100,INT_VALUE));
      FileWrite(filehandle,60.8));
      FileWrite(filehandle,23.4));
      FileClose(filehandle);
      Print("FileOpen OK");
     }

 

 

Thank you very much

My Problem was solved

 
Intrger or Double is unreadable files CSV?

 
Maryam:
Intrger or Double is unreadable files CSV?

They are readable. how about showing your read files code.
 
Lets fully explain you comfortable help me

I want indicator information all symbols in Market Watch save into file, and then after find symbol serching data for Comparison

I can write to file but I can not read

please see following code

   string str;
   bool find=false;
   ResetLastError();
   filehandle=FileOpen("fractals1.csv",FILE_READ|FILE_CSV);
   if(filehandle!=INVALID_HANDLE)
     {   
      FileSeek(filehandle,0,SEEK_SET);
      while (find==false)
      {       
       str=FileReadString(filehandle);
       Print (str);
       Print ("err String",GetLastError()); ResetLastError();
             
       if(str==Symbol())
        {
         Print("find ",str);
         find=true;
        }
       else FileSeek(filehandle,1,SEEK_CUR);
      }
    }



Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
 
Maryam:

Lets fully explain you comfortable help me

I want indicator information all symbols in Market Watch save into file, and then after find symbol serching data for Comparison

I can write to file but I can not read

please see following code

 Here's my code for read and write operation that I tested several time ago.

   int hnd = 0;
   string txt;

   //--- Write operation
   ResetLastError();
   hnd = FileOpen("test.csv",FILE_WRITE|FILE_CSV );
   if(hnd != INVALID_HANDLE)
     {
      FileWrite (hnd, "EURUSD", 2.34567, 3.45678, 4.56789);
      FileWrite (hnd, "GBPUSD", 8.76543, 7.65432, 6.54321);
      FileClose(hnd);
     }
   else Print("Operation FileOpen write failed, error ",GetLastError());
  
   //--- Read operation
   ResetLastError();
   hnd = FileOpen("test.csv",FILE_READ|FILE_CSV);
   if(hnd != INVALID_HANDLE)
     {
     while (FileIsEnding(hnd) == false)
        {
        txt = FileReadString(hnd);
        Print (txt);
        
        txt = FileReadString(hnd);
        Print (txt);
        
        txt = FileReadString(hnd);
        Print (txt);
        
        txt = FileReadString(hnd);
        Print (txt);
        }
      FileClose(hnd);
     }
   else Print("Operation FileOpen read failed, error ",GetLastError());
 
phi.nuts:

 Here's my code for read and write operation that I tested several time ago.

Thank you

There is no possibility to search in the file? For example, the 100 symbols with indicators data into the file written

To compare prices string to double become?

 
Maryam:

Thank you

There is no possibility to search in the file? For example, the 100 symbols with indicators data into the file written

To compare prices string to double become?

1. There's always a way to search in the file, but you just have to code its logic. Basically, you scan the data one by one :(.

2. You need to convert string into double using StringToDouble(). Comparing double variable is risky, maybe I'll explain that later.