[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] How To Avoid Exporting Multiple Headers To ASCii File



PureBytes Links

Trading Reference Links

Below is the code that exports Eod data in old MetaStock format to C:\ZZ\Mseod.csv. It is based on Graham's formula found here:

http://www.amibroker.com/library/detail.php?id=327

Problem: how to place the header in the CSV file only once, at the top of the file, when you are exporting multiple symbols, eg. from a watch list, to avoid the situation when the header for the next ticker is placed in the middle of the file:

http://img184.imageshack.us/img184/940/12262006041035ps1.png

Here is the line with fputs(...) that had to be removed because of this. It would have to be modified somehow:

fh = fopen( output_folder + "\\" + output_file, "a");
if (fh)
{
// fputs( "Ticker,Date,Open,High,Low,Close,Volume,Trades\n", fh );
  t = Name();
  p = "D";
  y = Year()%100;

And here is the full code. The first part with "IF" allows overwriting the old, existing CSV file with the new data. Without it, the new data would just be appended to the old data.

/**** START ****/

output_folder = "C:\\ZZ";
output_file   = "Mseod.csv";

// This is "one time switch"; it opens the file in overwrite mode once before 
// it is run in append mode rest of the time.
// If the directory doesn't exists it will be automatically created
// If the file already exists all data will be w=overwritten

if ( Status("stocknum") == 0 )
{
fmkdir( output_folder );
fopen( output_folder + "\\" + output_file, "w");
}

// a=append is needed to get all tickers from watch list

fh = fopen( output_folder + "\\" + output_file, "a");
if (fh)
{
  t = Name();
  p = "D";
  y = Year()%100;
  m = Month();
  d = Day();
for( i = 0; i < BarCount; i++ ) // loop
  {
  fputs( t + "," , fh );
  fputs( p + "," , fh );
  ds = StrFormat( "%02.0f%02.0f%02.0f,", y[i], m[i], d[i] );
  fputs( ds, fh );
  qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f,%.0f\n", O[i], H[i], L[i], C[i], V[i], OI[i] );
  fputs( qs, fh );
  }
fclose( fh );
}
Buy = 0; // link to "scan" button

/**** END ****/


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.28/604 - Release Date: 12/26/2006 12:23 PM