How to detect when a MDI Tab is visible


How can I detect when a MDI Tab (chart) is visible?

I am using RequestTimedRefresh to run the script in case the chart is invisible. But when the chart is visible, I only want it to run when a new bar/tick appears. Not because of the RequestTimedRefresh.

The only relative information I found is here:

Status("action") will always return actionIndicator and Status("actionex") will either return actionExInterpret (when chart pane has focus and intepretation window is visible) or actionIndicator otherwise (when pane does not have focus or interpretation is NOT visible). Be careful NOT to disable Plot() depending on Status("actionex") code. If you really think you need to execute Plot() conditionally you should only check for Status("action")==actionIndicator.

I tested a chart (indicator) with maximized/minimized and Focus/noFocus. The status code of the above is always 1.

From what I understand, there is no way to check if a window has the focus.

@bobptz From my point of view, you usually tend to unnecessary overcomplicate things...

The simplest solution (I'm not saying the best) would be entering 0 (zero) in Tools --> Preferences --> Intraday --> Realtime chart refresh interval. I quote from:

Realtime chart refresh interval - defines interval between automatic chart refreshes in real-time mode.
New in 4.90 : To enable 'every tick' chart refresh in Professional Edition, go to Tools->Preferences, Intraday tab and enter ZERO (0) into "Intraday chart refresh interval" field. (note Standard Edition won't allow to do that).

Once you enter zero, AmiBroker will refresh all charts with every new trade arriving provided that the formulas you use execute fast enough...

If you are determined enough, you might try using OLE ( Application's Properties: ActiveWindow As Object, Visible As Integer), or experiment with Status("actionex"), but the real question is why? I don't see a good reason...

If you want your charts to be executed when they are invisible/minimized, you need to use: RequestTimedRefresh(interval, onlyvisible = False) anyway. For this reason I suggest making a 2 in 1 solution - a very light core code which can be executed as often as it needs to be without causing any noticable CPU overhead, with some additional (heavier) parts of the code executed only conditionally.


Hello @Milosz

I don't know how to use OLE.

I did experiment with Status("actionex"), I could not find a contition that serves my needs.

I am already using this:
RequestTimedRefresh(interval, onlyvisible = False)

The reason I need this:
When the window is NOT visible, the RequestTimedRefresh forces it to execute every 1 sec. This is good. When the chart IS visible, the chart executes in every tick, like a normal chart. So I do not want to put the extra burden on the CPU, to have the extra execution every 1sec because of the RequestTimedRefresh. Am I doing something wrong here?

Anyway, even for purely educational reasons, I'd like to know how can I detect that a window is or is not visible. From what I understand there is no way.

Wait, if in realtime (this is where I need it), AB will update ALL CHARTS (and not just the visible ones), then my problem is solved and I do not really need the Requesttimedrefresh. I will need to test this.

So Requesttimedrefresh has no place in the realtime?

No, as I wrote above:

... even when you enter 0 (zero) in Tools --> Preferences --> Intraday --> Realtime chart refresh interval. It is all described here:

Using my suggested solution + status( ''redrawaction'' ) - which returns 0 (zero) for regular refreshes, and 1 for refreshes triggered via RequestTimedRefresh(), you are able to execute selected parts of the code for instance only every n seconds or only when a new bar appears.

I have never needed to be able to detect if a window is minimized or not, because if I need to force additional refreshes in my code, I can turn this part of the code on/off manually (via params or gui buttons) or it happens automatically depending on the time of the day etc. For example:



Anyway you might ask Tomasz, what is the best way of detecting if a window is visible or not.


As mentioned in this thread - invisible window does not receive refreshes unless RequestTimedRefresh() with onlyvisible set to false is called. There are no other methods to distinguish that unless you write your own plugin and use functions like IsWindowVisible(). It is Windows thing. Windows message WM_PAINT isn't sent to invisible windows.

1 Like

Thank you both @Tomasz and @Milosz.