Skip to content

Instantly share code, notes, and snippets.

@currencysecrets
Last active December 16, 2015 06:58
Show Gist options
  • Save currencysecrets/5394780 to your computer and use it in GitHub Desktop.
Save currencysecrets/5394780 to your computer and use it in GitHub Desktop.
Using the SendEmail function to alert me of potential problems in my MetaTrader live code.
// This function provides a boilerplate type template for sending email alerts about your MetaTrader code.
// param subject (optional) => Usually a short description of what the email is alerting you about
// param body (optional) => As the email already contains many bits of information I just use the body for detailing a reason
// param systemTag (optional) => The name/tag of your expert advisor
//
// Example usage within my EA:
// alertMe( "CLOSE long order failed", "Reason: Closing a pending buystop order in function XYZ has failed", "My Sys (v1.0)" );
void alertMe( string subject = "", string body = "", string systemTag = "" ) {
SendMail( subject + " " + Symbol() + " " + systemTag ,
body + "\n" +
"System: " + systemTag + "\n" +
"Currency: " + Symbol() + "\n" +
"Error #: " + GetLastError() + "\n" +
"Server Time: " + TimeToStr( TimeCurrent(), TIME_DATE|TIME_MINUTES|TIME_SECONDS ) + "\n" +
"Bar[0] Time: " + TimeToStr( Time[0], TIME_DATE|TIME_MINUTES|TIME_SECONDS ) + "\n" +
"Account #: " + AccountNumber() + "\n"
);
}
// if you have a global variable that contains the name of your expert advisor you can change the script above to
// the following without needing to pass in the third parameter
void alertMe( string subject = "", string body = "" ) {
string systemTag = globalSystemTag; // or whatever the name of your global variable is
SendMail( subject + " " + Symbol() + " " + systemTag ,
body + "\n" +
"System: " + systemTag + "\n" +
"Currency: " + Symbol() + "\n" +
"Error #: " + GetLastError() + "\n" +
"Server Time: " + TimeToStr( TimeCurrent(), TIME_DATE|TIME_MINUTES|TIME_SECONDS ) + "\n" +
"Bar[0] Time: " + TimeToStr( Time[0], TIME_DATE|TIME_MINUTES|TIME_SECONDS ) + "\n" +
"Account #: " + AccountNumber() + "\n"
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment