Export advice - how to perform this without opening Automatic Analysis form

Hi Seniors,

I am running on script which provide me output of my logic, but every time when i am running this script AmiBroker "Automatic Analysis" form was opening on over the AmiBroker screen and i have to wait till complete the operation.

Need help from seniors. how and what changes i need to do in script, so i can get my output and without opening Automatic analysis form.

// Exploration_Example.js

//  This Java Script file should:
//  1. Load a Database
//  2. Run an exploration on an afl.
//  3. Exports the exploration to a csv file.

// ----------------------------------------------------------------------------
// Create AmiBroker object and get Analysis object
// ----------------------------------------------------------------------------
var AB, AA, i;

AB = new ActiveXObject("Broker.Application");
AA = AB.Analysis;

// ----------------------------------------------------------------------------
// Load Database
// ----------------------------------------------------------------------------
//AB.LoadDatabase("C:\\ValveNet Technologies\\BestRT Pro\\BestRT Pro");

// ----------------------------------------------------------------------------
// Automatic Analysis Input and Export Information
// ----------------------------------------------------------------------------
AFL_Directory = "C:\\Program Files (x86)\\AmiBroker\\";                 		// Location of AFL
AFL_ExploreFileName = "MyLogic.afl";         									// AFL program to get the data to be exported
AFL_ExploreFile = AFL_Directory + AFL_ExploreFileName;   						// Name of the above program with it's path included

Export_Directory = "C:\\Program Files (x86)\\AmiBroker\\rupee^xn\\"             // Location where Exported data will be saved
ExportFileName = "MyLogic.txt";              									// Name of export file
ExportFile = Export_Directory + ExportFileName;          						// Name of above export file with its path included

Settings_Directory = "C:\\AmiBroker\\Settings\\";
SettingsFileName = "SettingsBasic.ABS";
SettingsFile = Settings_Directory + SettingsFileName;

// ----------------------------------------------------------------------------
// Load Reference Ticker into AmiBroker
// ----------------------------------------------------------------------------
//AB.ActiveDocument.Name = "RUT-I"; // Set RUT-I as reference ticker

// ----------------------------------------------------------------------------
// Automatic Analysis - Setup Exploration using info defined above
// ----------------------------------------------------------------------------
AA.LoadSettings( SettingsFile );
AA.LoadFormula( AFL_ExploreFile );

// Use the following to tell Amibroker what to Include/Exclude and what dates to use
//
// "index", "favorite", "market", "group", "sector", "index", "watchlist"
// 0 = include; 1 = exclude
// 0 = all stocks, 1 = current stock, 2 = use filter
// 0 = all quotes, 1 = n last quotes, 2 = n last days, 3 = from-to date
//

// Set Filters
AA.ClearFilters();

//AA.Filter(0,"favorite") = 1;   		// Try this to load a long ticker which is favorites ^rut
AA.ApplyTo = 2;                   // 0 = all stocks, 1 = current stock, 2 = use filter
AA.Filter(0,"watchlist") = 01;     // 0 = Include; "watchlist" number

// Set Dates
AA.RangeMode = 3;                    // 0 = all quotes, 1 = n last quotes, 2 = n last days, 3 = from-to date
//AA.RangeN = 5000;
AA.RangeFromDate = "12/20/2018";
AA.RangeToDate = "12/20/2018";

// ----------------------------------------------------------------------------
// Run exploration, export exploration to csv file
// ----------------------------------------------------------------------------
AA.Explore();
        
AA.Export( ExportFile );

// ----------------------------------------------------------------------------
// Save database (not really needed), Refresh database (also not really needed
// and close AA window when done.
// ----------------------------------------------------------------------------
//AB.SaveDatabase();
AB.RefreshAll();

//AA.ShowWindow(0);                     // 0 = all stocks, 1 = current stock, 2 = use filter

// ----------------------------------------------------------------------------

Thank you to all.

1 Like

This appears to be a very old script and on a very old version, pre 5.50, you should check the source from where you got it.

this object is AB.Analysis is obsolete, you should instead use AB.AnalysisDoc

AnalysisDoc provides Asynchronous Run as stated in the Guide. Do check it out.

The AFL and ABS files are all part of the APX Project File for latest AA functions.

Solution Part:

  1. Open AFL file in AA window of AB, apply all the required settings and run Explore to check.

  2. With AA window as the active window, File > Save (or save as) and create the APX project file.

  3. Go here https://www.amibroker.com/guide/objects.html

  4. There is a full working example that you can copy paste into your .JS
    Example 1 at the end.

  5. Set path of file to where you saved the APX file.

  6. Then run the .JS file as you currently do.

2 Likes

Thank a lot, for guidance.
Use object feature AB.Analysis, work as per my need. But when logic repeat after 3 minute analysis.apx pane appear for 15sec and after complete same pane get closed.

Is it possible to run back ground without effecting amibroker chart.

Thank you again.

If you want to learn, you need to read the manual.
Everything cannot be laid out on a silver platter.

Open you APX in an Analysis window.
Then find which Item Number it is, if there is only one AA window, it will start from 0.
Use the correct number, this will prevent new AA window from opening and closing.

oAB = new ActiveXObject("Broker.Application");

// NewC = oAB.AnalysisDocs.Count;	// get total analysis windows

NewA = oAB.AnalysisDocs.Item(0);	// 1st analysis starts with 0
NewA.Run( 1 );

//         NewA.Close();    // DO NOT close Analysis 

It is up to you to take care and write the validation code or checks as needed.

1 Like