Download MetaTrader 5
To add comments, please log in or register
All MQL5.community events are grouped together. Have a look at the Wall!
Carl Allen
14
Carl Allen 2010.02.28 22:45 

Greetings,

I've tried using both of the MQL4 program protections from the metatrader development

course and neither one works in my indicators. One is for account protection and the other

is for trials. I'm thinking maybe recent updates may have changed something since 2005. If

someone could make the necessary corrections to these it would greatly be appreciated.

Thanks

Carl

Limited account number protection:

In this method of protection you will ask the user to give you his account number and you write the following code to prevent the program to work with another accounts:

int start()
{

int hard_accnt = 11111; //<-- type the user account here before compiling
int accnt = AccountNumber();

if (accnt != hard_accnt)
{
Alert ("You can not use this account (" + DoubleToStr(accnt,0) + ") with this program!");
return(0);
}
// your normal code!
return(0);
}

Trial period protection:

If you want to give the user of the program a try-before-buy program you can limit the usage of your program by limited period of time and after this period the program will not work.
Use the code below to limit your program for period of time.

int start()
{
string expire_date = "2006.31.06"; //<-- hard coded datetime
datetime e_d = StrToTime(expire_date);

if (CurTime() >= e_d)
{
Alert ("The trial version has been expired!");
return(0);
}
// your normal code!
return(0);
}

Thanks

Carl

gordon
2322
gordon 2010.03.01 03:58  

Dallas4lr wrote >>

I've tried using both of the MQL4 program protections from the metatrader development

course and neither one works in my indicators. One is for account protection and the other

is for trials. I'm thinking maybe recent updates may have changed something since 2005. If

someone could make the necessary corrections to these it would greatly be appreciated.

Your code seems fine and should work... What makes u think it doesn't work? What are u expecting?

Note that both these 'protection methods' are extremely easy to break... There are many websites offering MQL4 decompiling services for a few dollars. The easiest way to protect your code is to not distribute it or the compiled files to anybody.


Next time:


Carl Allen
14
Carl Allen 2010.03.01 06:06  

gordon,

When I place the account code in my indicator with the proper account in the codeing and open MT4, it generates in error on the platform "You can not use this account with this program"

. if I hit compile in editor and manually apply the indicator it works. But if I close the program again and reopen it generates the error.

The trial continues to work in my indicators even if I place a date in that has already past. I now these are easy to crack, but if I could get these to work they will do for now. Could you

possibly post the code for a indicator with both of these imbedded where they function. Maybe if I see a totally function version of the two I can figure out why they dont work on my indicators.

Thanks

Carl

gordon
2322
gordon 2010.03.01 06:23  
Dallas4lr:

gordon,

When I place the account code in my indicator with the proper account in the codeing and open MT4, it generates in error on the platform "You can not use this account with this program"

. if I hit compile in editor and manually apply the indicator it works. But if I close the program again and reopen it generates the error.

The trial continues to work in my indicators even if I place a date in that has already past.

Thanks

Carl

The indicator is being loaded immediately when the Terminal starts, but it takes Terminal 1-2 seconds to connect to the broker; during those seconds AccountNumber() returns 0 which is not equal to hard_accnt, hence the alert is triggered. The moment the Terminal is connected to the broker, the alert stops and the indicator works properly.

The code in the book is supposed to be used in an expert adviser and not in an indicator. Experts do not start functioning immediately when Terminal starts, but only after Terminal is connected to broker, hence they do not have this problem of AccountNumber() returning zero in those first 2 seconds...


Regarding the 'trial period protection' - it works just fine for me. Are u sure u r using it properly?

Carl Allen
14
Carl Allen 2010.03.01 06:56  

Gordon,

You are right on both counts the account protection works after the 2 sec startup, and I had the month and day fields swaaped on the trial.

So they both work.

Thanks

gordon
2322
gordon 2010.03.01 07:11  
Dallas4lr:

Gordon,

You are right on both counts the account protection works after the 2 sec startup, and I had the month and day fields swaaped on the trial.

So they both work.

Thanks

Note that there is no reason to use StrToTime(), u can input datetime directly like so:

datetime e_d = D'2006.06.30';

See examples here -> https://docs.mql4.com/basis/types/datetime.


There is also no need to use DoubleToStr(...,0) for integers, since integer will be cast to string automatically (with no loss). For doubles u should only use DoubleToStr() if u want it to print differently than the default precision -> https://docs.mql4.com/common/Print.

/
To add comments, please log in or register