Help Writing to csv file

 

HI, Can anyone help me add the following script code, so that data into a CSV was imported into columns and cells?

//+------------------------------------------------------------------+
int start()
  {
 
 
 
      {
      mPrev=m;
      handle=FileOpen("Data\\Statement.csv",FILE_WRITE|FILE_CSV,",");
      if(handle<0) return(0);
      FileWrite(handle,"Ticket #,Open Time,Type,");
      for(i=0;i<hstTotal;i++)
         {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
            {
            FileWrite(handle,OrderTicket(),TimeToStr(OrderOpenTime(),TIME_DATE|TIME_MINUTES),OrderType(),);
            }
         }
      FileClose(handle);
      }
   return(0);
  }
//+----------------------
 
Question not understood. Create a script. paste code into script. Compile. Drag script onto a chart. Import the file.
 

Hi. I believe that MT4 does not place data into columns or cells....at least not in a way that you can manually open the .csv and see the data listed by column or cell.


This thread might help you

https://forum.mql4.com/28909

 

Your code should work properly except for one minor problem - instead of:

FileWrite(handle,"Ticket #,Open Time,Type,Lots,Symbol,Open Price,Stop/Loss,Take Profit,Close Time,Close Price,Profit,Comment");

Should be:

FileWrite(handle,"Ticket #","Open Time","Type","Lots","Symbol","Open Price","Stop/Loss","Take Profit","Close Time","Close Price","Profit","Comment");

This way the header will be in columns as well.

 
Your code produces a delimited comma-separated cvs file. In my Mac MS Office 2008, I open new Excel file and then IMPORT the cvs file. Then select cvs file type, then select delimited, then select next, then select comma and then select Finish.
Reason: