Chart Export via AFL - OLE

did anyone figure out a way to export charts from a floating window already? I know "you can't access floating charts via OLE because they are not MDI windows".

Would be nice though if one could export a chart just by pushing a button on a floating window. I can call the data I have in the floating window inside the docked window and then export the chart but it is a hassle because for 1 thing symbol lock should be turned off. So I support Beppe's suggestion for a native AFL function to export a chart unless there is some other way I don't know about yet. Or maybe the native function is already there and I did not notice :smile:

maybe a foolish question but I use this code @beppe posted with slight modifications for export path and export name. Works great but when I have multiple instances of Amibroker opened and drag this code for instance in a chart window of the second instance and press the "Export" button it will still export the chart in the first opened instance of Amibroker. Is there any way around this? Thanks

@empottasch, please see this previous answer of @Tomasz.

Re the "native" function, let's hope he will consider it.
Multiple users would like to export chart images. Personally, I would like to see an option to apply it complete charts or single panes.

OLE is a bit of pain for some users. I recall another post where @Tomasz wrote about the possibility of replacing it with some other way to control the application, but unfortunately, I suspect that it is not a priority.

1 Like

As I wrote, floating windows are not MDI and they are not "active" in the MDI sense, therefore if you use AB.ActiveWindow you will get MDI active window, not floating window. The thing is that Microsoft never provided a system (OS) way to have MDI in multiple monitors therefore developers have to workaround MDI limitations creating those "floating" windows that live outside Microsoft MDI framework. What I can do is to give access to that floating window from OLE and then you will be able to call ExportImage on it.


thanks for the replies. That would be great that addition to OLE. My last question however was a bit different from the the one I asked in May 2020. Today my question is unrelated to floating windows.

Today my problem was that if I open 1 instance of Amibroker then Beppes code works good. If I then open another instance of Amibroker (so I have Amibroker running twice on a single computer) then Beppes code still works (inside the second instance) but it sees the window in the first instance as the active window. So if I press the export button inside the second instance of Amibroker it exports the chart from the first instance of Amibroker.

No big issue I just wondered if I can control this from the code.

That is how Windows OLE works, CreateObject() gives you OLE dispatch interface of first running instance within given Windows user account. The only way is to run two instances in two separate Windows user accounts.

1 Like

ok thanks for your reply

That's great. I would be also interested in this feature. Currently I'm using an AFL code similar to this one:

if( some event )

	AB = CreateObject( "Broker.Application" );

    doc = AB.Documents( 3 );
    doc.Name = NewStock; // for instance "CDR"

    doc = AB.Documents( 6 );
    doc.Name = NewStock;

    doc = AB.Documents( 10 );
    doc.Name = NewStock;

... to change tickers in selected chart windows (which are usually in floating mode) to automatically synchronize them with the news coming during the session from different sources. So when a news for a stock appears, upper code automatically and instantly changes tickers in selected charts to this stock. It's very useful for an active daytrader. One of such windows is my custom trading panel which lets me quickly place an order (currently manually but shortly also in automatic mode). It works well but it is not the most robust solution, because whether automatic change of the ticker is successful in some cases depends on factors like:

  • what was the last active element - was it a chart, an analysis window or some other element
  • are the selected charts and last active element in normal or floating mode.
  • if I close or add a new chart window to my layout, upper code might synchronize wrong chart(s).

I have also tried synchronizing only one selected chart and let AmiBroker sync other selected charts using a Symbol link feature, but it needs user interraction to work as expected.

I have also noticed that when I'm connected to Statica plugin (and using such code) - after successfully changing the ticker, in some cases the ticker returnes to the previous one. It happens for instance when the last active window was in a floating mode. This problem doesn't occur when I'm working on a local database.

So summing up - currently the upper code does the job and it is very useful for me, but there are many factors which I need to take into account for the changing symbol to work properly.

If there was a way to have a direct robust access to floating windows from OLE it would probably make my solution better.

Thank you.

1 Like

FWIW: Analysis (and other non-chart windows like Account/ Web research) are NOT part of Documents collection so presence of Analysis windows does not impact Documents collection. Analysis windows are present in OTHER collection: AnalysisDocs.