How to Lock an EA to a Specific Account and Earn XM Affiliate Commissions

XMTrading

XM Affiliate Program is a program where you can earn rewards by introducing XM’s services. It is also applicable for those who develop EA (Expert Advisor) and aim to do affiliate marketing. There are mainly two types of rewards available: rewards through trader referrals and rewards through sub-affiliates. To use these, you first need to open an affiliate account as an XM partner.

Rewards through trader referrals

With XM’s trader affiliate program, you can earn rewards when the traders you refer make trades. This type of affiliate program is common in foreign exchange trading and follows a process like this:

  1. Open an XM partner account using the link above
  2. Receive an affiliate link from XM
  3. Post your affiliate link on your website or social media to attract customers
  4. People who open accounts through your affiliate link become your traders
  5. When traders make trades, rewards are sent to your affiliate account

By opening a partner account, you can also place banner ads like the one below on your website.

    Rewards through sub-affiliates

    With XM’s sub-affiliate program, you earn 10% of the rewards earned by the affiliates you refer. The process is as follows:

    1. Open an XM partner account using the link above
    2. Receive a sub-affiliate link from XM
    3. Post your sub-affiliate link on your website or social media to attract customers
    4. People who open partner accounts through your sub-affiliate link become your sub-affiliate partners
    5. When your sub-affiliate partners refer traders and earn rewards, you also receive a portion of the rewards

      The advantage of sub-affiliates is that if you can acquire a few motivated affiliates, rewards will automatically come in afterwards. While the trader affiliate program is the main focus at XM, if you are considering long-term revenue, sub-affiliates are also worth considering. With this as well, you can place banner ads like the one below on your website after opening a partner account.

      How to Distribute Your Custom EA and Earn Rewards

      By developing your own trading system or EA (Expert Advisor) and providing it to other traders or affiliates, you can earn rewards. The more users you introduce to your EA, the more rewards you can potentially earn. If your developed EA can produce excellent results, it may attract the interest of many traders and affiliates, which could lead to even more rewards. The process of earning rewards through EA development is as follows:

      1. Open an XM Partner Account using the link above
      2. Develop your own trading system or EA
      3. Introduce your developed EA or system on your website or social media
      4. Distribute the EA with account restrictions to interested traders and affiliates
      5. Earn rewards as more people use the EA with the designated accounts
      If you distribute an EA with no account restrictions under the condition that the user opens an account from the specified link, the EA can be used freely with accounts other than the specified ones. In such cases, you may not be able to expect affiliate rewards from continued trading, so it’s common to implement some sort of restriction on the use of the EA.

      How to Apply Account Restrictions (Account Binding)

      There are several ways to restrict the use of the EA you distribute so that it can only be used with specific accounts. Depending on the mechanism and purpose, you can choose from various patterns, some of which are introduced below.

      Please note that there are some differences in functions between MT4 EA (MQL4) and MT5 EA (MQL5), so we will introduce both of them.

      Directly Restricting Usage by Account ID

      This method prevents the EA from running on any account other than the specified account ID. It’s a simple method, but it requires you to compile the EA for each distribution target (ID).

      For MT4 (MQL4)

      int number = 123456789; //Account ID
      
      int OnInit(){
      
         if( AccountNumber() != number){
            Alert("Init failed\n\n","Invalid ID");
            return(INIT_FAILED);
         }
         Comment("Init succeeded");
         return(INIT_SUCCEEDED);
      }
      In this case, only users with the account ID “123456789” can use this EA.

      For MT5 (MQL5)

      In MQL5, use the AccountInfoInteger function. If you specify ACCOUNT_LOGIN as the argument, the account ID will be returned.

      int number = 123456789; //Account ID
      
      int OnInit(){
      
         if( AccountInfoInteger(ACCOUNT_LOGIN) != number){
            Alert("Init failed\n\n","Invalid ID");
            return(INIT_FAILED);
         }
         Comment("Init succeeded");
         return(INIT_SUCCEEDED);
      }

      In this case as well, only users with the account ID “123456789” can use this EA.

      These examples show how to apply account restrictions by directly restricting the usage of the EA based on the account ID. However, keep in mind that this method requires you to compile the EA for each distribution target (ID), which may be time-consuming. There are other methods for applying account restrictions, such as using an external server to verify the account ID or encrypting the EA with a unique key for each user. Choose the method that best suits your needs and purpose.

      By effectively applying account restrictions, you can protect your intellectual property and earn rewards through your developed EA. Distributing your EA with account restrictions can help you maintain control over its usage, ensuring that you receive the rewards you deserve as more traders and affiliates use your EA.

      Restricting by Server Name

      You can set up an EA (Expert Advisor) so that it can only be run if the server name matches the specified one. This method is useful for purposes such as “distributing an EA that can only be run on XMTrading’s demo account.”

      For MT4 (MQL4)

      string server = "XMTrading-Demo 3"; // Server name
      
      int OnInit(){
      
         if( AccountServer() != server){
            Alert("Init failed\n\n","Invalid server");
            return(INIT_FAILED);
         }
         Comment("Init succeeded");
         return(INIT_SUCCEEDED);
      }

      “XMTrading-Demo 3” is the server name for XMTrading’s MT4 demo account. The EA can only be run when logged into this server.

      By the way, there now seems to be a “XMTrading-Demo 5” for the KIWAMI ultimate demo account. Choose the one that suits your needs.

      For MT5 (MQL5)

      In MQL5, use the AccountInfoString function. When specifying ACCOUNT_SERVER as an argument, the server name is returned.

      string server = "XMTrading-MT5"; // Server name
      
      int OnInit(){
      
         if( AccountInfoString(ACCOUNT_SERVER) != server){
            Alert("Init failed\n\n","Invalid server");
            return(INIT_FAILED);
         }
         Comment("Init succeeded");
         return(INIT_SUCCEEDED);
      }

      “XMTrading-MT5” is the server name for XMTrading’s MT5 demo account. The EA can only be run when logged into this server.

      Restricting to Demo Accounts Only

      Although the above method of restricting by server name can be used to limit the EA to demo account servers, the following method allows you to create an EA that can only be run on demo accounts more broadly (not limited to specific forex brokers).

      For MT4 (MQL4)

      In MQL4, use the IsDemo function. This function returns true for demo accounts, so the implementation is simple as shown below.

      int OnInit(){
      if(IsDemo() == false){
      Alert("Init failed\n\n","Can only be used on demo accounts");
      return(INIT_FAILED);
      }
      Comment("Init succeeded");
      return(INIT_SUCCEEDED);
      }

      For MT5 (MQL5)

      In MQL5, use the AccountInfoInteger function. When specifying ACCOUNT_TRADE_MODE as an argument, the account type is returned. A value of 0 means a demo account.

      int OnInit(){
      if(AccountInfoInteger(ACCOUNT_TRADE_MODE) !=0){
      Alert("Init failed\n\n","Can only be used on demo accounts");
      return(INIT_FAILED);
      }
      Comment("Init succeeded");
      return(INIT_SUCCEEDED);
      }

      How to Set Up an Authentication Code

      Instead of limiting by account ID as mentioned above, another method that can save you some effort is setting up an authentication code. With this method, you distribute the compiled EA once and then separately inform each user of their account ID-specific authentication code.

      Inputting the Authentication Code

      First, prepare an input field for the authentication code in the EA input screen.

      input int key_code = 0; //Authentication code

      By specifying the authentication code with input as shown above, you can create an input field.

      Getting the Account ID

      Next, obtain the account ID. The function is different for MT4 and MT5, so use the appropriate one.

      int ID = AccountNumber(); //For MT4
      int ID = AccountInfoInteger(ACCOUNT_LOGIN);//For MT5

      Generating the Authentication Code from the ID

      There are various ways to generate (calculate) the authentication code, but let’s try the following method.

      int key = StringToInteger(StringSubstr(IntegerToString(ID), 0, 1)) * 2 +
                StringToInteger(StringSubstr(IntegerToString(ID), 1, 1)) * 3 +
                StringToInteger(StringSubstr(IntegerToString(ID), 2, 1)) * 4 +
                StringToInteger(StringSubstr(IntegerToString(ID), 3, 1)) * 5 +
                StringToInteger(StringSubstr(IntegerToString(ID), 4, 1)) * 6 +
                StringToInteger(StringSubstr(IntegerToString(ID), 5, 1)) * 7 +
                StringToInteger(StringSubstr(IntegerToString(ID), 6, 1)) * 8 +
                StringToInteger(StringSubstr(IntegerToString(ID), 7, 1)) * 9;
      For example, using the ID 12345678, the authentication code can be calculated as follows: 1 * 2 + 2 * 3 + 3 * 4 + 4 * 5 + 5 * 6 + 6 * 7 + 7 * 8 + 8 * 9 = 2 + 6 + 12 + 20 + 30 + 42 + 56 + 72 = 240. Therefore, when the ID is 12345678, the authentication code will be 240.

      Checking the Authentication Code

      Set up the EA to operate only when the authentication code entered in the input (key_code) matches the authentication code calculated from the ID (key).

      int OnInit(){
         if(key!= key_code){
            Alert("Init failed\n\n","The authentication code is incorrect");
            return(INIT_FAILED);
         }
         Comment("Init succeeded");
         return(INIT_SUCCEEDED);

      This concludes the method of limiting by using an authentication code.

      Other Authentication Code Generation Methods

      There are countless ways to generate authentication codes. Here are some other patterns for your reference.

      Calculate the sum of odd digits and the sum of even digits, then triple the sum

      Example: abcdefgh → (a+c+e+g) + 3×(b+d+f+h)

      int ID = 12345678;
      int oddSum = StringToInteger(StringSubstr(IntegerToString(ID), 0, 1)) +
                   StringToInteger(StringSubstr(IntegerToString(ID), 2, 1)) +
                   StringToInteger(StringSubstr(IntegerToString(ID), 4, 1)) +
                   StringToInteger(StringSubstr(IntegerToString(ID), 6, 1));
      
      int evenSum = StringToInteger(StringSubstr(IntegerToString(ID), 1, 1)) +
                    StringToInteger(StringSubstr(IntegerToString(ID), 3, 1)) +
                    StringToInteger(StringSubstr(IntegerToString(ID), 5, 1)) +
                    StringToInteger(StringSubstr(IntegerToString(ID), 7, 1));
      
      int key = oddSum + 3 * evenSum;
      
      In this code, the sum of odd digits (oddSum) and the sum of even digits (evenSum) are calculated separately, with the result (key) being the sum of oddSum and three times the evenSum. For ID = 12345678, the sum of odd digits is: 1 + 3 + 5 + 7 = 16, while the sum of even digits is: 2 + 4 + 6 + 8 = 20. The key is calculated as: 16 + 3 * 20 = 16 + 60 = 76. Therefore, the key will be 76.

      Multiplying each digit by an arbitrary value and finding the sum

      Example: abcdefgh → a×7 + b×6 + c×5 + d×4 + e×3 + f×2 + g×1 + h×8

      int ID = 12345678;
      int key = StringToInteger(StringSubstr(IntegerToString(ID), 0, 1)) * 7 +
                StringToInteger(StringSubstr(IntegerToString(ID), 1, 1)) * 6 +
                StringToInteger(StringSubstr(IntegerToString(ID), 2, 1)) * 5 +
                StringToInteger(StringSubstr(IntegerToString(ID), 3, 1)) * 4 +
                StringToInteger(StringSubstr(IntegerToString(ID), 4, 1)) * 3 +
                StringToInteger(StringSubstr(IntegerToString(ID), 5, 1)) * 2 +
                StringToInteger(StringSubstr(IntegerToString(ID), 6, 1)) * 1 +
                StringToInteger(StringSubstr(IntegerToString(ID), 7, 1)) * 8;

      In this code, each digit is multiplied by an arbitrary value, and the sum (key) is calculated. For ID = 12345678, the key is calculated as follows: 1×7 + 2×6 + 3×5 + 4×4 + 5×3 + 6×2 + 7×1 + 8×8 = 7 + 12 + 15 + 16 + 15 + 12 + 7 + 64 = 148. Therefore, the key equals 148.

      Finding the sum of the first four digits and the last four digits, doubling the sum of the first four digits, and adding it to the sum of the last four digits

      Example: abcdefgh → (a+b+c+d)×2 + (e+f+g+h)

      int ID = 12345678;
      int sum_front = StringToInteger(StringSubstr(IntegerToString(ID), 0, 1)) +
                      StringToInteger(StringSubstr(IntegerToString(ID), 1, 1)) +
                      StringToInteger(StringSubstr(IntegerToString(ID), 2, 1)) +
                      StringToInteger(StringSubstr(IntegerToString(ID), 3, 1));
      int sum_back = StringToInteger(StringSubstr(IntegerToString(ID), 4, 1)) +
                     StringToInteger(StringSubstr(IntegerToString(ID), 5, 1)) +
                     StringToInteger(StringSubstr(IntegerToString(ID), 6, 1)) +
                     StringToInteger(StringSubstr(IntegerToString(ID), 7, 1));
      int key = sum_front * 2 + sum_back;
      In this code, the sum of the first four digits and the last four digits is calculated, the sum of the first four digits is doubled, and it is added to the sum of the last four digits (key). For ID = 12345678, sum_front = 1 + 2 + 3 + 4 = 10 sum_back = 5 + 6 + 7 + 8 = 26 key = (10 * 2) + 26 = 20 + 26 = 46 Therefore, the key is 46.

      Method requiring authentication code only for real accounts

      This is a combination of the methods introduced so far. The demo account does not require an authentication code, and the real account has a restriction that the EA cannot operate if the authentication code does not match.

      For MT4 (MQL4)

      int OnInit(){
         if(IsDemo() == false&&key!= key_code){
            Alert("Init failed\n\n","Invalid authentication code");
            return(INIT_FAILED);
         }
         Comment("Init succeeded");
         return(INIT_SUCCEEDED);

      For MT5 (MQL5)

      int OnInit(){
         if(AccountInfoInteger(ACCOUNT_TRADE_MODE) !=0&&key!= key_code){
            Alert("Init failed\n\n","Invalid authentication code");
            return(INIT_FAILED);
         }
         Comment("Init succeeded");
         return(INIT_SUCCEEDED);

      Summary

      In summary, the XM Affiliate Program offers a lucrative opportunity for EA developers and affiliate marketers to earn rewards through trader referrals and sub-affiliates. This article has provided a comprehensive guide on how to distribute your custom EA and apply account restrictions, such as binding to specific account IDs, server names, or demo accounts only. Additionally, it has outlined various methods for setting up authentication codes to further protect your EA. By following these steps, you can maximize your earnings while ensuring that your EA is only used by authorized clients.

      Comments

      Copied title and URL