How to include 'Header Row' in exploration

Hi Experts,

I'm exporting exploration data to CSV. I have written the below code which works fine but unable to include any header row on top of the CSV.

#pragma maxthreads 1

_ROC = ROC( C, 1 );
filepath = "C:\\ScanExport.csv";

if( Status( "stocknum" ) == 0 )
{
    fdelete( filepath );
}

fh = fopen( filepath, "a", True );

if( fh )
{
    fputs( Name() + "," + _ROC + "\n", fh );
    fclose( fh );
}

The output is similar to:
Capture1

But I want the output to include a 'Header Row' similar like:
Capture2

Can anyone help please in identifying on what I'm missing or reconstructing the code.
Any help would be much appreciated!

Regards,
Sandeep

Your code is not an exploration.
Proper exploration code would look like this:

AddColumn( ROC( C, 1 ), "ROC");
Filter = Status("lastbarinrange");

and you would copy it to excel simply by pressing Ctrl+A (select all), Ctrl+C (copy) and PASTE to Excel.

And column headers will be automatically included.

If you want to do write files from the code simply write whatever you want in the header

if( Status( "stocknum" ) == 0 )
{
   fh = fopen( filepath, "w" ); // open for writing, not appending (so you don't need to delete)
   if( fh ) 
   { 
     fputs("Name, ROC\n"), fh ); 
     fclose( fh );
   }
}
3 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.