for loop

 
int init()
  {
  
  int handle;
  handle=FileOpen("countmein", FILE_CSV|FILE_WRITE, ';');
  if(handle>0)
   
       for (int Counter = 1; Counter <= 100; Counter++)
    {
     FileWrite(handle, Close[Counter], Open[Counter], High[Counter], Low[Counter]);
     FileClose(handle);
    
  }
  //...

//----
   
//----
   return(0);

Suppose I want to write the last 100 bars to a CSV file, why doesn't this code work?

The loop doesn't seem to be updating.

Can anybody help me out?


Thanks folks.

 
monkeybus:

Suppose I want to write the last 100 bars to a CSV file, why doesn't this code work?

The loop doesn't seem to be updating.

Can anybody help me out?

You Open the File, start the loop, write the first set of values, Close the File, then try to write the rest of the values . . . to a closed file.
 

You are correct. How could I miss this?


Thanks a lot.