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:
- Application : object
- Parent : object
- Name : string
methods:
- ShowMessage(Text : string)
- Close()
- Activate()
Application
properties:
- ActiveDocument : object
- Stocks : object (collection)
- Version : string
- Documents : object (collection)
methods:
- Quit()
- RefreshAll()
- Import(Type : number, FileName : string, [optional] DefFileName : string ) : long
- Log(Action : number) (*new in 3.42)
(Action = 0 - delete import log, 1 - display import.log, 2- ask the user and display import.log)
Stock
properties:
- Ticker : string
- Quotations : object (collection)
- FullName : string
- Index : boolean
- Favourite : boolean
- Continuous : boolean
- IndustryID : number - (*new in 3.40)
- MarketID : number
- GroupID : number
- WatchListBits : number (*new in 3.70) - SEE NOTE
- WatchListBits2 : number (*new in 3.70) - SEE NOTE
- Code : number
- Issue : number
- BookValue : number
- NominalValue : float
- Address : string
- Alias : string
- WebID : string (*new in 3.30)
- FinanceYear( number Quarter ) : number
- FinanceIncome( number Quarter ) : number
- FinanceEBT( number Quarter ) : number
- FinanceEAT( number Quarter ) : number
- IsDirty : boolean - (*new in 3.40)
- DataSource : number- (*new in 3.90)
- DataLocalMode : number- (*new in 3.90)
- MarginDeposit : number- (*new in 4.10)
- PointValue : number- (*new in 4.10)
- RoundLotSize : number- (*new in 4.10)
- TickSize : number- (*new in 4.10)
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:
- Date : datetime
- Close : float
- Open : float
- High : float
- Low : float
- Volume : float
- OpenInt : float - (*new in 3.40)
methods:
(none)
Stocks (collection)
properties:
- Count : number
methods:
- Add( Ticker : string ) : object
- Item( Item : string or number) : object
- Remove( Item : string or number ) : boolean
- GetTickerList( Type: number ) : string (new in 4.00) (Type is reserved for the future, set it to zero)
Quotations (collection)
properties:
- Count : number
methods:
- Add( DateTime: string ) : object
- Item( Item : string or number) : object
- Remove( Item : string or number ) : boolean
Documents (collection)
properties:
- Count : number
- Application : object
- Parent : object
methods:
- Item( Index : number) : object
- Add() : object
- Close()
- Open( Ticker : string) : object
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:
========================================
/* create AB object */
AB = new ActiveXObject("Broker.Application");
/* retrieve automatic analysis object */
AA = AB.Analysis;
/* load formula from external file */
AA.LoadFormula("afl\\macd_c.afl");
/* optional: load settings */
// AA.LoadSettings("the_path_to_the_settings_file.abs");
/* setup filters */
/* backtest over symbols present in market 0 only (zero-based number) */
AA.ClearFilters();
AA.Filter( 0, "market" ) = 0;
/* set apply to and range */
AA.ApplyTo = 2; // use filters
AA.RangeMode = 0; // use all available quotes
/* run backtest and display report */
AA.Backtest();
AA.Report(""); // empty file name means display report
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.