|
AmiBroker object model hierarchy. V5.00 |
|
|
Properties:
- Date As Date
- AdvIssues As Long
- AdvVolume As Single
- DecIssues As Long
- DecVolume As Single
- UncIssues As Long
- UncVolume As Single
Description:
ADQuotation class keeps one bar of advance/decline information
Methods:
- Function Add(ByVal Date As Variant) As Object
- Function Remove(ByVal Date As Variant) As Boolean
Properties:
- Item(ByVal Date As Variant) As Object [r/o] [default]
- Count As Long
Description:
ADQuotations is a collection of ADQuotation objects
Properties:
- Property Filter(ByVal nType As Integer, ByVal pszCategory As String) As Long [r/w]
Methods:
- Sub Backtest([ByVal Type As Variant])
- Sub ClearFilters()
- Sub Edit([ByVal bForceReload As Variant])
- Sub Explore()
- Function Export(ByVal pszFileName As String) As Boolean
- Function LoadFormula(ByVal FileName As String) As Boolean
- Function LoadSettings(ByVal pszFileName As String) As Boolean
- Sub MoveWindow(ByVal Left As Long, ByVal Top As Long, ByVal Width As Long, ByVal Height As Long)
- Sub Optimize([ByVal Type As Variant])
- Function Report(ByVal pszFileName As String) As Boolean
- Function SaveFormula(ByVal pszFileName As String) As Boolean
- Function SaveSettings(ByVal pszFileName As String) As Boolean
- Sub Scan()
- Sub ShowWindow(ByVal nShowCmd As Long)
- Sub SortByColumn(ByVal iColumn As Long, ByVal bAscending As Integer, ByVal bMultiMode As Integer)
Properties:
- RangeMode As Long
- RangeN As Long
- RangeFromDate As Date
- RangeToDate As Date
- ApplyTo As Long
Description:
Analysis object provides programmatic control of automatic analysis window
Notes:
Analysis.Backtest( Type = 2 ); - runs backtest
Type parameter can be one of the following values:
0 : portfolio backtest/optimize
1 : individual backtest/optimize
2 : old backtest/optimizeAnalysis.Optimize(Type = 2 ); - runs optimization
Type parameter can be one of the following values:
0 : portfolio backtest/optimize
1 : individual backtest/optimize
2 : old backtest/optimizeAnalysis.Report( FileName: String ) - saves report to the file or displays it if FileName = ""
Analysis.ApplyTo - defines apply to mode: 0 - all stocks, 1 - current stock, 2 - use filter
Analysis.RangeMode - defines range mode: 0 - all quotes, 1 - n last quotes, 2 - n last days, 3 - from-to date
Analysis.RangeN - defines N (number of bars/days to backtest)
Analysis.RangeFromDate - defines "From" date
Analysis.RangeToDate - defines "To" date
Analysis.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"
Methods:
- Function Import(ByVal Type As Integer, ByVal FileName As String, [ByVal DefFileName As Variant]) As Long
- Function LoadDatabase(ByVal Path As String) As Boolean
- Function LoadLayout(ByVal pszFileName As String) As Boolean
- Function Log(ByVal Action As Integer) As Long
- Sub Quit()
- Sub RefreshAll()
- Sub SaveDatabase()
- Function SaveLayout(ByVal pszFileName As String) As Boolean
Properties:
- ActiveDocument As Object
- Stocks As Object
- Version As String
- Documents As Object
- Markets As Object
- DatabasePath As String
- Analysis As Object
- Commentary As Object
- ActiveWindow As Object
- Visible As Integer
Description:
Application object is main OLE automation object for AmiBroker. You have to create it prior to accesing any other objects. To create Application object use the following code:
JScript:
AB = new ActiveXObject("Broker.Application");
VB/VBScript:
AB = CreateObject("Broker.Application")
AFL:
AB = CreateObject("Broker.Application");
Methods:
- Sub Activate()
- Sub Close()
- Function ExportImage(ByVal FileName As String, [ByVal Width As Variant], [ByVal Height As Variant], [ByVal Depth As Variant]) As Boolean
- Function LoadTemplate(ByVal lpszFileName As String) As Boolean
- Function SaveTemplate(ByVal lpszFileName As String) As Boolean
- Function ZoomToRange(ByVal From As Variant, ByVal To As Variant) As Boolean
Properties:
- SelectedTab As Long
- Document As Object
Description:
Window object provides programmatic control over charting window.
Methods:
- Function Add() As Object
Properties:
- Item(ByVal Index As Long) As Object [r/o] [default]
- Count As Long
Description:
Windows is a collection of Window objects.
Methods:
- Sub Apply()
- Sub Close()
- Function LoadFormula(ByVal pszFileName As String) As Boolean
- Function Save(ByVal pszFileName As String) As Boolean
- Function SaveFormula(ByVal pszFileName As String) As Boolean
Description:
Commentary object gives programmatic control over guru commentary window.
Methods:
- Sub Activate()
- Sub Close()
- Sub ShowMessage(ByVal Text As String)
Properties:
- Application As Object
- Parent As Object
- Name As String
- ActiveWindow As Object
- Windows As Object
Description:
Document object represents active document (of 'chart' type). In document-view architecture each document can have multiple windows (views) connected. Name property defines currently selected symbol for the document.
Methods:
- Function Add() As Object
- Sub Close()
- Function Open(ByVal Ticker As String) As Object
Properties:
- Item(ByVal Index As Long) As Object [r/o] [default]
- Count As Long
- Application As Object
- Parent As Object
Description:
Documents is a collection of document objects.
Properties:
- Name As String
- ADQuotations As Object
Description:
Market represents market category and its related data (i.e. per-market advance/decline information)
Properties:
- Item(ByVal Index As Integer) As Object [r/o] [default]
- Count As Integer
Description:
Markets is a collection of Market objects
Properties:
- Date As Date
- Close As Single
- Open As Single
- High As Single
- Low As Single
- Volume As Single
- OpenInt As Single
Description:
Quotation class represents one bar of price data
Methods:
- Function Add(ByVal Date As Date) As Object
- Function Remove(ByVal Item As Variant) As Boolean
- Function Retrieve(ByVal Count As Long, ByRef Date As Variant, ByRef Open As Variant, ByRef High As Variant, ByRef Low As Variant, ByRef Close As Variant, ByRef Volume As Variant, ByRef OpenInt As Variant) As Long
Properties:
- Item(ByVal Item As Variant) As Object [r/o] [default]
- Count As Long
Description:
Quotations is a collection of Quotation objects. It represents all quotations available for given symbol. Quotations collection is available as a property of Stock object.
Properties:
- Ticker As String
- Quotations As Object
- FullName As String
- Index As Boolean
- Favourite As Boolean
- Continuous As Boolean
- MarketID As Long
- GroupID As Long
- Beta As Single
- SharesOut As Single
- BookValuePerShare As Single
- SharesFloat As Single
- Address As String
- WebID As String
- Alias As String
- IsDirty As Boolean
- IndustryID As Long
- WatchListBits As Long
- DataSource As Long
- DataLocalMode As Long
- PointValue As Single
- MarginDeposit As Single
- RoundLotSize As Single
- TickSize As Single
- WatchListBits2 As Long
- Currency As String
- LastSplitFactor As String
- LastSplitDate As Date
- DividendPerShare As Single
- DividendPayDate As Date
- ExDividendDate As Date
- PEGRatio As Single
- ProfitMargin As Single
- OperatingMargin As Single
- OneYearTargetPrice As Single
- ReturnOnAssets As Single
- ReturnOnEquity As Single
- QtrlyRevenueGrowth As Single
- GrossProfitPerShare As Single
- SalesPerShare As Single
- EBITDAPerShare As Single
- QtrlyEarningsGrowth As Single
- InsiderHoldPercent As Single
- InstitutionHoldPercent As Single
- SharesShort As Single
- SharesShortPrevMonth As Single
- ForwardDividendPerShare As Single
- ForwardEPS As Single
- EPS As Single
- EPSEstCurrentYear As Single
- EPSEstNextYear As Single
- EPSEstNextQuarter As Single
- OperatingCashFlow As Single
- LeveredFreeCashFlow As Single
Description:
Stock class represents single symbol data. For historical reasons the name of the object is Stock, but it can hold any kind of instrument (including futures, forex, etc).
Methods:
- Function Add(ByVal Ticker As String) As Object
- Function GetTickerList(ByVal nType As Long) As String
- Function Remove(ByVal Item As Variant) As Boolean
Properties:
- Item(ByVal Item As Variant) As Object [r/o] [default]
- Count As Long
Description:
Stocks is a collection of Stock objects. It is available as a property of Application object.
Notes:
Stock.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;
Stock.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 );
Stock.DataSource ( 0 - default, 1 - local only )
Stock.DataLocalMode ( 0 - default, 1 - store locally, 2 - don't store locally)
Example 1: Running simple backtest
/* 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;
// uncomment line below to
// AA.Filter( 1, "market" ) = 2; // exclude 2nd market
/* 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.
/*****************************
*
* 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
}
}
}Example 3: Execute commentary
AB = new ActiveXObject("Broker.Application");
AB.Commentary.LoadFormula("C:\\Program Files\\AmiBroker\\AFL\\MACD_c.afl");
AB.Commentary.Apply();
AB.Commentary.Save("Test.txt");
AB.Commentary.SaveFormula("MACDTest.afl");
//AB.Commentary.Close();