File Problems

 

I can not seem to get any data into the files I am creating. Who can see what I am doing wrong.

The code is stripped down to show only the file code as below: when I examine the created files they are empty (not even anything in the column headings)

//Variable declarations:
string OldDay = TimeToString(1000, TIME_DATE);
string SName = "Will be Short Name";
string FName = "Will be File Name";StringConcatenate(SName,"StaticAnalysis", OldDay);

//Once off creation of a dummy file to kick of file system:
fileStringConcatenate(FName, SName, ".csv");  
datafile = FileOpen(FName, FILE_WRITE|FILE_CSV);

//Making a unique file at the start of every new day (rolling 1 year):
if (StrucNow.day_of_year != OldDay)
 {   
   FileClose(datafile);
   OldDay = StrucNow.day_of_year;
   StringConcatenate(SName, "StaticAnalysis", OldDay);
   StringConcatenate(FName, SName, ".csv");
   datafile = FileOpen(FName, FILE_WRITE|FILE_CSV);
// Files to be exported to spreadsheet so these are column headings
   FileWrite(FName, "Ticket", "Target", "Position", "Price", "Volume", "Profit");
   FileFlush(datafile);
  }

//attempt to write data to the daily file under the above headings when certain conditions are met:
FileWrite(datafile, ticket, target, position, myprice.bid, newvolume, 
                 PositionGetDouble(POSITION_PROFIT));
FileFlush(datafile);
 
BigAl:

I can not seem to get any data into the files I am creating. Who can see what I am doing wrong.

The code is stripped down to show only the file code as below: when I examine the created files they are empty (not even anything in the column headings)

In . . .

FileWrite(   FName,      "Ticket", "Target", "Position", "Price", "Volume", "Profit");

 shouldn't you be using the file handle instead of part of the filename ?  FileWrite()

 
RaptorUK:

In . . .

 shouldn't you be using the file handle instead of part of the filename ?  FileWrite()

A BIG LOL !!!! How to look a fool with stupid mistakes.

Thanks RaptorUK

 
BigAl:

A BIG LOL !!!! How to look a fool with stupid mistakes.

Thanks RaptorUK

Don't beat yourself up,  the only people who don't make mistakes are those that do nothing  :-)  
Reason: