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

Re: [amibroker] Re: How To Overwrite Exported CSV Data File



PureBytes Links

Trading Reference Links

Hi Lester.

Thanks for your code. It works OK and you are great!

Amon

Lester Vanhoff <ebsn247lsm@xxxxxxxxxxxxx> wrote:                               I forgot to include the line that automatically creates the direcotry C:\Test. You don't need if the directory already exists:
 
 output_folder = "C:\\Test\\";
 fmkdir( output_folder );
 fh = fopen(output_folder + Name() + ".csv", "w");
 
 etc.
 
 --- In amibroker@xxxxxxxxxxxxxxx, "Lester Vanhoff" <ebsn247lsm@xxx> wrote:
 >
 > Amon, it is actually easier than exporting multiple symbols into a single file. The following code will export data in the following format:
 > 
 > - each file has a header
 > - no ticker column (ticker is included in the file name)
 > - US date format: mm/dd/yy
 > 
 > To remove the header simply delete this line:
 > 
 > fputs( "Date,Open,High,Low,Close,Volume,OpenInt\n", fh );
 > 
 > /****START****/
 > 
 > output_folder = "C:\\Test\\";
 > 
 > fh = fopen(output_folder + Name() + ".csv", "w");
 > 
 > if (fh)
 > {
 >   fputs( "Date,Open,High,Low,Close,Volume,OpenInt\n", fh );
 >     y = Year()%100;
 >     m = Month();
 >     d = Day();
 >   for( i = 0; i < BarCount; i++ )
 >     {
 >     ds = StrFormat("%02.0f/%02.0f/%02.0f, ", m[i], d[i], y[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;
 > 
 > /****END****/
 > 
 > 
 > --- In amibroker@xxxxxxxxxxxxxxx, Amon Ra <amon_gizeh@> wrote:
 > >
 > > Hi Lester.
 > > Your code works Ok but how can export all simbols with a single click into different csv files? ex: MSFT in MSFT.csv, IBM into IBM.csv etc. ?
 > > 
 > > 
 > > 
 > > Lester Vanhoff <ebsn247lsm@> wrote:                               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****/
 > >
 >
 
 
     
                       

 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com