Hi Mike (and anyone else wanting this),
It can be done. Took some hunting, but, here's two options...
(And unfortunately I lost the links to the bits and pieces to derive this, so
I'm leaving a bunch of extraneous comments and code in case one cares to
backtrack.)
Odd Tidbit:
AA.Export( reportname ) will change what it writes based upon the filename
extension (eg. .HTML, .CSV, and probably others?) Be warned, it also does not
export the full list of items shown in the AA results window.
The AB object model is poorly documented, but seems pretty robust, so just keep
trying variants until it does what you want.
And there's probably a better way to get this done, but this works, so I
stopped exploring.
Best All,
Michael
/*****************************
*
* 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
AFLFolder = "E:\\AmiBroker\\afl";
//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;
AD = AB.Documents;
AA.LoadFormula("E:\\AmiBroker\\myScripts\\firstSystem3.afl");
filename = "E:\\AmiBroker\\Reports\\firstSystem3.log";
/* 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
//Analysis.ApplyTo - defines apply to mode: 0 - all stocks, 1 - current stock,
2 - use filter
AA.ApplyTo = 1; // current stock
//AA.Filter(0,"watchlist") = 1 /* watch list number */;
// AA.Filter(0,"group") = 0 /* group number */;
// Then Pick one option from below
==========================
Option one (loop through all stocks)
==========================
var oStocks = AB.Stocks;
var Qty = oStocks.Count;
// If you have ~~~EQUITY (etc.) use this
//Qty = Qty - 1 ; // remove ~~~EQUITY, increase for other ~~fields
for( i = 0; i < Qty; i++ )
{
oStock = oStocks( i );
var ticker = oStock.Ticker;
AD.Open(ticker)
reportname = filename.substr( 0, filename.length - 4 ) + ticker + ".CSV" ;
AA.Optimize(Type = 2 ); //- runs optimization
AA.Export( reportname );
}
==========================
Option two (no looping)
==========================
var ticker = "ABC";
AD.Open(ticker);
reportname = filename.substr( 0, filename.length - 4 ) + ticker + ".CSV" ;
AA.Optimize(Type = 2 ); //- runs optimization
AA.Export( reportname );
AD.Close();
var ticker = "DEF";
AD.Open(ticker);
reportname = filename.substr( 0, filename.length - 4 ) + ticker + ".CSV" ;
AA.Optimize(Type = 2 ); //- runs optimization
AA.Export( reportname );
AD.Close();
...
var ticker = "XYZ";
AD.Open(ticker);
reportname = filename.substr( 0, filename.length - 4 ) + ticker + ".CSV" ;
AA.Optimize(Type = 2 ); //- runs optimization
AA.Export( reportname );
// Note no Close() on last run as it generally closes out your last chart.