Account Information
The functions of the client terminal and status checking functions are convenient to be applied for program restriction when it is distributed on the commercial basis, for example. Let's examine the solution of the problem below:
|
Problem 39. Create a protection code of the program distributed on the commercial basis, which meets the following requirements: - the program must require a password to be executed on real accounts of individual clients;
- the password is not required to execute the program on real accounts of corporate clients;
- no limitations are provided for the execution of the program on demo accounts.
|
This example contains a correct problem definition. For successful commercial distribution, you provide your potential consumers with a program that can be fully tested on a demo account. So the user can weigh all the advantages of the program and come to the decision of buying it.
The application of a common password is incorrect - the unauthorized distribution of the program is possible, in this case. So the individual password for the user must be dependent on the real account number. There is no need to use the password for the corporate clients (if the dealing center bought the license for all its traders) - the program must self-identify the server that the client terminal is connected to. And, if it is the server of the corporate client then every user must be able to work without obstacles.
The solution of the Problem 39 limiting the rights of program use can be the following (сheck.mq4 EA):
extern int Parol=12345;
int start()
{
if(Check()==false)
return;
Alert("Program execution");
return;
}
bool Check()
{
if (IsDemo()==true)
return(true);
if (AccountCompany()=="SuperBank")
return(true);
int Key=AccountNumber()*2+1000001;
if (Parol==Key)
return(true);
Alert("Wrong password. EA does not work.");
return(false);
}
The necessary checking is performed in top entries of the special start() function, in this example (block 2-3):
if(Check()==false)
If the Check() function returns false as the result of checking, then the control is passed to the return operator and the special start() function finishes its working. The main code of the program is located directly after this checking. The Check() function will return true if checking is successful, then the main code will be executed.
The checking is performed according to three criteria in the user-defined function Check():
- is the account a demo one;
- does the server belong to a corporate client;
- is the password valid for the real account.
The function IsDemo() is used for checking according to the first criterion.
Function IsDemo()
bool IsDemo()
The function returns TRUE, if the program is working with a demo account. Otherwise, it returns FALSE.
If the IsDemo() function returns true, then the user is working with the demo-account. This means that there is no need for further checking (because use of program with a demo-account is free for everyone). The Check() function finishes its working and returns true, in this case:
if (IsDemo() == true)
return(true);
But if the IsDemo() function returns false value then the user is working with the real account. It is necessary to find out if the user has enough rights, in this case. The AccountCompany() function is used in this example to check the corporate clients.
Function AccountCompany()
string AccountCompany()
The function returns the name of the company the current account is registered at.
If the checking resulted in:
if (AccountCompany() == "SuperBank")
return(true);
determining that the name of the company corresponds with the one specified in the program, then the Check() function will finish its working and return true - the checking will be finished successfully. If it is turned out that the client is connected to the other company (that is not a corporate client), then there is no need to find out if he\she has an individual license.
The entry:
int Key = AccountNumber()*2+1000001;
puts the algorithm for calculation of a key for any account in the program. This example contains the simple method. The programmer, as he\she thinks fit, can insert more complex method for key calculation. Anyway, the algorithm must consider an account number that is available for the program by using the AccountNumber() function.
Function AccountNumber()
int AccountNumber()
The function returns the number of the current account.
The password previously calculated using the same algorithm is passed to the user. If the checking has resulted in finding out that that the password and the key match each other, then the Check() function finishes its working and returns true value:
if (Parol == Key)
return(true);
If none of the checking procedures finished successfully then the user can not trade using a real account. In this case, the Check() function finishes its working and returns false value after making the appropriate announcement. In such a manner the unauthorized use of the program attempt is suppressed.
Functions Returning Client Terminal Information
Function |
Summary Info |
TerminalCompany |
It returns the name of the company that owns the client terminal. |
TerminalName |
It returns the name of the client terminal. |
TerminalPath |
It returns the directory the client terminal is launched from. |
Functions Detecting the Current Status of the Client Terminal Including the Environment Status of the Executed MQL4 Program
Function |
Short description |
GetLastError |
The function returns the last error code, following which the value of the special last_error variable that contains the last error code is set to zero. So the next calling of the GetLastError function will return 0 value. |
IsConnected |
It returns the status of the connection used for data transferring between the client terminal and the server. TRUE - the connection to the server is established, FALSE - there is no connection to the server or the connection is lost. |
IsDemo |
It returns TRUE if a program works with a demo-account. Otherwise, it returns FALSE. |
IsDllsAllowed |
It returns TRUE if DLL calling functions are permitted for an EA. Otherwise, it returns FALSE. |
IsExpertEnabled |
It returns TRUE if the EA launching is permitted in the client terminal. Otherwise, it returns FALSE. |
IsLibrariesAllowed |
It returns TRUE if an EA is able to declare a library function. Otherwise, it returns FALSE. |
IsOptimization |
It returns TRUE if an EA is working in the test optimizing mode. Otherwise, it returns FALSE. |
IsStopped |
It returns TRUE if a program (EA or script) received a command to exit working. Otherwise, it returns FALSE. |
IsTesting |
It returns TRUE if an EA is working in the testing mode. Otherwise, it returns FALSE. |
IsTradeAllowed |
It returns TRUE if an EA is allowed to trade and the traffic is free for trading. Otherwise, it returns FALSE. |
IsTradeContextBusy |
It returns TRUE if the traffic for trading is busy. Otherwise, it returns FALSE. |
IsVisualMode |
It returns TRUE if an EA is tested in the visualization mode. Otherwise, it returns FALSE. |
UninitializeReason |
It returns the code of the reason for operation termination of an EA, a custom indicator or a script. Returned values can be one of the deinitialization codes. This function can be called in the init() function to analyze the reasons for deinitialization of the previous launch, as well. |
Functions Accessing to the Information about the Active Account
Function |
Short description
|
AccountBalance |
It returns a value of the balance of the active account (the total amount of money on the account). |
AccountCredit |
It returns a credit value of the active account. |
AccountCompany |
It returns the name of a brokerage company the current account is registered at.
|
AccountCurrency |
It returns the currency name of the current account. |
AccountEquity |
It returns the equity value of the current account. The equity calculation depends on server settings. |
AccountFreeMargin |
It returns the value of free margin permitted for opened orders of a current account. |
AccountFreeMarginCheck |
It returns the value of free margin that will remain after the specified position has been opened on the current account. |
AccountFreeMarginMode |
The calculation of free margin amount mode for opened orders of the current account.
|
AccountLeverage |
It returns the leverage value of the current account. |
AccountMargin |
It returns the amount of margin used to maintain the open positions on the current account.
|
AccountName |
It returns the user name of the current account. |
AccountNumber |
It returns the number of the current account. |
AccountProfit |
It returns the profit value of the current account calculated in the base currency. |
AccountServer |
It returns the name of the active server. |
AccountStopoutLevel |
It returns the value of the level that is used to identify the StopOut status. |
AccountStopoutMode |
It returns the mode of StopOut level calculation. |
To get the detailed description of these and other functions, please refer to the Documentation at
MQL4.community, at
MetaQuotes Ltd. website or at the "Help" section of MetaEditor.