I know that this question has been asked before, but I can't get it to work. I hope someone can help.
From my custom EA, I want to programmatically add my custom indicator to a subwindow of the chart the EA was added to. I've managed to do this in MQL5 with ChartIndicatorAdd. So, I have my indicator which is added to a separate window (#property indicator_separate_window) and from my EA, I'm calling the following code from https://forum.mql4.com/20946 :
int RegisterWindowMessageA(string MessageName);
int PostMessageA(int hwnd, int msg, int wparam, string Name);
void keybd_event(int VirtualKey, int ScanCode, int Flags, int ExtraInfo);
void StartCustomIndicator(int hWnd, string IndicatorName, bool AutomaticallyAcceptDefaults = false)
int MessageNumber = RegisterWindowMessageA("MetaTrader4_Internal_Message");
PostMessageA(hWnd, MessageNumber, 15, IndicatorName);
if (AutomaticallyAcceptDefaults) ClearConfigDialog();
// In my code where I launch the indicator
int hWnd = WindowHandle(Symbol(), 0);
However, when I execute this code, nothing is happening. Am I doing something wrong? Also, is it possible to provided parameters to the indicator using this manner?
Since Feb, 2014 Build 600, all strings are Unicode. RegisterWindowMessageA and PostMessageA will never work.
Whether the adjusted code will work is doubtful.
Create a template with the indicator added and then have EA call ChartApplyTemplate - MQL4 Documentation
The real question is why are you trying to do this? Indicators need to be visible only for Humans. EA's just get their value via iCustom.
Thanks for the reply.
To answer your question why I need this: I want to visually analyze my EA and see how my EA buys/sells when the indicator changes. Yes, I could add the indicator manually, but I love things that are automated.
With regards to the unicode strings: will RegisterWindowMessageA and PostMessageA never-ever work, or should they work if I convert the strings to ANSI and pass them to the functions?
Other people who are interested. I've managed to get it working:
int RegisterWindowMessageW(string MessageName);
int PostMessageW(int hwnd, int msg, int wparam, char &Name);
string name = "MyIndicator";
StringToCharArray(name , name2);
int MessageNumber = RegisterWindowMessageW("MetaTrader4_Internal_Message");
int r = PostMessageW(hWnd, MessageNumber, 15, name2);
Can somebode check this code in the latest 880 build?
For me it is crashing mt4, though after restarting the mt4 ATR indicator is on the chart, so it was attached before the crash.
With using SendMessageW instead of PostMessageW - no crash, but indicator's dialog window appears and waits for user input (calling keybd_event(13, 0, 0, 0) does not work).
Any update, on getting the code to work on current build.
To add comments, please log in or register