Automation Object Model

NOTE: OLE Automation interface is supported only in Windows version of AmiBroker. Amiga version provides the same functionality via ARexx Interface.

Applies to AmiBroker/Win32 version 3.25 and above. Document covers versions upto 4.30.

AmiBroker object model hierarchy

Document

properties:

methods:

Application

properties:

methods:

Stock

properties:

methods:

(none)

NOTE:
Added with version 3.70:
WatchListBits (long) - each bit 0..31 represents assignment to one of 32 watch lists to add a stock to nth watch list write (JScript example):
Stock.WatchListBits |= 1 << nth;

WatchListBits2 (long) - each bit 0..31 represents assignment to one of watch lists numbered from 32..63 to add a stock to nth watch list write (JScript example):
Stock.WatchListBits2 |= 1 << ( nth - 32 );

DataSource ( 0 - default, 1 - local only )
DataLocalMode ( 0 - default, 1 - store locally, 2 - don't store locally)

Quotation

properties:

methods:

(none)

Stocks (collection)

properties:

methods:

Quotations (collection)

properties:

methods:

Documents (collection)

properties:

methods:

 

Classes added in AmiBroker 3.30

Market

properties:

methods:

(none)

ADQuotation

properties:

methods:

(none)

ADQuotations (collection)

properties:

methods:

Markets (collection)

properties:

methods:

NEW in AmiBroker version 4.30:

new method in Quotations collection for faster retrieval of quotes
long Retrieve( long Count, Variant *Date, Variant *Open, Variant *High, Variant *Low, Variant *Close, Variant *Volume, Variant *OpenInt );

new property Broker.Application.DatabasePath
new method: Broker.Application.LoadDatabase( Path )
new method: Broker.Application.SaveDatabase()

Example VBScript code (Windows Scripting Host):

Set oAB = CreateObject("Broker.Application")

WScript.Echo( "Current path to database is " + oAB.DatabasePath )

if oAB.LoadDatabase("c:\program files\amibroker\data") = True then
WScript.Echo( "succesfully loaded new database" )
end if

WScript.Echo( "Current path to database is " + oAB.DatabasePath )

oAB.SaveDatabase()

New Analysis object.

Analysis object (accessible via Broker.Application.Analysis)

Methods:
- Backtest(); - runs backtest
- Explore(); - runs exploration
- Scan(); - runs scan
- Optimize(); - runs optimization
- bool Report( FileName: String ) - saves report to the file or displays it if FileName = ""
- bool Export( FileName: String ) - exports result list to CSV file
- bool LoadFormula( FileName: String ) - loads AFL formula
- bool SaveFormula( FileName: String ) - saves AFL formula
- bool LoadSettings( FileName: String ) - loads backtest settings
- bool SaveSettings( FileName: String ) - saves backtest settings
- ClearFilters() - removes all filters

Properties:
- long ApplyTo - defines apply to mode: 0 - all stocks, 1 - current stock, 2 - use filter
- long RangeMode - defines range mode: 0 - all quotes, 1 - n last quotes, 2 - n last days, 3 - from-to date
- long RangeN - defines N (number of bars/days to backtest)
- DATE RangeFromDate - defines "From" date
- DATE RangeToDate - defines "To" date
- Filter( nType: short, Category : String ) - sets/retrieves filter setting
nType argument defines type of filter 0 - include, 1 - exclude
Category argument defines filter category:
"index", "favorite", "market", "group", "sector", "index", "watchlist"

Examples

ClearFilters(); // clear all filters first
Filter( 0, "index" ) = 1; // include only indices
Filter( 1, "market" ) = 2; // exclude 2nd market


Full Example for Windows Scripting Host:
========================================



Example 2: Batch backtesting

Caution: It will run backtest of EVERY formula stored in C:\Program Files\AmiBroker\AFL
on all symbols of current database. After each backtest the report is generated and saved
into the file named <formula name>.HTML.

You can modify this AFL path in the script itself (you can open it with Notepad).

Below comes the listing.

/*****************************
*
* BatchTest.js
*
* Batch testing sample script
* Shows how to use JScript and new AmiBroker 4.23
* 'Analysis' object to perform batch backtesting
* and generate reports
*
* Created: Dec 21, 2002 TJ
* Last modification: Dec 22, 2002 TJ
*
* Copyright (C)2002 Amibroker.com
*
* Status: Freeware
* You can use/modify/adopt this code freely
*
*/
 
/* The directory where AFL files are stored
** Also reports generated by the bactest
** will be saved here
*/

AFLFolder = "C:\\Program Files\\AmiBroker\\AFL"; // MODIFY TO FIT YOUR SETUP
 
WScript.Echo("Batch testing of all AFL files stored in " + AFLFolder );
 
var AB, AA;
var fso, f, f1, fc, s;
var filename;
 
/* Create AmiBroker object and get Analysis object */
 
AB = new ActiveXObject("Broker.Application");
AA = AB.Analysis;
 
/* backtest over symbols and all quotes*/
AA.ClearFilters();
AA.ApplyTo = 0; // use symbols
AA.RangeMode = 0; // all quotes
 
/* to use filters you should uncomment lines below
 
// AA.ApplyTo = 2; // use filters
// AA.Filter(0,"watchlist") = 2 /* watch list number */;
// AA.Filter(0,"group") = 0 /* group number */;
 

/* Create FileSystemObject */
fso = new ActiveXObject("Scripting.FileSystemObject");
 
/* Iterate through all files in the folder */
f = fso.GetFolder(AFLFolder);
fc = new Enumerator(f.files);
for (; !fc.atEnd(); fc.moveNext())
{
    // we need to add empty string to make sure that filename is a string object
    filename = "" + fc.item(); 
 
 /* check the AFL extension */
  if( filename.substr( filename.length - 4 ).toUpperCase() == ".AFL" )
  {  
   if( AA.LoadFormula( filename ) )
   {
    AA.Backtest();
 
   reportname = filename.substr( 0, filename.length - 3 ) + "HTML" ;
 
    AA.Report( reportname ); // generate report
   }
  }
}
 
WScript.Echo("Batch backtest finished");