Jun 15, 2009

Protect MQ4

Without protecting your MQL4 code it will be waste of time to try to commercialize your programs, that's why I'm writing this article.

Source code verse binary:

Just as a review and to emphasis that we are talking about how to protect the .ex4 files read the next section:
There are two kinds of files that you use with MetaTrader; the program files and the executable files:

The program files are normal text files but have one of these extensions: .mq4 and .mgh.
These files are the source code of the programs wrote in MQL4 programming language; source code means they could be opened for viewing or editing in MetaEditor.

The executable files are binary files (you can't open them for viewing or editing) and has the extension .ex4.
These files are the result of compiling the .mq4 files using MetaEditor, and these are the files that you can load them in MetaTrader and use them.

Compiling is an operation taken by a special program (called a compiler) to convert the program from text (readable) format to the binary format which the computer can understand (computers think in binary).
This is the general definition of compiling. Compiling in our case is converting the mq4 files to ex4 for file using MetaEditor program.

We are doing this by opening the mq4 files in MetaEditor then pressing F5 hot key. MetaEditor will compile (convert) the file to ex4 format and keeping the mq4 file untouched MetaEditor will place the generated ex4 file at the same path as the mq4 file. We compile the mq4 files because the MetaTrader can't load any files except ex4 files.

The source code of MQL4 programs can't be protect because it's in text format and when you distribute it you intend to give the receiver the access to the source code of the program.
The executable version of the program is the only version that you can protect it. You protect it by write the protection code in the source code of the program then compile it to the ex4 format then distribute it to the user.

Kinds (ideas) of the protection:

We are going to discuss some ideas of MQL4 programs protection, maybe they are not the best but they are the common ideas, we are going to write some code to apply these ideas:
Password protection code:

This the widely used method to protect softwares in general and can be used to protect MQL4 programs.
When the user buy your program you send him the program with a password and he can use the program without the password.

This is a simple code to apply password protection method:

int start() {
    extern string Please_Enter_Password = "0";
   // your code here.... --- Put your code here ----
int start() {
    if (password != "viva metatrader")  {  //change to the password you give the user!
       Alert ("Wrong password!");
    return (0);
    }
   // your code here.... --- Put your code here ----
}

In the code above the password is "viva metatrader" which is hard coded in the MQL4 file. You have to compile the program after adding this piece of code and send it to the user with the password.

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 code here.... --- Put your code here ----
   return(0);
}

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 code here.... --- Put your normal code here ----
return(0);
}

Limited account type protection: 

In this method of protection you will allow the user to use the program in demo mode only and prevent him to use the program in live trading.
It's not strong protection because the user can host the program in another instance of MetaTrader that runs in demo mode and trade manually in the real account instance.

int start() {
    bool demo_account = IsDemo();
    if (!demo_account) {
         Alert ("You can not use the program with a real account!");
         return(0);
    }  
// your code here.... --- Put your normal code here ----
return(0);
}

Re-Edit From : http://www.metatrader.info

-EOF-
... read More !..

Search By Google



Here You can find Tutorial How to Trade in Forex Market... Especialy For Newbies

Who Ami

My Photo
Praetorian'Fx
Bandung, JB, Indonesia
My Desc was Simple $o$ :::>>> Low Profile High Profit
View my complete profile

Sponsored By


Tutorial Forex

Delivered By

Forex News