The program files are normal text files but have one of these extensions: .mq4.
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.
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.
There are some ideas of MQL4 programs protection: Password protection, Trial period protection, Limited account number protection, Limited account type protection and DLL protection.
But the DLL protection is the best ideas.
The method to add protect code in
MQL4 language
(Just for demo version)
1. In the front of MQL4 language, you should add code as below:
//////----Add code below----------
#import "mt4whgs.dll"
int MT4WH(string testlock);
#import
int Ret;
string testlock = "abcdefghijklmnopqrstuvwxyz01234567890987654321";
//////----Add code above-----------
2. In function init(), you should add:
//////----Add code below----------
Ret = MT4WH(testlock);
if(Ret == -1) return(0);
if(Ret != 0) return(0);
//////----Show Date limit-------
string Date_Limit="Date limit: " +
DoubleToStr(StringGetChar(testlock,12),0) + "/" +
DoubleToStr(StringGetChar(testlock,13),0) + "/"+
DoubleToStr(StringGetChar(testlock,11)+2000,0);
ObjectDelete("Show_Date_Limit");
ObjectCreate("Show_Date_Limit",OBJ_LABEL , 0, 0, 0 );
ObjectSet ("Show_Date_Limit",OBJPROP_CORNER , 2);
ObjectSet ("Show_Date_Limit",OBJPROP_XDISTANCE , 0);
ObjectSet ("Show_Date_Limit",OBJPROP_YDISTANCE , 5);
ObjectSet ("Show_Date_Limit",OBJPROP_BACK , True );
ObjectSetText("Show_Date_Limit", Date_Limit, 9, "Arial", Yellow);
//////----Add code above-----------
3. In function deinit(), you should add:
int deinit()
{
//////----Add code below----------
ObjectDelete("Show_Date_Limit");
//////----Add code above-----------
return(0);
}
4、In function start(), you should add:
//////----Add code below----------
if(Ret != 0) return(0);
if(StringGetChar(testlock,0)!= 9) return(0);
if(StringGetChar(testlock,1)!= 4) return(0);
if(StringGetChar(testlock,2)!= 8) return(0);
if(StringGetChar(testlock,3)!= 5) return(0);
if(StringGetChar(testlock,4)!= 5) return(0);
//////----Add code above-----------
5、Example of CCI.mq4
//+------------------------------------------------------------------+
//| CCI.mq4 |
//| Copyright ?2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 LightSeaGreen
//---- input parameters
extern int CCIPeriod = 14;
//---- buffers
double CCIBuffer[];
double RelBuffer[];
double DevBuffer[];
double MovBuffer[];
//////----Add code below----------
#import "mt4whgs.dll"
int MT4WH(string testlock);
#import
int Ret;
string testlock = "abcdefghijklmnopqrstuvwxyz01234567890987654321";
//////----Add code above-----------
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//////----Add code below----------
Ret = MT4WH(testlock);
if(Ret == -1) return(0);
if(Ret != 0) return(0);
//////----Show Date limit-------
string Date_Limit="Date limit: " +
DoubleToStr(StringGetChar(testlock,12),0) + "/" +
DoubleToStr(StringGetChar(testlock,13),0) + "/"+
DoubleToStr(StringGetChar(testlock,11)+2000,0);
ObjectDelete("Show_Date_Limit");
ObjectCreate("Show_Date_Limit",OBJ_LABEL , 0, 0, 0 );
ObjectSet ("Show_Date_Limit",OBJPROP_CORNER , 2);
ObjectSet ("Show_Date_Limit",OBJPROP_XDISTANCE , 0);
ObjectSet ("Show_Date_Limit",OBJPROP_YDISTANCE , 5);
ObjectSet ("Show_Date_Limit",OBJPROP_BACK , True );
ObjectSetText("Show_Date_Limit", Date_Limit, 9, "Arial", Yellow);
//////----Add code above-----------
string short_name;
//---- 3 additional buffers are used for counting.
IndicatorBuffers(4);
SetIndexBuffer(1, RelBuffer);
SetIndexBuffer(2, DevBuffer);
SetIndexBuffer(3, MovBuffer);
//---- indicator lines
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, CCIBuffer);
//----
if(CCIPeriod <= 0)
CCIPeriod = 14;
//----
SetIndexDrawBegin(0, CCIPeriod);
//---- name for DataWindow and indicator subwindow label
short_name="CCI(" + CCIPeriod + ")";
IndicatorShortName(short_name);
SetIndexLabel(0, short_name);
return(0);
}
int deinit()
{
//////----Add code below----------
ObjectDelete("Show_Date_Limit");
//////----Add code above-----------
return(0);
}
//+------------------------------------------------------------------+
//| Commodity Channel Index |
//+------------------------------------------------------------------+
int start()
{
//////----Add code below----------
if(Ret != 0) return(0);
if(StringGetChar(testlock,0)!= 9) return(0);
if(StringGetChar(testlock,1)!= 4) return(0);
if(StringGetChar(testlock,2)!= 8) return(0);
if(StringGetChar(testlock,3)!= 5) return(0);
if(StringGetChar(testlock,4)!= 5) return(0);
//////----Add code above-----------
int i, k, counted_bars = IndicatorCounted();
double price, sum, mul;
if(CCIPeriod <= 1)
return(0);
if(Bars <= CCIPeriod)
return(0);
//---- initial zero
if(counted_bars < 1)
{
for(i = 1; i <= CCIPeriod; i++)
CCIBuffer[Bars-i] = 0.0;
for(i = 1; i <= CCIPeriod; i++)
DevBuffer[Bars-i] = 0.0;
for(i = 1; i <= CCIPeriod; i++)
MovBuffer[Bars-i] =0.0;
}
//---- last counted bar will be recounted
int limit = Bars - counted_bars;
if(counted_bars > 0)
limit++;
//---- moving average
for(i = 0; i < limit; i++)
MovBuffer[i] = iMA(NULL, 0, CCIPeriod, 0, MODE_SMA, PRICE_TYPICAL, i);
//---- standard deviations
i = Bars - CCIPeriod + 1;
if(counted_bars > CCIPeriod - 1)
i = Bars - counted_bars - 1;
mul = 0.015 / CCIPeriod;
while(i >= 0)
{
sum = 0.0;
k = i + CCIPeriod - 1;
while(k >= i)
{
price =(High[k] + Low[k] + Close[k]) / 3;
sum += MathAbs(price - MovBuffer[i]);
k--;
}
DevBuffer[i] = sum*mul;
i--;
}
i = Bars - CCIPeriod + 1;
if(counted_bars > CCIPeriod - 1)
i = Bars - counted_bars - 1;
while(i >= 0)
{
price = (High[i] + Low[i] + Close[i]) / 3;
RelBuffer[i] = price - MovBuffer[i];
i--;
}
//---- cci counting
i = Bars - CCIPeriod + 1;
if(counted_bars > CCIPeriod - 1)
i = Bars - counted_bars - 1;
while(i >= 0)
{
if(DevBuffer[i] == 0.0)
CCIBuffer[i] = 0.0;
else
CCIBuffer[i] = RelBuffer[i] / DevBuffer[i];
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Anti- EX4-MQ4 Decompiler: The
method to protect ex4 file
http://www.zlocksoft.com/english
We can protect the *.ex4 files from ex4-mq4 decompiler. If you want protect it, you should give me your mq4 or ex4 files.

Anti- EX4-MQ4 Decompiler: The
method to write mq4 code to dll
http://www.zlocksoft.com/english
(Just for demo version)
The sample of write CCI.mq4 to DLL
The int start() of CCI.mq4 as below:
//+------------------------------------------------------------------+
int start()
{
int i, k, counted_bars = IndicatorCounted();
double price, sum, mul;
if(CCIPeriod <= 1)
return(0);
if(Bars <= CCIPeriod)
return(0);
//---- initial zero
if(counted_bars < 1)
{
for(i = 1; i <= CCIPeriod; i++)
CCIBuffer[Bars-i] = 0.0;
for(i = 1; i <= CCIPeriod; i++)
DevBuffer[Bars-i] = 0.0;
for(i = 1; i <= CCIPeriod; i++)
MovBuffer[Bars-i] =0.0;
}
//---- last counted bar will be recounted
int limit = Bars - counted_bars;
if(counted_bars > 0)
limit++;
//---- moving average
for(i = 0; i < limit; i++)
MovBuffer[i] = iMA(NULL, 0, CCIPeriod, 0, MODE_SMA, PRICE_TYPICAL, i);
//---- standard deviations
i = Bars - CCIPeriod + 1;
if(counted_bars > CCIPeriod - 1)
i = Bars - counted_bars - 1;
mul = 0.015 / CCIPeriod;
while(i >= 0)
{
sum = 0.0;
k = i + CCIPeriod - 1;
while(k >= i)
{
price =(High[k] + Low[k] + Close[k]) / 3;
sum += MathAbs(price - MovBuffer[i]);
k--;
}
DevBuffer[i] = sum*mul;
i--;
}
i = Bars - CCIPeriod + 1;
if(counted_bars > CCIPeriod - 1)
i = Bars - counted_bars - 1;
while(i >= 0)
{
price = (High[i] + Low[i] + Close[i]) / 3;
RelBuffer[i] = price - MovBuffer[i];
i--;
}
//---- cci counting
i = Bars - CCIPeriod + 1;
if(counted_bars > CCIPeriod - 1)
i = Bars - counted_bars - 1;
while(i >= 0)
{
if(DevBuffer[i] == 0.0)
CCIBuffer[i] = 0.0;
else
CCIBuffer[i] = RelBuffer[i] / DevBuffer[i];
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
When we write it to DLL, it will be:
//+------------------------------------------------------------------+
int start()
{
double Zlock[][6];
ArrayCopyRates(Zlock);
ZlockSoft_com(Zlock,IndicatorCounted(),
Bars, CCIPeriod, CCIBuffer,
RelBuffer, DevBuffer, MovBuffer);
return(0);
}
//+------------------------------------------------------------------+
We use one row code ( red ) take the place
of original 50 rows code. Thus, if someone turns the ex4 to mq4 by
EX4-MQ4 decompiler, he will not understand how the
ZlockSoft_com() to work, and the function
ZlockSoft_com() can’t work if not been registed.
If you want to protect your mq4 by this method, you must give me your
all or part of mq4 files. I can write a special DLL function for your
mq4 code. Please trust to me, I will not use or sold your mq4 code.