Alain Verleyen #: You just have to add code to simulate key stroke, like you do manually.
Doesn't work. I need to execute the add indicator code from an indicator. I have tried many solutions, but I get no results. The indicator I want to add gets added, but the indicator configuration window stays on and waits for manual confirmation. I am doing this in MT4 Build 1353.
To be clear, those codes work from script fine, and the keyboard emulation works from script, too. No luck from an indicator...
I would like to thanks Georgiy Liashchenko, and I would like to share my upgraded version of his code that add the indicator directly into the chart with AutomaticallyAcceptDefaults (when it is on "true").
I hope it will help some people that need to insert indicators from the expert.
#import "user32.dll"int RegisterWindowMessageW(string lpString);
int FindWindowW(string lpClassName, string lpWindowName);
int GetDlgItem(int hDlg, int nIdDlgItem);
int SetActiveWindow(int hWnd);
bool PostMessageA(int hWnd, int msg, int wParam, uchar &lParam[]);
bool PostMessageW(int hWnd, int msg, int wParam, int lParam);
#import
#define MAX_PATH 260// e.g. the max. path on drive D is "D:\some-256-chars-path-string<NUL>"#define MT4_LOAD_CUSTOM_INDICATOR 15#define IDC_CUSTOM_INDICATOR_OK 1// control id of "Ok" button in "Custom Indicator" dialog#define BM_CLICK 0x00F5uchar buffer[MAX_PATH];
void StartCustomIndicator(int hWnd, string indicatorName, bool autoCloseDlg = true) {
StringToCharArray(indicatorName, buffer);
int WM_MT4 = RegisterWindowMessageW("MetaTrader4_Internal_Message");
PostMessageA(hWnd, WM_MT4, MT4_LOAD_CUSTOM_INDICATOR, buffer);
if (autoCloseDlg) {
string className, title = "Custom Indicator - "+ indicatorName;
int i = 0;
while (i < 5) {
Sleep(10);
int hWndDlg = FindWindowW(className, title);
if (hWndDlg != 0) {
int hWndOk = GetDlgItem(hWndDlg, IDC_CUSTOM_INDICATOR_OK);
if (hWndOk != 0) {
SetActiveWindow(hWndDlg);
PostMessageW(hWndOk, BM_CLICK, 0, 0);
}
elsePrint("Error: \"OK\" button not found");
break;
}
i++;
if (i >= 5) Print("Error: Dialog \""+ title +"\" not found");
}
}
}
intOnInit()
{
//---int hWnd=WindowHandle(Symbol(),0);
StartCustomIndicator(hWnd,"Stochastic"); // For example STO//---return(INIT_SUCCEEDED);
}
with all the different codes related to user32.dll and messages, it should be a good idea to share an updated version of the include file with additionnal codes.
I would like to thanks Georgiy Liashchenko, and I would like to share my upgraded version of his code that add the indicator directly into the chart with AutomaticallyAcceptDefaults (when it is on "true").
I hope it will help some people that need to insert indicators from the expert.
Note2 : Don't use indicators with more than 15 characters (before the ".ex4")
Hello everyone,
This solution is really interesting and works well, but there is a small problem. If the same EA is active on more than one chart, on the first the loading of the indicator is automatic, on the others it requires manual confirmation on OK. Is there any solution?
I have also used the code from @Hossein Sadeghian Nezhad and it works pretty good - thanks for that!
However, I want to add custom indicators on the main chart with specific input variables. When using the code above, you can't change the the input values, it will only show the indicator with "standard" settings.
How can I show the custom indicator in the chart with other input values?
Alain Verleyen:
Hello
I am trying to use this code in a SCRIPT, but sometimes my metatrader close soddenly
Do you know what is the problem ?
Chart.mqh is pretty obvious........
You just have to add code to simulate key stroke, like you do manually.
Doesn't work. I need to execute the add indicator code from an indicator. I have tried many solutions, but I get no results. The indicator I want to add gets added, but the indicator configuration window stays on and waits for manual confirmation.
To be clear, those codes work from script fine, and the keyboard emulation works from script, too.I am doing this in MT4 Build 1353.
No luck from an indicator...
Hello everyone,
I would like to thanks Georgiy Liashchenko, and I would like to share my upgraded version of his code that add the indicator directly into the chart with AutomaticallyAcceptDefaults (when it is on "true").
I hope it will help some people that need to insert indicators from the expert.
Note : I works for custom indicators, else change the windows name
Note2 : Don't use indicators with more than 15 characters (before the ".ex4")
Great
Hi
with all the different codes related to user32.dll and messages, it should be a good idea to share an updated version of the include file with additionnal codes.
Here is the include file I am using:
Hello everyone,
I would like to thanks Georgiy Liashchenko, and I would like to share my upgraded version of his code that add the indicator directly into the chart with AutomaticallyAcceptDefaults (when it is on "true").
I hope it will help some people that need to insert indicators from the expert.
Note : I works for custom indicators, else change the windows name
Note2 : Don't use indicators with more than 15 characters (before the ".ex4")
Hello everyone,
This solution is really interesting and works well, but there is a small problem. If the same EA is active on more than one chart, on the first the loading of the indicator is automatic, on the others it requires manual confirmation on OK. Is there any solution?
Hi all,
I have also used the code from @Hossein Sadeghian Nezhad and it works pretty good - thanks for that!
However, I want to add custom indicators on the main chart with specific input variables. When using the code above, you can't change the the input values, it will only show the indicator with "standard" settings.
How can I show the custom indicator in the chart with other input values?
Thanks in advance for feedback!