Hi All
Many years since I posted here, but I have just added Exploration Buttons to a custom Toolbar and thought I would consolidate my findings here. Hope it is useful.
How to add Exploration Buttons to a Toolbar
Make folder under Amibroker - Explorations
. Do a normal exploration with with all parameters set to your requirements
. Make sure the Analysis window is Normal (not Floating)
. File / Save As myexploration.apx in the Explorations folder
. Make a file in the same folder with the following name: myexploration.js. Note I have AB installed in C:\Amibroker\
myexploration.js
=======================================================================================
AB = new ActiveXObject( "Broker.Application" );
var FileName = "MyExploration" // The name of the .apx file.
try
{
NewA = AB.AnalysisDocs.Open( "c:\AmiBroker\Explorations\" + FileName + ".apx" ); // opens given analysis project file
if ( NewA )
{
NewA.Run( 1 ); // starts analysis (asynchronous - returns immediatelly
// (0-scan, 1- exploration, 2- portfolio backtest, 4- optimization, 6-walk forward)
while ( NewA.IsBusy )
WScript.Sleep( 500 ); // wait for completion
NewA.Export( "C:\\AmiBroker\\Exploration Scripts\\" + FileName + ".html" ); // Exploration results
WScript.echo( "Results are in C:\\AmiBroker\\Explorations\\" + FileName + ".html" );
// NewA.Close(); // closing analysis window // This is commented out so that the analysis window remains open and you can scroll through the tickers. Uncomment if you want the .apx to run and close automatically
}
}
catch ( exc )
{
WScript.echo( "Exception: " + exc.message );
}
=======================================================================================
. From main AB window
. Tools / Customize
. Select Toolbars if not selected (It is default)
. New
. Name of Toolbar eg "Explorations", OK
. Close Customize
. Open Tools / Customize again
. Select Tools
. New, enter the name of the Button
. In Command type the Path and filename of .js file
. eg c:\AmiBroker\Explorations\MyExploration.js
. If in error you type c:\AmiBroker\Explorations\MyExploration.apx ie extension is .APX instead of .JS Clicking the button will start a new instance of AB.
. Close to save the tool
. Open Tools / Customize again and Leave it open. When open it puts AB into a configuration mode.
. Now go to the main menu Tools. The new tool should be at the bottom of the list.
. Hold the CTRL key down and drag the tool to the Explorations Toolbar (Copies the button instead of moving it. You can run the exploration from either the Tools Menu or the Button)
. Close the Customize menu and click the new button, The exploration should run.
. If you need to to delete or change the name of a button, you need to go to the Tools / Customize menu and leave open to put AB into configuration mode Right click on the toolbar button and delete etc.
As an aside, I have a batch file to sort watch lists, external to AB. (listed below)
I number my watch lists eg "1010 ASX 100" and increment them in steps of 10 (in a similar fashion to GW Basic) etc. Allows room to slot in new watchlists without renumbering them all.
If, in your analysis, you apply a filter which includes a watch list, sorting the watch list may upset your .apx Just correct the watch list in the Apply to Filter and resave your .apx
WatchListSort.bat
=======================================================================================
Rem This sorts index.txt into alphabetical/numerical order. If all else fails delete
Rem index.txt and Amibroker will re-create it. If there are stray .tls files, delete them
Rem and also index.txt - run AB
Rem Note Must close AB before running this file
sort < c:\AmiBroker\ASX-PremiumData\WatchLists\index.txt > c:\AmiBroker\ASX-PremiumData\WatchLists\index2.txt
Copy c:\AmiBroker\ASX-PremiumData\WatchLists\index2.txt c:\AmiBroker\ASX-PremiumData\WatchLists\index.txt /Y
del c:\AmiBroker\ASX-PremiumData\WatchLists\index2.txt
=======================================================================================