Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via Visa QIWI Wallet
goocreations
329
goocreations 2015.04.14 06:31 

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://www.mql5.com/en/forum/115967 :

#import "user32.dll"
   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);
#import

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);

StartCustomIndicator(hWnd, "MyIndicator");


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?

whroeder1
13616
whroeder1 2015.04.14 12:26  

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.

goocreations
329
goocreations 2015.04.14 13:17  

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?

goocreations
329
goocreations 2015.04.14 13:34  

Other people who are interested. I've managed to get it working:


#import "user32.dll"
  int RegisterWindowMessageW(string MessageName);
  int PostMessageW(int hwnd, int msg, int wparam, char &Name[]);
#import


 string name = "MyIndicator";
 char name2[];
 StringToCharArray(name , name2);
 
 int MessageNumber = RegisterWindowMessageW("MetaTrader4_Internal_Message");
 int r = PostMessageW(hWnd, MessageNumber, 15, name2);
Kun Li
331
Kun Li 2015.08.27 09:57  
goocreations:

Other people who are interested. I've managed to get it working:


#import "user32.dll"
  int RegisterWindowMessageW(string MessageName);
  int PostMessageW(int hwnd, int msg, int wparam, char &Name[]);
#import

void callIndic(){
   string name = "ATR";
   char name2[256];
   StringToCharArray(name , name2);
   
   int hWnd = WindowHandle(Symbol(), Period());
   int MessageNumber = RegisterWindowMessageW("MetaTrader4_Internal_Message");
   int r = PostMessageW(hWnd, MessageNumber, 15, name2);

}


Mykola Bilak
467
Mykola Bilak 2015.09.23 15:56  

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).

AnkaSoftware
178
AnkaSoftware 2016.08.29 13:27  
nickbilak:

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).



Hi,

   Any update, on getting the code to work on current build.

whroeder1
13616
whroeder1 2016.08.29 18:10  
EA's have no eyes, there is no need for the EA to attach an indicator. If you want it on the chart, add it.
/
To add comments, please log in or register