I tried a little indicator to see if it would tell me anything.
#property indicator_chart_window #include <WinUser32.mqh> #include <stdlib.mqh> #import "user32.dll" int GetAncestor (int hwnd, int gaFlags); #import int start(){ int hWnd = WindowHandle( Symbol(),0 ); int mainHwnd = GetAncestor(hWnd,2); Comment( "handle=" + hWnd + "\nparent=" + mainHwnd ); return(0); }
Sure enough, two windows with the same symbol and the same timeframe do give different handles on the hWnd. I tried passing this in the PeekMessageA as the lparam
PostMessageA( mainHwnd, WM_COMMAND, EA_KILL, hWnd );
No joy :-(
How does it know which Window to send it to? How about the window with focus? A few more commands required ...
EDIT: It was actually fewer commands! By sending the message to the chart window (which doesn't know how to handle the message and therefore passes it up to its parent to handle) the parent knows who sent the message and therefore what action to take on which chart. It doesn't need input focus by actual test. The original problem of two charts with the same symbol and the same period is therefore resolved :-)
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Here is my self-destructing EA. The idea is that when it is finished doing its job, it removes itself from the chart. And it does do this very nicely and in not too many lines of code.