Thanks, Dingo, for your help. Your code had some problems when scan was applied 
to a watch list so I modified it a little. The following formula seems to be 
working fine with both "current symbol" and "filters" set to watch lists. The 
old data in the file is always overwritten and all watch list tickers are 
included in export:

/****START****/

output_folder = "C:\\Test";
output_file   = "Mseod.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 needed to get 
all tickers from watch list
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] ); // date string
  fputs( ds, 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

/****END****/


--- In [email protected], "dingo" <[EMAIL PROTECTED]> wrote:
>
> Oh, I thought you'd know...
> 
> Here:
> 
> if ( Status("stocknum") == 0 )
> {
>     output_folder = "C:\\Test";
>     output_file   = "Mseod.csv";      
>     fmkdir( output_folder ); // if the directory doesn't exists it will be
> automatically created
>     fh = fopen( output_folder + "\\" + output_file, "w"); 
> }
> 
> 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.f%02.f%02.f,", y[i], m[i], d[i] ); // date string
>   fputs( ds, 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 );
>   }
> }
> Buy = 0; // link to "scan" button
> 
> 
> > Below is the copy of e-mail from Dingo with his idea (his 
> > post for some reason has never made it to this board). I'm 
> > still not sure how to implement it in my code. Thanks, Dingo.
> > 
> > From: dingo <dingo@>
> > 
> > What you need is a "one time switch" so you can open the file 
> > in overwrite mode once and then do an append the rest of the 
> > time. This can be accomplished by:
> > 
> > if ( Status("stocknum") == 0 )
> > {
> >        Your "one time stuff" here before your other code }
> > 
> > 
> > --- In [email protected], "Lester Vanhoff" 
> > <ebsn247lsm@> wrote:
> > >
> > > The following AFL will export eod data to C:\Test\Mseod.csv 
> > (set the filter, eg. a watch list and hit Scan button). 
> > However, to use it in real life you would need to delete that 
> > csv file before every export, otherwise the new data will be 
> > appended to the old file. The question is how to overwrite 
> > this file from AFL.
> > > 
> > > 1) This line must be set to a=append in order to export all 
> > tickers in a watch list. If set to w=overwrite only one 
> > ticker will be exported:
> > > 
> > > fh = fopen( output_folder + "\\" + output_file, "a");
> > > 
> > > 2) I tried to include fdelete(), 2nd line below, but then 
> > only data for one ticker is exported:
> > > 
> > > fmkdir( output_folder );
> > > fdelete( output_folder + "\\" + output_file );
> > > 
> > > Here is the full code:
> > > 
> > > // Export data to C:\Test\Mseod.csv in old MetaStock format: 
> > > Tkr,D,yymmdd,O,H,L,C,V,oi
> > > 
> > > output_folder = "C:\\Test";
> > > output_file   = "Mseod.csv";
> > > fmkdir( output_folder ); // if the directory doesn't exists 
> > it will be 
> > > automatically created
> > > 
> > > fh = fopen( output_folder + "\\" + output_file, "a"); // a=append 
> > > needed to get all tickers from watch list
> > > 
> > > 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.f%02.f%02.f,", y[i], m[i], d[i] ); 
> > // date string
> > >   fputs( ds, 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
> > >






------------------------ Yahoo! Groups Sponsor --------------------~--> 
You can search right from your browser? It's easy and it's free.  See how.
http://us.click.yahoo.com/_7bhrC/NGxNAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to