How to obtain the HWND of the chart window in strategy tester?

Doerk Hilger
1789
Doerk Hilger  

Hi there,

anyone an idea? For whatever reason, the corresponding - ChartGetInteger(m_chart_id,CHART_WINDOW_HANDLE) - returns zero.

Stanislav Korotky
35822
Stanislav Korotky  
I'm afraid you can't do it directly (without a DLL). The tester is a separate process in MT5, it does not support many API features available in the terminal.
Doerk Hilger
1789
Doerk Hilger  

I know. The question is how, which functions of winuser32.dll lead to the result?

alphatrading
110
alphatrading  
Doerk Hilger:

I know. The question is how, which functions of winuser32.dll lead to the result?

Because of the many irregularities in MQL the logic differs depending on what MQL program type you call the function from. So it is different for experts, indicators and scripts.

Have a look at my code here: https://github.com/rosasurfer/mt4-expander/blob/master/src/context.cpp#L539

The function resolves the HWND of the current chart under all possible circumstances (also when WindowHandle() returns 0). Some comments are still in German but you should get the logic and already know the used functions. If it matches your skill level I can extract and simplify it a bit and write a WindowHandleEx() for you.

Then, this is MT4 not MT5. If you need the same for MT5 it will be similar but not the same. In this case I can't help, sorry.