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

[amibroker] Re: Exploration For Exporting ASCii Intraday Data Won't Work - Resolved



PureBytes Links

Trading Reference Links

Thanks, Prashanth, that did it. In AA-Settings I had periodicity set to "daily". It should be "1 minute".

Here is the summary of additions to Graham's original code from here:

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

1) The "fmkdir" line will create the output folder if it doesn't exist.

2) The "fopen" line is the "One time switch", which opens the file in overwrite mode once, before the rest of the formula is run in append mode. This way if you already have the old "csv" file on your hard drive it will be overwritten with the new data. Without this addition the new data will be appended to the old data.

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

3) Trying to have the date format to show two-digit year instead of four-digit was a tough one. Here is the solution:

y = Year()%100;

4) File header was removed because in the csv file with the data for multiple tickers it was created for each new ticker in the middle of the file:

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

fh = fopen( output_folder + "\\" + output_file, "a");
// a=append is needed to get all tickers from watch list
if (fh)
{
/* fputs( "Ticker,Date,Time,Open,High,Low,Close,Volume,Trades\n", fh ); */
   t = Name();
   y = Year();   // to get two digit year use: y = Year()%100;
   etc.

I will start another thread about this issue.

Happy New Year,
Lester

----------------------
Here is the full code:

// Export RT data to C:\ZZ\RT.csv in the format: Tkr,mm/dd/yyyy,hh:mm:ss,O,H,L,C,V,I

// 1) AA - settings - periodicity: one min. Chart can be set to any peridicity. Date range won't work.
// 2) Execution: AA - ApplyTo (set "filters") - Date Range: anything (it doesn't work) - Scan
// 3) If the directory doesn't exist it WILL be created automatically
// 4) Hitting "verify" or "apply" buttons exports only the active symbol in the periodicity of the cahrt.
//    Use "scan" to export a watch list, in periodicity set in AA-Settings

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

if ( Status("stocknum") == 0 )
{
fmkdir( output_folder ); // if the directory doesn't exists it will be automatically created
fopen( output_folder + "\\" + output_file, "w"); // if the file already exists all data will be w=overwritten
}

fh = fopen( output_folder + "\\" + output_file, "a"); // a=append is needed to get all tickers from watch list
if (fh)
{
// fputs( "Ticker,Date,Time,Open,High,Low,Close,Volume,Trades\n", fh );
   t = Name();
   y = Year();   // to get two digit year use: y = Year()%100;
   m = Month(); 
   d = Day(); 
   r = Hour();
   e = Minute();
   n = Second();
for( i = 0; i < BarCount; i++ ) // loop
  {
  fputs( t + ", " , fh );
  ds = StrFormat("%02.0f/%02.0f/%02.0f, ", m[i], d[i], y[i] ); // date string
  fputs( ds, fh );
  ts = StrFormat("%02.0f:%02.0f:%02.0f, ", r[i], e[i], n[i] ); // time string
  fputs( ts, fh );
  qs = StrFormat("%.4f, %.4f, %.4f, %.4f, %.0f, %.0f\n", O[i], H[i], L[i], C[i], V[i], OI[i] ); // quote string
  fputs( qs, fh );
  }
fclose( fh );
}
Buy = 0; // link to "scan" button

/************/



Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.27/602 - Release Date: 12/25/2006 10:19 AM