I am new on the forum, so my apologies if I'm not in the right place, but I'm at the end of my rope, and wondering if any code gurus might be able to help point me in the right direction. I am the opposite of a programming professional, but I've spent countless hours on a trading panel that is coming along very nicely, and I'm hitting a couple of bugs that I just can't figure out how to get through. This post addresses the first bug. Sorry in advance for length.
I found and used the code block from this thread to enable me to add indicators from my own custom UI on demand: https://www.mql5.com/en/forum/73391/page3 (post #27 by Kray). I had to make minor tweaks in terms of using Sleep and the keybd commands, and generally, it has been working. (Note as I admit below, I am a hack, so if you think my use of these commands is duplicate in nature and dumb, I am sure you're right -- but when I found a combo that worked I didn't want to mess with it, since it's been brittle for me.)
Mine below:
Code: Select all
#import "user32.dll"
int GetAncestor(int, int);
int RegisterWindowMessageW(string MessageName); // For Start custom indicator
int PostMessageW(int hwnd,int msg,int wparam,uchar &Name[]); // For Start custom indicator
int FindWindowW(string lpszClass,string lpszWindow); // For Start custom indicator
// int keybd_event(int bVk, int bScan, int dwFlags, int dwExtraInfo); // For Start custom indicator
#import
#define VK_RETURN 13 //ENTER key#import // For Start custom indicator
void StartCustomIndicator(int hWnd,string IndicatorName,bool AutomaticallyAcceptDefaults=true) // true = skip the indicator dialog box
{
Sleep(100);
uchar name2[];
StringToCharArray(IndicatorName,name2,0,StringLen(IndicatorName));
Print("IndicatorName="+IndicatorName);
Print("ArraySize(name2)="+ArraySize(name2));
for (int i = 0; i < ArraySize(name2); i++){
Print("name2["+i+"]="+name2[i]);
}
int MessageNumber=RegisterWindowMessageW("MetaTrader4_Internal_Message");
Sleep(100);
int r=PostMessageW(hWnd,MessageNumber,15,name2);
Sleep(200);
if(AutomaticallyAcceptDefaults) {
keybd_event(13, 0, 0, 0);
int ind_settings = FindWindowW(NULL, "Custom Indicator - "+IndicatorName);
PostMessageW(ind_settings,0x100,VK_RETURN,name2);
keybd_event(13, 0, 0, 0);
}
}In the last day or two, suddenly I was always getting the error messages. I discovered through some trial and error that if I reduced my indicator name length from 15 characters to 14, I'm back to good. 15 was very clearly the magic number before, and now the magic number is 14. I don't know why any number would be a magic number, let alone why it has clearly and definitively changed as of a day or two ago. I am totally stuck making sense of any of this and blind to how this Windows API stuff works, and I'm a noob when it comes to working with uchars as well. I've spent hours googling and trying to sort it out but with no success.
If anyone can explain this, help me resolve, or even point me to a resource where I can help myself, I would be most appreciative.
If you've read this far, thank you so much.
biegea