amibroker

HomeKnowledge Base

How to export quotations from AmiBroker to CSV file ?

The easiest way to export quotes to CSV file is to use the below formula from Automatic Analysis window:
(Analysis -> Automatic Analysis)

Filter=1;
AddColumn(O,"Open");
AddColumn(H,"High");
AddColumn(L,"Low");
AddColumn(C,"Close");
AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0)

  1. Open: Analysis->Formula Editor
  2. Paste the above formula into formula window
  3. Choose Tools->Send to Auto-Analysis menu in the Formula Editor
  4. In Automatic Analysis window select Apply to: All Stocks, Range: All quotations (or any other time range or filter, depending on what you need to export)
  5. Press Explore button
  6. Press Export button, specify the name and press OK

6 Responses to “How to export quotations from AmiBroker to CSV file ?”

  1. March 6th, 2006 | 6:53 pm

    From experience of this if you intend to import this data back into Amibroker, you need to make certain your windows date and time formats are compatible with the AB ascii import formats. eg time to be in 24 hour clock

  2. March 6th, 2006 | 7:41 pm

    Yes that’s true, this code sample was designed to be easy and output was not intended to be re-imported to AmiBroker. There are other ways to export of course, including using file functions as shown in the code below that does what you asked for (exports date in fixed YYMMDD format and times in HHMMSS 24-hour format).

    fh fopen"DataFor"+Name()+".csv""w" );
    if( 
    fh )
    {
      
    fputs("Symbol,Date,Time,Open,High,Low,Close,OpenInt,Volume\\n"fh );

      dn DateNum();
      
    tn TimeNum();

      for( 0BarCounti++ )
      {
       
    Line Name() +
       
    StrFormat(",%06.0f,%06.0f,%g,%g,%g,%g,%g,%g\\n",
       
    dn] % 1000000,
       
    tn],
       
    Open],
       
    High],
       
    Low],
       
    Close],
       
    OpenInt],
       
    Volume] );
      
       
    fputsLinefh );
      }
     
      
    fclosefh );
    }

    Buy=Sell=0// for scan
    Filter Status("lastbarinrange");
    AddTextColumn("Export done""Status")

  3. jim
    July 5th, 2006 | 10:45 pm

    is there anyway to export all datas to Metastock format ?

  4. July 6th, 2006 | 3:33 am

    You can not export to Metastock directly, but you can export to text file and later use Equis Downloader to import text files to Metastock.

  5. October 16th, 2006 | 5:54 am

    […] 1) Export quotations from one database to the ASCII files and reimport quotes from another database (export procedure is described in the following article in the Knowledge Base http://www.amibroker.com/kb/2006/03/04/how-to-export-quotations-from-amibroker-to-csv-file/ ) […]

  6. AFL
    August 26th, 2007 | 2:11 am

    How to separate day/time column to day column and time column? eg. 10-10-07 10:30 to 10/10/07 and 10:30