Workflow to Save and Open last session

Hi all,
I'm trying to develop a workflow and shortcut commands for saving and opening last session that includes chart and analysis windows.

For this, need to create 2 javascript files:
1st javascript file: I'm using this javascript code which I've found online to open a user specified layout and analysis file

//http://ask.amibroker.org/index.php?qa=179&qa_1=how-do-i-save-the-workspace-including-the-analysis-window

// I need to open Amibroker first, then execute this script

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

// close any open charts in Amibroker.
docs = ab.Documents() ;
docs.close() ; 

// close any open AA in Amibroker.
adocs = ab.AnalysisDocs() ; 
adocs.close();

ab.loadLayout ( "C:\\Program Files\\AmiBroker\\IntradayUpdateDB\\Layouts\\Default.awl");
ab.AnalysisDocs.Open( "C:\\Program Files\\AmiBroker\\My Analysis\\SystemBuild\\ EMA System.apx" ); 
ab.AnalysisDocs.Open( "C:\\Program Files\\AmiBroker\\My Analysis\\DAILY SCAN\\BTST.apx" ); 

Then I create a command shortcut in the menu bar to call this javascript and it works. All charts from my last session and the analysis files listed above are opened.
AB%20open%20last%20session%20shortcut

I just need some guide to create the 2nd javascript file to identified and list all the current opened charts and analysis windows (Later can create another Menu shortcut "Save This Session" and link to this 2nd javascript file). Later this list can be used to update the 1st javascript (so user can re-open this chart and analysis windows).

Appreciate comments and advice on this.

Also, it would be awesome if the experienced can share on how you guys track working sessions.

thanks!

1 Like

Hi all,
Is there a way to get the list of the opened analysis .apx files in Amibroker and assign this to a variable via JS? I have looked into the AB object model documentation but could not find any info about this.
Any advice is appreciated.

Thanks.

Hello @bursaware

I see, you have already done some research and probably came across these threads in which very similar issues have been discussed:


Although I'm using jscripts and OLE, I'm definitely not an expert in this field - but I think it is not possible to retrieve (using OLE) names and paths to all open Analysis windows (not just number of all open AA windows). That would allow keeping track and updating this jscript file which opens all recently used AA windows after AB restart. If I'm wrong I would appreciate correcting me and showing an example code.

For this reason, currently I don't see a better option than opening apx files and rearranging them on the screen(s) manually (or using jscript + OLE just to open them) after each AB restart. Of course you can make a shortcut in the menu bar to the Recent Files. For me the biggest problem is not opening those apx files, but rearranging them manually on my monitors before each session. These repetitive tasks unnecessarily take time every single day.

As I wrote in another thread, I know, there could be also some disadvantages of saving AA Windows in the Layouts, but if that is the case, there is probably another way of achieving that - for example some additional/optional layouts only for AA Windows. Another awaited feature is implementing Analysis windows’ unique IDs - that would make possibe using separate Parameters for each AA window.

If you (or for example @travick) are interested in implementing these features, you can upvote Issue #2653 - Save AA Window in Layout in the Feedback Centre. It's current status is "put on hold" - so there is a chance it might be implemented in the future...

2 Likes

For now I use AutoIt to run AB and load the layout.

My single screen setup has small left pane with Symbols window, 2 charts and 2 analysis windows on the right forming a 4 tile Layout.

Problem with OLE afaik, is that there is no way of pre-determining the order of analysis windows if already open.

using COM.open() and COM.close() from OLE is annoying as it creates new Analysis window and closes it. If you run it every few mins its not workable.

I open my Analysis windows in specific order, so the array returned is always the same, and limited to COM.Count.

If we can open a .APX file from an already open Analysis window, I think a lot of work can be saved.
Then TJ may just need save the positioning of Analysis windows in Layout.

Once Layout is loaded, the blank Analysis windows can re-open the specific .APX.

Obviously, easier said than done, but TJ i'm sure knows the best way.
Also, would love some more properties and methods exposed in COM :smiley:

2 Likes

Thanks @Milosz for the thread reference, tried to find related topic but couldn't find the best keywords.
I have the feeling that it's not possible to retrieve names and path of all open analysis windows based on the OLE documentation.
Good idea on using Recent Files. Will have a look at it.

thanks.

Thanks @travick for sharing your setup. I got your point, having the ability to track the order of analysis windows is crucial for a practical automated windows loading.
I guess, until there's a better way, for the time being I'll just stick to the manual way of updating my JS script to store the important analysis.apx file for loading in the next session.

thanks heaps!

There are many ways of opening apx files from AmiBroker. A few examples:

  1. File --> Open --> *.apx
  2. Creating a shortcut to the Recent Files or/and Recent Formulas in the main menu bar. An example here:
  1. Creating shortcuts (also in a form of small icons) in the main menu bar to Custom tool items (https://www.amibroker.com/guide/w_customize.html). They allow to easily run external programs or scripts. Starting from AB 6.29 you can have up to 20 custom tool items.
  2. Using Gui Buttons. Each button can run one or more external scripts via ShellExecute(). You can even create a kind of a custom "control panel" in a separate chart, with a set Gui buttons and some additional controls.

Examples of point 3 and 4 are here:

  1. Running batch files (https://www.amibroker.com/guide/h_batch.html) from AFL (indicator or another AA window) or using external scripts.
  2. etc...

http://www.amibroker.com/kb/2015/01/12/ole-automation-scripts-with-32-and-64-bit/
https://www.amibroker.com/guide/h_batch.html

1 Like

Thanks @Milosz, for now I will settle with the shortcut to the recent files and formula.. Thanks for the tips and links to @fxshrat answers.

1 Like