Search Your Queries Here

Export intraday and EOD data to TXT files from Amibroker to TEXT




First Process

Export intraday and EOD data to TXT files
One file for each stock
In the first line insert the directory you want to save them to, make sure the
directory exists
Select your charts to export with the “Apply to” filter in AA window
Select the timeframe period you want to save as using the AA “Settings”
Press Scan button

AFL :


/*
Export intraday and EOD data to TXT files
*/
fh = fopen( "c:\\SaveData\\"+Name()+".txt", "w");
if( fh )
{
   fputs( "Ticker,Date,Time,Open,High,Low,Close,Volume \n", fh );
   y = Year();
   m = Month();
   d = Day();
   r = Hour();
   e = Minute();
   n = Second();
   index = BarCount - 420;
   if(index > 0)
   {
    for( i = index; 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 );
    }
   }
   else {
    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;


Second Process

fmkdir( "C:\\SaveData" );
Buy = ( (DateNum() >= 1121220) AND (DateNum() <= 1121231) ); // data exported from 20/12/2012 to 31/12/2012

//if we want to export data for a single Day, we modify the Second line like this
//Buy = ( (DateNum() == 1070129));

for( i = 0; i < BarCount; i++ )
if( Buy[i] )
{
//fh = fopen( "C:\\SaveData\\intraday.csv", "a");//if we want to export all data in a single file//
fh = fopen( "C:\\SaveData\\"+Name()+".csv", "a");// if we want to export data in an individual file//
if( fh )
{
y = Year();
m = Month();
d = Day();
r = Hour();
e = Minute();
s= Second();

for( i = 0; i < BarCount; i++ )
if( Buy[i] )

{
fputs( Name() + "," , fh );
ds = StrFormat("%02.0f/%02.0f/%02.0f%02,",
y[ i ], m[ i ], d[ i ] );
fputs( ds, fh );

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

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

/*Export Data from Amibroker to ASCII files

Here there is a formula available to export data from Amibroker to ASCII files. With the formula we can export data for a specified period from Amibroker database.

How to export:

Scan with the formula in Automatic Analyser (AA) in Amibroker.
The formula will create a folder in C drive named 'Savedata' and will collecte the data in separate text files for each symbol.

Periodicity:

WE can export the data for different periodicity 1min, 5min, 10min or daily etc. as we required. To configure that go to AA > settings > General > Periodicity and set periodicity. Thus we can get data for 5min, 10min, 1 Hour, daily etc.

Select Date Range:

To set the date range, we have to edit the formula.
Open AA > pick (the formula file) > edit.
In the second line we can see:

Buy = ( (DateNum() >= 1061225) AND (DateNum() <= 1070110) );

First DateNum is the start date and second DateNum is end date.
The current settings will export data from 20061225(=10612205, so 2006 =106) to 20070110.
Just like that, we can select another date range. Instead of 2006, should give 106 and for 2007, give 107 etc. Month and date are same. Save the formula and scan it.
It will export and save the data in C:\Savedata folder.
If you want to export for an another date range, that will also be added to the corresponding files just after the current data.*/ 

0 comments:

About Me

My photo

I am Technical Analyst in Various Markets eg. NSE,MCX,FOREX. and just love to help everyone in markets to make profits.