Expert Advisor Programming by Andrew R. Young
Expert Advisor Programming by Andrew R. Young
Expert Advisor Programming by Andrew R. Young
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Tips and Tricks<br />
You can use the account functions AccountName(), AccountNumber() and AccountBroker() to<br />
check the account name, number and broker respectively. Limiting usage <strong>by</strong> account number is a<br />
common and easy to implement method of protection:<br />
int CustomerAccount = 123456;<br />
if(AccountNumber() != CustomerAccount)<br />
{<br />
Alert("Account number does not match!");<br />
return(0);<br />
}<br />
You can use AccountName() or AccountBroker() in a similar manner. For AccountBroker(), you'll<br />
first need to use a Print() statement to retrieve the correct return value from the broker. This value<br />
will be printed in the experts log.<br />
If you do decide to sell an EA commercially, be aware that MQL files are notoriously easy to<br />
decompile. There are various methods you can use to make it more difficult for hackers to crack your<br />
EA, such as placing functions in external libraries or DLLs. But ultimately, there is little protection<br />
against a determined cracker.<br />
MessageBox()<br />
So far in this book, we've been using the built-in Alert() function to display error messages. But<br />
what if you want to customize your alert dialogs, or request input from the user? The MessageBox()<br />
function will allow you to create a custom pop-up dialog using Windows API functions.<br />
To use the MessageBox() function, we must first #include the WinUser32.mqh file that is installed<br />
with MetaTrader. This file imports functions from the Windows user32.dll file and defines constants<br />
necessary for the MessageBox() function to work. Here is the syntax for the MessageBox() function:<br />
int MessageBox(string Text, string Title, int Flags);<br />
To use the MessageBox() function, we must define the Text to appear in the pop-up dialog, along<br />
with a Title that appears in the title bar. We will also need to specify Flags that indicate which<br />
buttons and icons should appear in our pop-up. If no flags are specified, an OK button will be the<br />
default. Flags must be separated <strong>by</strong> the pipe (|) character.<br />
Here's an example of a message box with Yes/No buttons and a question mark icon:<br />
125