Batch import multiple ascii files

I need to import multiple csv files to update the data and i was wondering, after reading the knowledgebase for the batch importer without success, if there is a way of importing multiple csv files at the same time from the batch import ascii option, instead of doing it manually. Thank you.

@kaizenusing using the batch functionality of AmiBroker you can add as many "ImportASCII" steps as you want.

The format of the file is straightforward to understand (here below a sample with just two .cvs files to import).

<?xml version="1.0" encoding="ISO-8859-1"?>
<AmiBroker-Batch CompactMode="0">
<Step>
<Action>ImportASCII</Action>
<Param>C:\\Program Files (x86)\\AmiBroker\\Download\\ZYY.csv</Param>
</Step>
<Step>
<Action>ImportASCII</Action>
<Param>C:\\Program Files (x86)\\AmiBroker\\Download\\XYZ.csv</Param>
</Step>
</AmiBroker-Batch>

This means that you can just create a .abb (AmiBroker Batch file extension) file to import many tickers using a text editor or any scripting application, or even better directly from an AmiBroker formula looping over your required symbols from your watchlists.

2 Likes

Thanks for your answer. Yes, i know de batch import method, but the problem is that i need to import a lot of files, so i am more interested in the formula looping method, and i still cant figure it out. Can you please give me some kind of example to work with? Thanks.

Use CategoryGetSymbols to get sym list from a watchlist of your choice. Then iterate that list concatenating repeated strings. Apply to chart pane and open param window to click button to trigger export.

/// Code to create Import batch file from multiple symbols of a chosen Watchlist
/// @link https://forum.amibroker.com/t/batch-import-multiple-ascii-files/6762/4
/// by fxshrat
wlnumber = 0;// choose Watchlist number here
datafolder = "C:\\Program Files (x86)\\AmiBroker\\Download\\"; // location of your data files
extension = "csv"; // data file extension
batch_location = "C:\\test.abb";

wlist = CategoryGetSymbols(categoryWatchlist, wlnumber );

"\n";

EnableTextOutput(0);

str1 = "<?xml version='1.0' encoding='ISO-8859-1'?>\n<AmiBroker-Batch CompactMode='0'>\n";

str2 = "";
for( i = 0; ( sym = StrExtract( wlist, i ) ) != ""; i++ )
	str2 += StrFormat( "<Step>\n<Action>ImportASCII</Action>\n<Param>%s%s.%s</Param>\n</Step>\n", datafolder, sym, extension);

str3 = "</AmiBroker-Batch>";

str = str1+str2+str3;

printf( str );

if( ParamTrigger( "Create Import Batch file", "Click here" ) ) {
	fh = fopen(batch_location, "w" );
	if( fh ) { 
		fputs( str, fh );
		fclose( fh );
	} else 
		Error("Error opening batch file!"); 
}

911

2 Likes