Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Backup you Amibroker EOD Database in CSV Format

42 sec read


 

I was trying to search an option which will export the data from AmiBroker to a folder where the data will be stored in seperate csv sheets. Here is a simple trick to export your Amibroker EOD Database to CSV Format. For eg. Nifty will be stored in a sheet where the data will be there from the date specified in the Automatic Analysis window to the date specified in Automatic Analysis window

AFL Code for Exporting to CSV

https://gist.github.com/6d0bc827303faf0cc8b8

Steps to Backup your Data
1)Save the Export to CSV AFL Code to C:\\Program Files\\AmiBroker\\Formulas\\Custom path
2)Create a Folder Name “Amibackup” in C:\\ Drive
3)Open Amibroker ->Analysis-> Automatic Analysis
4)Select All Symbols option from the Apply to coloumn and All Quotatios from the Range Column
you can also select specific Stocks by selecting the suitable options from the Apply to Column
5)Run SCAN
6)Amibroker Database converts to individual .csv file

Download Export CSV data from Amibroker AFL code

Here the limitation is that you cannot specifiy the range of Date. By Default it will download from starting date to
ending date
Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

What is QuantZilla?

Quantzilla is 75+ hours of code mentoring program designed for noncoders who want to learn the coding program right from designing indicators, scanners, trading...
Rajandran R
58 sec read

Things to Consider While Building a Bracket Order Execution…

Building a Bracket Order Strategy is the most demanded request we got from most of the algomojo traders. This article explains the list of...
Rajandran R
12 min read

PlaceOrder – Multi Broker Exectuion Code Snippets for Amibroker

This tutorial explains how to build a button trading right from scratch and with a click of a button how you can send orders...
Rajandran R
7 min read

23 Replies to “Backup you Amibroker EOD Database in CSV Format”

  1. Hi.. Thanks for the code.. Assume that My hard disk’s C drive crashed due to virus and I can’t able to retrieve any past datas.. So, I’ll format the disk and will create a new database which will accept only .txt format..

    My question is,Is it possible to create Ami database which will accept both .csv and .txt format..? Since, our backup is in .csv format I raised this Question..

    Thank you..

    1. Yeh Govindharaj… It supports both .txt and .csv format… you just simply edit the afl code and change it to ur required format and get the backup….
      Now use import wizard and import ascii funtionality to import those backup data into ur new amidatabase

  2. Hi.. I just replaced .csv with .txt in the first line of the code and got backup in .txt format.. Sorry for the previous post..

    But, how to use these datas in a new Database..?

    Thank you..

    1. yes it can used for IEOD you need to edit the code according to your required output format. Small knowledge of C/C++ is good enough to edit the code

  3. sir idon’t know how to Backup you Amibroker EOD Database in CSV Format can you help to do this pleas sir
    i have team wever.

  4. Dear Rajendran,
    While i am trying to take backup the database in amibroker using the above afl it shows an syntax error as below..

    fh = fopen( “
    —————-^

    Error 31.
    Syntax error, unexpected $end, expecting ‘)’ or ‘,’

    Kindly help in this regard.
    Regards,
    Swetharanyan

    1. @Swetharanyan

      Copy the AFL code from here directly to your notepad and from notepad then copy to your amibroker code editor. Direct copying from
      website sometimes creates Double quotation problem.

  5. sir,
    i am also getting syntax error
    While i am trying to take backup the database in amibroker using the above afl it shows an syntax error as below..

    fh = fopen( “
    —————-^

    Error 31.
    Syntax error, unexpected $end, expecting ‘)’ or ‘,’
    i have adopted the solution u suggested but , its showing error

    1. Hi Sameer,
      try this
      fh = fopen( “c:\\AmiBackup\\”+Name()+”.csv”, “w”);
      if( fh )
      {
      fputs( “Ticker,Date,Open,High,Low,Close,Volume \n”, fh );
      y = Year();
      m = Month();
      d = Day();
      //r = Hour();
      //e = Minute();
      //n = Second();
      for( i = 0; i < BarCount; i++ )
      {
      fputs( Name() + "," , fh );
      ds = StrFormat("%02.0f-%02.0f-%02.0f,",
      y[ i ], m[ i ], d[ i ] );
      fputs( ds, fh );
      //ts = StrFormat("%02.0f:%02.0f:%02.0f,",
      //r[ i ],e[ i ],n[ i ] );
      //fputs( ts, fh );
      qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n",
      O[ i ],H[ i ],L[ i ],C[ i ],V[ i ] );
      fputs( qs, fh );
      }
      fclose( fh );
      }
      Buy = 0;

  6. hi
    still the same syntax error apears
    i had already done copy to note pad and then copy to farmula
    still not working any solution to save data in amibroker ????

  7. solved the problem of syntax error..
    the inverted commas should be replaced
    for example – fh = fopen( “c:AmiBackup”+Name()+”.csv”, “w”);

    to

    fh = fopen(“C:AmiBackup”+Name()+”.csv”, “w”);

    this will solve the problem. although you will have to change all the commas in the code.. not just in this line

    1. I am able to resolve on my own. I created the directory named amibackup and also replaced “//” with “\\”
      thanks a ton

  8. Hi Rajendran,
    I am having a bit of a problem with this code. Firstly, I was trying to export intraday data. So I removed the comments to include time. I am afraid the data is coming in one continuous line and there are no line breaks. The time is also not coming correctly they are all coming as 00:00:00.
    When I see the data in the quote editor and of course in Ami the data is displayed correctly as bars.
    My final code is pasted below for ready reference.
    Please help…
    TIA
    Praveen.

    Code===========================
    fh = fopen( “c://AmiBackup//”+Name()+”.csv”, “w”);
    if( fh )
    {
    fputs( “Ticker,Date,Open,High,Low,Close,Volume”, fh );
    y = Year();
    m = Month();
    d = Day();
    r = Hour();
    e = Minute();
    n = Second();
    for( i = 0; i < BarCount; i++ )
    {
    fputs( Name() + "," , fh );
    ds = StrFormat("%02.0f-%02.0f-%02.0f,",y[ i ], m[ i ], d[ i ] );
    fputs( ds, fh );

    ts = StrFormat("%02.0f:%02.0f:%02.0f,",
    r[ i ],e[ i ],n[ i ] );
    fputs( ts, fh );

    qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f",O[ i ],H[ i ],L[ i ],C[ i ],V[ i ] );
    fputs( qs, fh );
    }

    fclose( fh );
    }

    Buy = 0;
    Code ends=====================================
    Sample output data==============================
    Ticker,Date,Open,High,Low,Close,VolumeNIFTY-I,2012-01-02,00:00:00,4637.7998,4656.0000,4592.3999,4648.1001,277565NIFTY-I,2012-01-03,00:00:00,4680.5498,4794.3999,4680.5498,4783.2002,362152NIFTY-I,2012-01-04,00:00:00,4775.2002,4799.0000,4737.6001,4760.2002,353400NIFTY-I,2012-01-05,00:00:00,4759.0000,4791.8501,4740.1001,4758.1001,271152NIFTY-I,2012-01-06,00:00:00,4745.0000,4821.0000,4692.6001,4771.9502,450646NIFTY-I,2012-01-09,00:00:00,4748.3501,4778.0000,4705.1499,4751.7998,321543NIFTY-I,2012-01-10,00:00:00,4780.0000,4876.2998,4779.5000,4870.2998,392413NIFTY-I,2012-01-11,00:00:00,4805.0000,4889.0000,4805.0000,4872.3501,266376

    1. Thanx Rajendran,
      I figured out the issue… Guess, the line feeds are missing.. Thats the reason for the data coming continuous.
      As regards the time stamp issue, it needs to be set in the settings to one minute and then it comes out just fine.
      Posting it here so that others may also benefit…
      HIH,
      Praveen.
      Corrected Code===========================
      fh = fopen( “c://AmiBackup//”+Name()+”.csv”, “w”);
      if( fh )
      {
      fputs( “Ticker,Date,Open,High,Low,Close,Volume\n”, fh );
      y = Year();
      m = Month();
      d = Day();
      r = Hour();
      e = Minute();
      n = Second();
      for( i = 0; i < BarCount; i++ )
      {
      fputs( Name() + "," , fh );
      ds = StrFormat("%02.0f-%02.0f-%02.0f,",y[ i ], m[ i ], d[ i ] );
      fputs( ds, fh );

      ts = StrFormat("%02.0f:%02.0f:%02.0f,",
      r[ i ],e[ i ],n[ i ] );
      fputs( ts, fh );

      qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n",O[ i ],H[ i ],L[ i ],C[ i ],V[ i ] );
      fputs( qs, fh );
      }

      fclose( fh );
      }

  9. hi

    is there any update of the afl for exporting the explorer data to excel/csv…?

    looking for that please…

    Thanks

  10. Hi there, It serves the purpose but exactly what I am looking for… I have one code if you please help me with this. My one custom requirement in the below-mentioned code is to get date in ddmmyyyy format and not in dd-mm-yyyy. Admin please help…

    // create folder for exporting purposes
    fmkdir( “C:\\DataExport\\” );

    // open file for writing
    // file name depends on currently processed ticker
    fh = fopen( “c:\\DataExport\\” + Name() + “.txt”, “w” );

    // proceed if file handle is correct
    if ( fh )
    {
    dt = DateTime();

    // write header line
    fputs( “Ticker,Date/Time,Open,High,Low,Close,Volume\n”, fh );

    // iterate through all the bars

    for ( i = 0; i < BarCount; i++ )
    {
    // write ticker name
    fputs( Name() + "," , fh );

    // write date/time information
    fputs( DateTimeToStr( dt[ i ] ) + ",", fh );

    //write quotations and go to the next line
    qs = StrFormat( "%g,%g,%g,%g,%g\n", O[ i ], H[ i ], L[ i ], C[ i ], V[ i ] );
    fputs( qs, fh );

    }
    // close file handle
    fclose( fh );
    }

    // line required by SCAN option

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More