Code to determine which chart is currently on top in MT4

 

Hi,

I am trying to write code which determines which chart is currently on top, in MT4.

For example, if an EA or indicator is running on a particular chart, how to determine whether the EA/indicator's chart is currently on top?

I know that you can bring chart to top: ChartSetInteger(chartID, CHART_BRING_TO_TOP, 0, true), and search through charts with ChartFirst/ChartNext to see if a chart is open or search by SymbolName() in MarketWatch to see if it is in the list, but not sure how to find out which chart is actually on top.

Currently I am considering storing current chart on top info (e.g. in file/GlobalVar) each time a chart is brought to top (e.g. ChartSetSymbolPeriod), but even that is insufficient since changing charts with the chart tab button (CHARTEVENT_CHART_CHANGE event handling) does not provide which chart is being switched to.

Hopefully I am just overlooking something.

Any suggestions on how to do this would be very much appreciated?

Thanks,

Al

 
albry:

I am trying to write code which determines which chart is currently on top, in MT4.

Please see the following pages for useful information and easy to understand examples.

https://docs.mql4.com/chart_operations/windowhandle

https://docs.mql4.com/chart_operations/windowfind


Please see this page for useful information about chart functions.

https://docs.mql4.com/chart_operations

- Jack

WindowHandle - Chart Operations - MQL4 Reference
WindowHandle - Chart Operations - MQL4 Reference
  • docs.mql4.com
Returns the system handle of the chart window. If the chart of symbol and timeframe has not been opened by the moment of function calling, 0 will be returned.
 
Jack Thomas:

Please see the following pages for useful information and easy to understand examples.

https://docs.mql4.com/chart_operations/windowhandle

https://docs.mql4.com/chart_operations/windowfind


Please see this page for useful information about chart functions.

https://docs.mql4.com/chart_operations

- Jack

Hi Jack,


The links are much appreciated, but I did go through all of those and I could not find any way to determine which chart is on top, i.e. not just open but open AND on top of all other charts.

Like I said, if I am overlooking something, it would be great to be pointed to the specific routine or set of routines that I could use to determine which chart is on top.

I have also looked through other stuff (like WinUser32)  but only referred to the MT4 stuff above that seemed most relevant.

Thanks

Al

 

You can use:

ChartGetInteger(chart_id, CHART_IS_MAXIMIZED);

https://www.mql5.com/en/docs/constants/chartconstants/charts_samples#chart_is_maximized


In addition, you can also bring to top the chart you want:

ChartSetInteger(chart_id, CHART_BRING_TO_TOP, true);

https://www.mql5.com/en/docs/constants/chartconstants/charts_samples#chart_bring_to_top


Regards.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Examples of Working with the Chart
Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Examples of Working with the Chart
  • www.mql5.com
This section contains examples of working with chart properties. One or two complete functions are displayed for each property. These functions allow setting/receiving the value of the property. These functions can be used "as is" in custom mql5 applications. The screenshot below demonstrates the graphic panel illustrating how changing of the...
 

Hi Jose,


YES, the CHART_IS_MAXIMIZED parameter works, i.e. ChartGetInteger(ChartID(),CHART_IS_MAXIMIZED,0,value); I hadn't noticed this parameter in MQL4, so just had a look and foundit  in MQL5. The description of what maximized vs minimized is pretty unclear however, so I guess that it could mean on top vs not on top.


Coincidentally, I was trying out different things in MT4 and WinUser and I found that MQL4 seems to have implemented (undocumented) ChartGetInteger for CHART_BRING_TO_TOP parameter, i.e. ChartGetInteger(ChartID(),CHART_BRING_TO_TOP,0,value) ALSO works. I should have just tried this out a LONG time ago, as I have spent way too many hours on this now.


I have tested both CHART_IS_MAXIMIZED and CHART_BRING_TO_TOP for EAs and indicators in main window and subwindows, in OnTimer and onTick and all these combinations return the correct values for both parameters when the chart is on top vs when not on top.


So now I have 2 choices :)  Thanks very much for pointing this out !!

Al

 
albry:

Hi Jose,


YES, the CHART_IS_MAXIMIZED parameter works, i.e. ChartGetInteger(ChartID(),CHART_IS_MAXIMIZED,0,value); I hadn't noticed this parameter in MQL4, so just had a look and foundit  in MQL5. The description of what maximized vs minimized is pretty unclear however, so I guess that it could mean on top vs not on top.


Coincidentally, I was trying out different things in MT4 and WinUser and I found that MQL4 seems to have implemented (undocumented) ChartGetInteger for CHART_BRING_TO_TOP parameter, i.e. ChartGetInteger(ChartID(),CHART_BRING_TO_TOP,0,value) ALSO works. I should have just tried this out a LONG time ago, as I have spent way too many hours on this now.


I have tested both CHART_IS_MAXIMIZED and CHART_BRING_TO_TOP for EAs and indicators in main window and subwindows, in OnTimer and onTick and all these combinations return the correct values for both parameters when the chart is on top vs when not on top.


So now I have 2 choices :)  Thanks very much for pointing this out !!

Al


You are welcome. 

Just add that CHART_IS_MAXIMIZED is only valid for mql5. I mentioned it because the question is made in the forums of mql5 and therefore it is supposed to be relative to mql5. The issues related to MT4 and mql4 should go to their specific section in the forum:  https://www.mql5.com/en/forum/mql4


CHART_BRING_TO_TOP works on both mql4 and mql5.

Regards.

Reason: