Download MetaTrader 5

EA Security and account information

To add comments, please log in or register
bobzacaria
45
bobzacaria  

Hello,

 

I'm working on my EA with no prior experience in MQL5. Could you please advize on how to use account information (i.e. account #, account name, account trade mode) to protect my EA. Also, can I use the account number as the EA Magicnumber? I'll have many questions in the area of mone management and will appreciate your cooperation. I attached below the cose I'm using for your comment and help.

 

 //---- input parameters

LONG_VALUE        Account_Number                     // Account Number
string                   Account_Name                       // AccountName
LONG_VALUE        AccountLeverage                    // AccountLeverage

nanobot
46
nanobot  

Use the CAccountInfo class to declare an instance of the account info object.. you must include the definition of the class:

#include <Trade\AccountInfo.mqh>

//---- correct input declaration

input long        Account_Number                     // Account Number
input string      Account_Name                       // AccountName
input long        Account_Leverage                   // AccountLeverage 

CAccountInfo MyAccount;

//---- getting info

long account_number = MyAccount.Login();

string account_name = MyAccount.Name();

long account_leverage = MyAccount.Leverage();

//---- security code here...

Then compare these values to the input values or do it directly bypassing the use of local variables.

About using the account number as magic number: yes you can.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Account Properties - Documentation on MQL5
To add comments, please log in or register