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

[amibroker] import.js questions



PureBytes Links

Trading Reference Links

I am trying to use Tomasz Janeczkos' import.js script (below) to
import a series of text files into several AmiBroker databases and
into different watchlists.  The script works, importing the specified
text file into the default database of an open AB database.  How do I:

1] Select a watch list
2] Select an alternate database
3] Import into the database when AB is closed

Many thanks for and help and guidance.

k


/*
** AmiBroker/Win32 scripting Example
**
** File:	 Import.js
** Created:	 Tomasz Janeczko, January 30th, 2000
** Purpose:	 Import quotes from Metastock ASCII file
** Language: JScript (Windows Scripting Host)
**
** The data is stored in lines with following format
** <ticker>,<per>,<date>,<high>,<low>,<close>,<volume>
**
*/


ImportMsASCII( "Import_Test.txt" );

function ImportMsASCII( filename )
{
	var fso, f, r;
	var ForReading = 1;
	var AmiBroker;
	var date;
	var quote;
	var fields;
	var stock;

	/* Create AmiBroker app object */
	AmiBroker = new ActiveXObject( "Broker.Application" );

	/* ... and file system object */
	fso = new ActiveXObject( "Scripting.FileSystemObject" );

	/* open ASCII file */
	f = fso.OpenTextFile( filename, ForReading);

	/* skip first line which contains format definition */
	f.SkipLine(); 

	/* read the file line by line */
	while ( !f.AtEndOfStream )
	{  
		  r =  f.ReadLine();
		  
		  /* split the lines using comma as a separator */
		  fields = r.split(","); 
		  
		  /* add a ticker - this is safe operation, in case that */
		  /* ticker already exists, AmiBroker returns existing one */
		  stock = AmiBroker.Stocks.Add( fields[ 0 ] ); 
		  
		  /* notify the user */
		/*  WScript.Echo( "Importing " + fields[ 0 ] );*/
		  
		  /* parse the date from the text file */
		  date = new Date( fields[ 2 ] );
		  
		  /* add a new quotation */
		  quote = stock.Quotations.Add( date.getVarDate() );
		  
		  /* put data into it */
		  quote.High  = parseFloat( fields[ 3 ] );
		  quote.Low   = parseFloat( fields[ 4 ] );
		  quote.Close = quote.Open = parseFloat( fields[ 5 ] );
		  quote.Volume = parseInt( fields[ 6 ] );
		  
	}

	/* refresh ticker list and windows */
	AmiBroker.RefreshAll();

	/* notify the user */
	 /* WScript.Echo( "Finished" );*/

}



Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/