Warning 503 Using OLE/CreateObject

I want to use the code below to zoom to my user defined range. When I use Verify syntax a warning 503 message pops up that using OLE/CreateObject is not multi-threading friendly (I have the multi-threaded charts execution box checked in AFL preferences). Despite the warning, the code is correctly applied to a chart most of the time, but it can be quirky and sometimes doesn’t have any effect at all. Is there a code change that can be made to eliminate the warning or to ensure that it will more reliably zoom to a range as intended? Appreciate any helpful thoughts on this.


_SECTION_BEGIN("Zoom"); //Multi Date Range Setup
AB = CreateObject("Broker.Application");
AW = AB.ActiveWindow;
startDate = ParamDate("StartDate","01/01/2000",1);
endDate = ParamDate("EndDate","12/31/2016",1);
trigger = ParamTrigger("Trigger","Zoom In");
if (trigger) AW.ZoomToRange(startDate,endDate);

OLE automation interface is provided to control AmiBroker from the outside script, not from within AFL formula.

You can’t get rid of the warning because it is for a reason - you should NOT be using OLE from within AmiBroker because you are likely to create implict infinite loops.

For example zooming causes refresh, refresh means code execution which in turns causes another refresh and another execution -> infinite loop. Just for the reason that many users abused OLE interface that way while being unaware of consequences AmiBroker has internal protections that break out of such infinite loop by IGNORING certain calls in certain situations (when you call too often).

1 Like

Thank you for your response and explanation of why the warning occurs. I have read and re-read the section “Efficient use of multithreading” in the Amibroker manual which talks about avoiding the use of OLE/CreateObject. Unfortunately, as someone with a limited programming background, I was not able to determine what changes need to be made in order to eliminate the 503 warning. I would welcome any suggestions for code revisions that would still provide the ZoomToRange functionality and be in compliance with AFL best practices.


Since none of the older zoom functions (UKB and Library) don’t work anymore from inside an indicator formula is there any other way to find and zoom to events on a chart?

To step through signals on the chart is a great time saver when you want to inspect trades and design entries/exits.

Best regards,

All “older” code continue to work. As I wrote many times, Warning is NOT an error. It does NOT prevent formula from running.

Thank you,

I apologize and stand corrected. I earlier tried two different programs and
they didn’t work, I also had someone else confirm it didn’t work before

Now that I tried again it worked… not sure what we did wrong. One of
those gremlins…

Have a great day!

This morning zoom functions didn’t work again. After some searching I found an extra invisible instance of Amibroker running. Not sure how this happened, perhaps because sometimes I run two instances of AB. Closing both and relaunching AB the zoom functions worked fine.