Detected Country () : English
Protect EA and indicators with Password or Licensing - codingforex.com

Welcome to CodingForex.Com!

Knowledge portal where you can learn how to create forex indicators and robot.

Click button below to choose level that suite you:

Protect EA and indicators with Password or Licensing

Samples [2017-11-19 20:18:59] - by hillzx
Featured Image

There are several types of passwords that we can use include:

  1. Password static
  2. Password dynamic

Static password means the password is unchanged and will always be the same, while the dynamic password is a changeable password depending on who is using it. Usually this dynamic password uses the information element of the account, for example by Account Name or Account Number, so the password for each account will be different.

How to protect using static password :

1. Create 2 variables: password entered user and password that we have set

extern string InputPassword=""; //Ketik password anda
string StaticPassword="123ABC";

2. Make validation whether password match or not?

if (InputPassword!=StaticPassword){
  //Password ditolak
} else {
  //Password diterima
}

Here's the full code:

//+------------------------------------------------------------------+
//|                                              Password Static.mq4 |
//|                                                 hillzx@gmail.com |
//|                          https://www.facebook.com/groups/hillzx/ |
//+------------------------------------------------------------------+
#property copyright "hillzx@gmail.com"
#property link      "https://www.facebook.com/groups/hillzx/"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
 int Corner=0;
 int XPos=10;
 int YPos=20;
 int TextSize=14;
 color TextColor=White;
extern string InputPassword=""; //Ketik password anda
string StaticPassword="123ABC";

int OnInit()
  {
//--- indicator buffers mapping
JalankanProses();
//---
   return(INIT_SUCCEEDED);
  }
  
void OnDeinit(const int reason)
{
   DeleteObjects();
   return;
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
JalankanProses();
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+

void JalankanProses(){

if (InputPassword!=StaticPassword){
   ObjectCreate("text1",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("text1",OBJPROP_CORNER,Corner);
   ObjectSet("text1",OBJPROP_XDISTANCE,XPos);
   ObjectSet("text1",OBJPROP_YDISTANCE,YPos);
   ObjectSetText("text1","Maaf password ditolak",TextSize,"Verdana",Red);
} else {
   ObjectCreate("text1",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("text1",OBJPROP_CORNER,Corner);
   ObjectSet("text1",OBJPROP_XDISTANCE,XPos);
   ObjectSet("text1",OBJPROP_YDISTANCE,YPos);
   ObjectSetText("text1","Selamat password diterima!",TextSize,"Verdana",Lime);
   
   // Lakukan pekerjaan lainnya disini
}
}

void DeleteObjects()
{
  for (int i = ObjectsTotal() - 1; i > -1; i--)
  {
   if (StringFind(ObjectName(i), "text") >= 0) ObjectDelete(ObjectName(i));
  }
}



How to protect using dynamic password :

1. Create input variable password and secret code (secret code is whatever you want)

extern string InputPassword=""; //Ketik password anda
int KodeRahasia=123456;

2. Create a function for password validation

string DapatkanPasswordDynamic(){
int tmp1= (AccountNumber() / 2) + KodeRahasia ;
string tmp2 = IntegerToString(tmp1);
return tmp2;
}

Here's the complete code :

//+------------------------------------------------------------------+
//|                                             Password Dynamic.mq4 |
//|                                                 hillzx@gmail.com |
//|                          https://www.facebook.com/groups/hillzx/ |
//+------------------------------------------------------------------+
#property copyright "hillzx@gmail.com"
#property link      "https://www.facebook.com/groups/hillzx/"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
 int Corner=0;
 int XPos=10;
 int YPos=20;
 int TextSize=14;
 color TextColor=White;
extern string InputPassword=""; //Ketik password anda
int KodeRahasia=123456;

int OnInit()
  {
//--- indicator buffers mapping
JalankanProses();
//---
   return(INIT_SUCCEEDED);
  }
  
void OnDeinit(const int reason)
{
   DeleteObjects();
   return;
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
JalankanProses();
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+

void JalankanProses(){

if (InputPassword!=DapatkanPasswordDynamic()){
   ObjectCreate("text1",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("text1",OBJPROP_CORNER,Corner);
   ObjectSet("text1",OBJPROP_XDISTANCE,XPos);
   ObjectSet("text1",OBJPROP_YDISTANCE,YPos);
   ObjectSetText("text1","Maaf password ditolak",TextSize,"Verdana",Red);
} else {
   ObjectCreate("text1",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("text1",OBJPROP_CORNER,Corner);
   ObjectSet("text1",OBJPROP_XDISTANCE,XPos);
   ObjectSet("text1",OBJPROP_YDISTANCE,YPos);
   ObjectSetText("text1","Selamat password diterima!",TextSize,"Verdana",Lime);
   
   // Lakukan pekerjaan lainnya disini
}
}

void DeleteObjects()
{
  for (int i = ObjectsTotal() - 1; i > -1; i--)
  {
   if (StringFind(ObjectName(i), "text") >= 0) ObjectDelete(ObjectName(i));
  }
}

string DapatkanPasswordDynamic(){
int tmp1= (AccountNumber() / 2) + KodeRahasia ;
string tmp2 = IntegerToString(tmp1);
return tmp2;
}

Let us try, do not forget to share and follow our facebook and our youtube channel, happy trading!






- Provided by HiLLzSoft Studio -