MQL5 TUTORIAL BASICS – SIMPLE ACCOUNT CHECK

video
play-sharp-fill

 

  1. Introduction to Account Number Security in Expert Advisors (00:00 – 00:12)
    • Introduction to creating an Expert Advisor in MQL5 that secures your account number, ensuring that the advisor is only usable with a specific account.
  2. Declaring the Account Number Variable (00:12 – 00:22)
    • Explanation of how to declare a variable to store the account number for comparison against a predetermined number.
  3. Understanding the OnTick Function (00:22 – 00:44)
    • Overview of the OnTick function, which is automatically called by MetaTrader when a new tick is received, and its role in calling the account number check function.
  4. Implementing the Check Account Number Function (00:44 – 01:04)
    • Detailed explanation of the check account number function, including the declaration of the ‘is licensed account’ variable and setting it to false.
  5. Retrieving and Comparing Account Information (01:04 – 01:38)
    • Instructions on using the ‘AccountInfoInteger’ function to retrieve the account number and type from MetaTrader, followed by a comparison with the predetermined number.
  6. Handling the Comparison Result (01:38 – 01:58)
    • Steps to handle the result of the account number comparison, including setting the ‘is licensed account’ variable and printing messages to the terminal window.
  7. Compiling and Testing the Code (01:58 – 02:12)
    • Guidance on compiling the code using F7 and returning to MetaTrader with F4 for testing purposes.
  8. Conclusion and Practical Application (02:12 – 03:03)
    • Conclusion of the tutorial with a demonstration of running the Expert Advisor on the correct account and ensuring it is not used by unauthorized users.

 

In this video, we are going to create a little simple expert advisor to secure your account number. So nobody else will be able to use your expert advisor if not a certain type of account is used. So let’s see how that can be done with MQL5.

The account number variable: the first part of the code is the declaration of the account number variable. This variable is used to store the account number that is to be compared against the predetermined number. The OnTick function: the OnTick function is a special function that is automatically called by the Metatrader platform whenever a new tick is received. In this case, the Ontick function is used to call the check account number function, which will be discussed in more detail later. The check account number function: The check account number function is the main function used to verify the account number. It begins by declaring the is licensed account boolean variable and setting it to false. This variable is used to store the result of the comparison between the account number and the predetermined number. The next line of code uses the account info integer function to retrieve the account number from the Metatrader platform and store it in the account number variable. The following line of code uses the account info integer function to retrieve the account type from the Metatrader platform and store it in the account type variable. The next part of the code is an if statement that compares the account number variable to the predetermined number.

If the comparison returns true, then the is licensed account variable is set to true and a message is printed to the terminal window. The last part of the code is an if statement that checks the value of the is licensed account variable. If the value is false, then a message is printed to the terminal window. Finally, the function returns the value of the is licensed account variable. You can now press F7 to compile your code and return to the Meta trader by pressing F4. Conclusion: This MQL5 code is used to verify if an account number is true or false. It does this by comparing the account number to a predetermined number and then returning a boolean value of true or false depending on the result of the comparison.

Okay, so far so good. If everything worked out as it should, you should now be able to run the expert advisor on the correct account. So let’s change that here. I will stop the strategy tester. Let’s pick the right account here, restart the test, and now we get the output, the account number is true. And in this little video, you have learned how to hard code an account number into your expert advisor to make sure that it is not used by anybody else. Thank you for watching and I will see you in the next video.