Hi, this script is to import data from a csv file. Its format is
strange though. It contains data in the following format for a single
ticker on a particular date.
Time(in hhmmss),Last Price,Volume
(e.g 105557,101.05,131.00
105600,101.10,100.00
105604,101.05,50.00 )
I need to import the above data to an intraday database.
The ticker name and date are needed to be manually added to the script.
I have modified the script from http://www.amibroker.com/docs/ab302.html
<http://www.amibroker.com/docs/ab302.html> and made this.
It gives the error at quote = stock.Quotations.Add(time.getVarTime() );
I am a newbie to this script programming. Any help would be greatly
appreciated.
This is the script.
ImportCSV( "c:\\testfile.csv" );
function ImportCSV( filename )
{
var fso, f, r;
var ForReading = 1;
var AmiBroker;
var ticker = "TST"; /* Manually enter Ticker Name */
var date = "08/14/2008"; /* Manually enter Date */
var quote;
var fields;
var stock;
var time;
/* Create AmiBroker app object */
AmiBroker = new ActiveXObject( "Broker.Application" );
/* ... and file system object */
fso = new ActiveXObject( "Scripting.FileSystemObject" );
/* add a ticker - this is safe operation, in case that */
/* ticker already exists, AmiBroker returns existing one */
/* we are doing this outside loop since the file contains */
/* quotes of single stock only */
stock = AmiBroker.Stocks.Add( ticker );
/* open ASCII file */
f = fso.OpenTextFile( filename, ForReading);
/* read the file line by line */
while ( !f.AtEndOfStream )
{
r = f.ReadLine();
/* split the lines using comma as a separator
*/
fields = r.split(",");
/* parse the time from the text file */
time = new Time( fields[ 0 ] );
/* add a new quotation */
quote = stock.Quotations.Add( time.getVarTime()
);
/* put data into it */
quote.Close = parseFloat( fields[ 1 ] );
quote.Volume = parseInt( fields[ 2 ] );
}
/* refresh ticker list and windows */
AmiBroker.RefreshAll();
/* notify the user */
WScript.Echo( "Finished" );
}