How to detect the current license of a paid EA?

 

Hello,

I need to check in runtime, what is the license type of the EA. In MQL4 terms. If it is free, demo, paid(full), or time trial. I need to check this, because my program is mainly designed to work in a tester mode, and it will have a paid version with more features unlocked.

This is a question I asked before, but I didn't receive a satisfactory answer. Still I know it is possible, because there are programs on the market which are working in that way. In addition, I received a new information about this topic, wrote a code,  and now I would like to ask for a help, if my license check function is written properly, before submitting the EA to the moderators.

I can't test this function myself, because I need a server response from Mql5 market, which can't be done if the EA is not already registred in Mql5 market.

Also, I guess, that in tester mode the following expression for obtaining the license type:

ENUM_LICENSE_TYPE licenseType = (ENUM_LICENSE_TYPE)MQLInfoInteger(MQL_LICENSE_TYPE);

will not give a true result. Please, tell me if I am right?

The idea is to check the license only when EA is applied to a live chart(because of the assumption that this can not be done in tester mode), to set the mode(demo or full) then to write the result into a file.

If in tester mode EA just reads the result from the file and sets its mode(demo or full). If there is no such file(EA not applied to a live chart, file corrupted or deleted ), it sets the mode to demo and alerts the user that she/he has to apply the EA to a live chart in order to obtain the license data.


Here is the code excerpt:

//-------------------LICENSE---------------
 const int FREE_LICENSE_RESPONSE = 10001;
 const int DEMO_LICENSE_RESPONSE = 10002;
 const int FULL_LICENSE_RESPONSE = 10003;
 const int TIME_LICENSE_RESPONSE = 10004;
 const int UNDEFINED_LICENSE_RESPONSE = 10005;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---                           
          TESTER_MODE = MQLInfoInteger(MQL_TESTER);            
                            
          if(!TESTER_MODE)  //If not in tester mode. 
          {    
            ENUM_LICENSE_TYPE licenseType = (ENUM_LICENSE_TYPE)MQLInfoInteger(MQL_LICENSE_TYPE); //Check the license type. IS THIS CHECK POSSIBLE IN TESTER MODE???
                                               
            int currentLicenseResponse = 0;
            
            if(licenseType == LICENSE_FREE) // if license is free, full features are unlocked
            {
               currentLicenseResponse = FREE_LICENSE_RESPONSE;
               IS_DEMO = false;
            }
            if(licenseType == LICENSE_DEMO) // if license is demo, full features are NOT unlocked
            {
               currentLicenseResponse = DEMO_LICENSE_RESPONSE;
               IS_DEMO = true;
            }
            else if(licenseType == LICENSE_FULL) // if license is FULL(that means payment is done), full features are unlocked
            {
               currentLicenseResponse = FULL_LICENSE_RESPONSE;
               IS_DEMO = false;
            }
            else if(licenseType == LICENSE_TIME) // if license is TIME(that means payment is done, and full feature trial is enabled), full features are unlocked
            {
               currentLicenseResponse = TIME_LICENSE_RESPONSE;
               IS_DEMO = false;
            }
            else // if answer by some reason is something else, full features are not unlocked
            {
               currentLicenseResponse = UNDEFINED_LICENSE_RESPONSE;
               IS_DEMO = true;
            }
            
             //-------------RECORD RESULT INTO FILE------------------
             int h = FileOpen(LICENSE_PATH, FILE_BIN|FILE_WRITE); 
             if(h > -1) // if file open or file creation successfull
             {    
               FileWriteInteger(h,currentLicenseResponse, INT_VALUE);  // we record server response
               FileClose(h);
             }         
             else  // if file open or file creation unsuccessfull
             {
                Alert("License file can't be created. Please check folder write permissions.");             
             }                              
        } // end if(!TESTER_MODE)  
        else // if in tester mode(I guess license info is not possible to obtain in this mode)
        {
            IS_DEMO = true;
            int h = FileOpen(LICENSE_PATH, FILE_BIN|FILE_READ); // we read the file containing the license server response obtained last time when expert was used in real trade mode
            if(h > -1) //if there is such a file, we read the answer
            {
               int savedLicense = FileReadInteger(h, INT_VALUE);
               if(savedLicense == FREE_LICENSE_RESPONSE || savedLicense == FULL_LICENSE_RESPONSE || savedLicense == TIME_LICENSE_RESPONSE)  // only in these cases all features are unlocked
               {
                 IS_DEMO = false;
               }
               FileClose(h);
            } 
            else
            {
               Alert("No license file found! Expert will start in demo mode. Please apply this expert to a live chart, in order to update the license file.");
            }      
        }                  
     
    


Thank you!

 

please dont doublepost

 
Marco vd Heijden:

please dont doublepost


Sorry, I noticed later that this is the more appropriate forum for my question. 

I will delete the other post.

 

You should reconsider your approach because you are not allowed to use your own licensing scheme according to the market rules:

IV. Products

  1. ...
  2. ...
  3. ...
  4. ...
  5. Integrating and applying any third-party sales, accounting, license control and update management systems (including the ones using WebRequestfeatures) in Products are prohibited.

Time-limited licenses are not supported yet.

When a demo is running in the tester it stops a considerable number of bars before today (making it impossible to use for real trading and analysis) - probably this will be sufficient for your product.

You can specify more details, then more suggestions could probably follow.

 
Stanislav Korotky:

You should reconsider your approach because you are not allowed to use your own licensing scheme according to the market rules:

Time-limited licenses are not supported yet.

When a demo is running in the tester it stops a considerable number of bars before today (making it impossible to use for real trading and analysis) - probably this will be sufficient for your product.

You can specify more details, then more suggestions could probably follow.


Well, I do not want to implement my own licensing system. What I want is very simple.

1. To detect in runtime if the current downloaded instance of the EA is already paid by the user, or not, according Mql5 market terms. If the user has paid for the EA in Mql5 market environment, or has downloaded only the demo version.

2. According to this information(paid or demo version), to allow(case paid by user) or restrict(case demo) some of the features in tester mode. I need this, because the main usage of my EA is in tester mode. Although it may be useful in real trading, the main purpose my EA is made, is to provide some backtesting benefits to the user. So, if the user has downloaded the demo version and she/he liked it, she/he may decide to pay some amount to unlock some additional features, which may be useful in tester mode(in real trade mode usage of demo version is not possible, according to Mql5 market terms).

That's all.

I have seen that some of the programs on the market here are working in this way, so it is possible and allowed. I just would like to know if my approach(the code above) is right, and if not, to receive some advice and direction how to accomplish this functionality.


Regards.

 

You don't have to take care of that - I guess. That's why Metaquotes offers their system of the Market.

Download from the Market a free EA or indicator and try to start it on a different (locale) terminal, e.g. a terminal that is paced in your own folder and has to be started in /portable-mode.

 
Carl Schreiber:

You don't have to take care of that - I guess. That's why Metaquotes offers their system of the Market.

Download from the Market a free EA or indicator and try to start it on a different (locale) terminal, e.g. a terminal that is paced in your own folder and has to be started in /portable-mode.


Either you don't understand my question or... what?


My question was how to get an information in runtime if the current instance of a paid EA has been bought, or not.

 
Boyan Taksirov:

Well, I do not want to implement my own licensing system. What I want is very simple.

1. Do detect in runtime if the current downloaded instance of the EA is already paid by the user, or not, according Mql5 market terms. If the user has paid for the EA in Mql5 market environment, or has downloaded only the demo version.

2. According to this information(paid or demo version), to allow(case paid by user) or restrict(case demo) some of the features in tester mode. I need this, because the main usage of my EA is in tester mode. Although it may be useful in real trading, the main purpose my EA is made, is to provide some backtesting benefits to the user. So, if the user has downloaded the demo version and she/he liked it, she/he may decide to pay some amount to unlock some additional features, which may be useful in tester mode(in real trade mode usage of demo version is not possible, according to Mql5 market terms).

That's all.

I have seen that some of the programs on the market here are working in this way, so it is possible and allowed. I just would like to know if my approach(the code above) is right, and if not, to receive some advice and direction how to accomplish this functionality.


Regards.

What's your problem actually ? You asked questions, but the code you posted is the answer to these questions.

Of course it works to check the licence type. If you want to test your code, just simulate the licence type to test.

 
Alain Verleyen:

What's your problem actually ? You asked questions, but the code you posted is the answer to these questions.

Of course it works to check the licence type. If you want to test your code, just simulate the licence type to test.


My problem was, that when I submitted an EA with a similar code for checking the license type, for moderator's approval, I received as an answer, that the EA stayed in demo mode.

Without further clarifications. The moderators advised me to search for an answer in this forum.

I put my question here, enclosing the corresponding part of the code, as I do now,  but I didn't receive an answer if the code I posted was working, or not.

So, I didn't know what to do further. I was convinced that my code was working, but the moderators insisted otherwise. I couldn't emulate their testing environment(communicating with Mql5 market server, etc.), and therefore obtain the same results as them. Of course, I could have been wrong in my former code, so now I post this one, in order to have enough confidence, before submitting the EA to the moderators.


You write, that the enclosed code does what it is meant for. Thank you, I am glad to read this.

So, I hope, that I do not have a problem anymore(hopefully).

 
Boyan Taksirov:


My problem was, that when I submitted an EA with a similar code for checking the license type, for moderator's approval, I received as an answer, that the EA stayed in demo mode.

Without further clarifications. The moderators advised me to search for an answer in this forum.

I put my question here, enclosing the corresponding part of the code, as I do now,  but I didn't receive an answer if the code I posted was working, or not.

So, I didn't know what to do further. I was convinced that my code was working, but the moderators insisted otherwise. I couldn't emulate their testing environment(communicating with Mql5 market server, etc.), and therefore obtain the same results as them. Of course, I could have been wrong in my former code, so now I post this one, in order to have enough confidence, before submitting the EA to the moderators.


You write, that the enclosed code does what it is meant for. Thank you, I am glad to read this.

So, I hope, that I do not have a problem anymore(hopefully).

I saw you were using the right functions but didn't check it in details. So I suggested you to test it. You don't need to emulate their testing environment, you just have to simulate the licence type.

input ENUM_LICENSE_TYPE licenseType;

Comment your "licenseType" initialization line. Try each value and check that it's doing what you want.

 

Your code:

MQLInfoInteger(MQL_LICENSE_TYPE)

should work correctly for experts and indicators. It did not work for scripts and libraries in past, and I don't have an updated information.

Your attept to read license from a file (in else branch) violates the Market rules, not to mention it seems having a flaw (a user can craft a file).

Reason: