AmiBroker/Win32 scripting Example to VBA / VB / VB.Net

#1
Dear All,
From the AmiBroker installation directory, I've found a script called Export.js. I've tried to convert the script to VBA (Excel), but I couldn't succeed. Kindly help me to convert the code which is mentioned below from the script file.

My intention is to connect from Excel (VBA) to AmiBroker and retrieve the quotes data (OHLC) from AmiBroker.

Kindly contribute your comments.

///////////////////////////////////////////////////////////////////////////////////
/*
** AmiBroker/Win32 scripting Example
**
** File: Export.js
** Created: Tomasz Janeczko, December 12th, 1999
** Purpose: Exports quotations to CSV file
** Language: JScript (Windows Scripting Host)
*/

function FormatFloat( number )
{
number = 0.001 * Math.round( number * 1000 );
str = number.toString();

return str.substring( 0, str.indexOf(".") + 4 );
}

var oAB = WScript.CreateObject("Broker.Application");
var fso = new ActiveXObject("Scripting.FileSystemObject");

var oStocks = oAB.Stocks;

Ticker = oAB.ActiveDocument.Name;

oStock = oStocks( Ticker );

var Qty = oStock.Quotations.Count;

WScript.Echo("Export of " + Ticker + " start" );

f = fso_OpenTextFile( Ticker + ".csv", 2, true );

f.WriteLine("$SEPARATOR ,");
f.WriteLine("$FORMAT Ticker,Date_YMD,Open,High,Low,Close,Volume")

for( i = 0; i < Qty; i++ )
{
oQuote = oStock.Quotations( i );

var oDate = new Date( oQuote.Date );

f.WriteLine( oStock.Ticker + "," +
oDate.getFullYear() + "-" + (oDate.getMonth()+1) + "-" + oDate.getDate() + "," +
FormatFloat( oQuote.Open ) + "," +
FormatFloat( oQuote.High ) + "," +
FormatFloat( oQuote.Low ) + "," +
FormatFloat( oQuote.Close ) + "," +
Math.round( oQuote.Volume ) );
}

f.Close();

WScript.Echo("Export finished" );
///////////////////////////////////////////////////////////////////////////////////
 
#2
Dear All,
From the AmiBroker installation directory, I've found a script called Export.js. I've tried to convert the script to VBA (Excel), but I couldn't succeed. Kindly help me to convert the code which is mentioned below from the script file.

My intention is to connect from Excel (VBA) to AmiBroker and retrieve the quotes data (OHLC) from AmiBroker.

Kindly contribute your comments.

///////////////////////////////////////////////////////////////////////////////////
/*
** AmiBroker/Win32 scripting Example
**
** File: Export.js
** Created: Tomasz Janeczko, December 12th, 1999
** Purpose: Exports quotations to CSV file
** Language: JScript (Windows Scripting Host)
*/

function FormatFloat( number )
{
number = 0.001 * Math.round( number * 1000 );
str = number.toString();

return str.substring( 0, str.indexOf(".") + 4 );
}

var oAB = WScript.CreateObject("Broker.Application");
var fso = new ActiveXObject("Scripting.FileSystemObject");

var oStocks = oAB.Stocks;

Ticker = oAB.ActiveDocument.Name;

oStock = oStocks( Ticker );

var Qty = oStock.Quotations.Count;

WScript.Echo("Export of " + Ticker + " start" );

f = fso_OpenTextFile( Ticker + ".csv", 2, true );

f.WriteLine("$SEPARATOR ,");
f.WriteLine("$FORMAT Ticker,Date_YMD,Open,High,Low,Close,Volume")

for( i = 0; i < Qty; i++ )
{
oQuote = oStock.Quotations( i );

var oDate = new Date( oQuote.Date );

f.WriteLine( oStock.Ticker + "," +
oDate.getFullYear() + "-" + (oDate.getMonth()+1) + "-" + oDate.getDate() + "," +
FormatFloat( oQuote.Open ) + "," +
FormatFloat( oQuote.High ) + "," +
FormatFloat( oQuote.Low ) + "," +
FormatFloat( oQuote.Close ) + "," +
Math.round( oQuote.Volume ) );
}

f.Close();

WScript.Echo("Export finished" );
///////////////////////////////////////////////////////////////////////////////////
I want to do the same as you want. HAve you got the solution to run in VBA (Excel)? please kindly share with us. thanks
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?