SendNotification not passing string variables

 

Hello there,

I'm struggling with the SendNotification function. I've tried different codes following advice in the forum that it cannot pass more than one argument, but i still don't get the full notification. Here is my current code:


Print("Error: "   + ErrorDescription(GetLastError()) + " closing Buy order ticket " + OrderTicket());
err = GetLastError();
string note3 = ErrorDescription(err);
msg = StringConcatenate("Error ", msg, " closing Buy order ticket ", OrderTicket());
if(Notification) SendNotification(msg);

Where the variables were declared as follows:

int err;

string msg;


I receive in my phone: Error no error closing Buy order ticket 2434249
The print command works fine. The journal says sending "Sending Error no error closing Buy order ticket 2434249 to Metatrader ID".
I've even copied the ErrorDescription function to inside my code, for fear that somehow it couldn't handle the call to the included file.

I've also tried the following code with no success:


Print("Error: "   + ErrorDescription(GetLastError()) + " closing Buy order ticket " + OrderTicket());
if(Notification) SendNotification("Error " + ErrorDescription(GetLastError()) + " closing Buy order ticket " + OrderTicket());


Any hints as to where i'm going wrong?

Thanks.

 
bentbawer:



Any hints as to where i'm going wrong?

Thanks.


If you receive a message "no error" this is because you don't have an error.

So only send your notification when you have an error :

Print("Error: "   + ErrorDescription(GetLastError()) + " closing Buy order ticket " + OrderTicket());
err = GetLastError();
string note3 = ErrorDescription(err);
msg = StringConcatenate("Error ", note3, " closing Buy order ticket ", OrderTicket());
if(err !=0 && Notification) SendNotification(msg);

See documentation.

 
bentbawer:


Hello there,

I'm struggling with the SendNotification function. I've tried different codes following advice in the forum that it cannot pass more than one argument, but i still don't get the full notification. Here is my current code:

When you have a problem with the functions you are using read the documentation.  GetLastError()  

"The function returns the last occurred error, then the value of special last_error variable where the last error code is stored will be zeroized. So, the next call for GetLastError() will return 0.

 

So . . .

Print("Error: "   + ErrorDescription(   GetLastError()  ) + " closing Buy order ticket " + OrderTicket()); // reads and zeros the error held by GLE

err = GetLastError();   //  this now reads as zero . . 

string note3 = ErrorDescription(err);
msg = StringConcatenate("Error ", msg, " closing Buy order ticket ", OrderTicket());
if(Notification) SendNotification(msg);

Do this instead . . .

err = GetLastError();  // this line moved to here . . 

Print("Error: "   + ErrorDescription(err) + " closing Buy order ticket " + OrderTicket());  //  line edited

string note3 = ErrorDescription(err);
msg = StringConcatenate("Error ", msg, " closing Buy order ticket ", OrderTicket());
if(Notification) SendNotification(msg);
 

If you're receiving "Error no error closing Buy order ticket 2434249" to your device than you're receiving the full message. The Print "Sending Error no error closing Buy order ticket 2434249 to Metatrader ID" is not what you asked for. Your message starts with Error and ends with ticket #.

I mean, its not like you're getting a fully error description with the Print command and opposite with the Notification. Maybe I'm having an eye-sore or something? Anyways perhaps you should be asking gle=GetLastError(), if( gle != 0 ){ do all this other stuff. } 

 

angevoyageur: I forgot to mention that before my code for error reporting, i check to see if an error occurs. I do get informed about the error number and description on Print().

RaptorUK: I haven't tested your code yet but i'm sure it is the solution.

ubzen: I'm sorry, what i meant by "Metatrader ID" is THE metatrader ID of my MT4 on my phone, so something like E34D074 (i'm guessing the ID). And yes, i'm getting a full error description with Print().

Thank you to all that replied.


 
bentbawer:


angevoyageur: I forgot to mention that before my code for error reporting, i check to see if an error occurs. I do get informed about the error number and description on Print().

RaptorUK: I haven't tested your code yet but i'm sure it is the solution.

ubzen: I'm sorry, what i meant by "Metatrader ID" is THE metatrader ID of my MT4 on my phone, so something like E34D074 (i'm guessing the ID). And yes, i'm getting a full error description with Print().

Thank you to all that replied.



Indeed, good catch RaptorUK :-)
 

msg = is wrong. Read documentation about StringConcatenate... 

Example: StringConcatenate(msg,"Error ", bla... bla...); The 1st variable has to be the string to create.

 
@Milko Vivaldi #: msg = is wrong. Read documentation about StringConcatenate... Example: StringConcatenate(msg,"Error ", bla... bla...); The 1st variable has to be the string to create.

I suggest that it is you that needs to read the documentation. This is the MQL4 section, not MQL5. The StringConcatenate for MQL4 is different to that of MQL5.

The function returns the string formed by concatenation of parameters transformed into string type.

string  StringConcatenate(
   void argument1,        // first parameter of any simple type
   void argument2,        // second parameter of any simple type
   ...                    // next parameter of any simple type
   );

Also, please don't wake up a 10 year-old thread for no apparent reason.

StringConcatenate - String Functions - MQL4 Reference
StringConcatenate - String Functions - MQL4 Reference
  • docs.mql4.com
StringConcatenate - String Functions - MQL4 Reference
Reason: