Download MetaTrader 5

Protecting Account

To add comments, please log in or register
Baptiste George
528
Baptiste George  
Hello,

I have so many trouble since I create new EAs.

All previous code seems broken:



I use to do this way to protect my EA:

int acc=(int)AccountInfoInteger(ACCOUNT_LOGIN);
   if(acc==0)return 0; // HERE I HAVE AN ERROR
  
//  if(AccountInfoInteger(ACCOUNT_LOGIN)!=Login_Account||TimeCurrent()>allowed_until)
      if(TimeCurrent()>allowed_until)
      {
      //-----------------------------------------------------------------
      // License expired ... please use this
      //-----------------------------------------------------------------
         ObjectCreate("Rect_20",OBJ_RECTANGLE_LABEL,0,0,0);
         ObjectSetInteger(0,"Rect_20",OBJPROP_XDISTANCE,0);
         ObjectSetInteger(0,"Rect_20",OBJPROP_YDISTANCE,0);
         ObjectSetInteger(0,"Rect_20",OBJPROP_XSIZE,1500); // Longueur
         ObjectSetInteger(0,"Rect_20",OBJPROP_YSIZE,1000); // largeur
         ObjectSetInteger(0,"Rect_20",OBJPROP_BGCOLOR,White); // clrPaleTurquoise C'236,233,216'
         ObjectSetInteger(0,"Rect_20",OBJPROP_BORDER_TYPE,BORDER_FLAT); // BORDER_FLAT BORDER_RAISED BORDER_SUNKEN
         string License =  "Wrong account or License has expired...", "\n", " TEST";
        
         // License
         ObjectCreate("License",OBJ_LABEL,0,0,0);                                
         ObjectSetInteger(0,"License",OBJPROP_XDISTANCE,200);                    
         ObjectSetInteger(0,"License",OBJPROP_YDISTANCE,200);                    
         ObjectSetText("License", "Wrong account or License has expired...", 12, "Times New Roman", Black);
        
         // License_1
         ObjectCreate("License_1",OBJ_LABEL,0,0,0);                                
         ObjectSetInteger(0,"License_1",OBJPROP_XDISTANCE,200);                    
         ObjectSetInteger(0,"License_1",OBJPROP_YDISTANCE,250);                    
         ObjectSetText("License_1", "Please contact CrazyTrader:", 12, "Times New Roman", Black);
        
         // Email
         ObjectCreate("Email",OBJ_LABEL,0,0,0);                                
         ObjectSetInteger(0,"Email",OBJPROP_XDISTANCE,200);                    
         ObjectSetInteger(0,"Email",OBJPROP_YDISTANCE,300);                    
         ObjectSetText("Email", "baptiste.george15@gmail.com", 12, "Times New Roman", Black);
    

      //----
      return 0; // HERE I HAVE AN ERROR
      }


I have 2 erros on "return".

I can put them in comment... but if the account is wrong... It will warn the license as expired... but the EA could still be working right?



Actually I made a backest... and it did open trades : (



Please advice



Regards
Marco vd Heijden
Moderator
5667
Marco vd Heijden  
Maybe try this

if(acc==0)return (0); // HERE I HAVE AN ERROR
return (0); // HERE I HAVE AN ERROR
or

return (false); // HERE I HAVE AN ERROR
Baptiste George
528
Baptiste George  
Hi,



still not working:


I got the following error:


'return' - 'void' function returns a value  
Marco vd Heijden
Moderator
5667
Marco vd Heijden  
Well thats obvious then.

Is it part of a void function ?
Max Enrik
988
Max Enrik  
Frenchytrader:
still not working:
Are you sure that errors comes from them?
Ziheng Zhuang
5000
Ziheng Zhuang  

Please note the AccountInfoInteger sometimes returns zero when EA just load or the MT4 is not connected with server.

Baptiste George
528
Baptiste George  
I print acc... it gets correct account number



I'm sure the error pops up when I added this code.



It says the error line as well.



What to do?



Please advice how to protect
Marco vd Heijden
Moderator
5667
Marco vd Heijden  
int acc=(int)AccountInfoInteger(ACCOUNT_LOGIN);
   if(acc==0)
    {
     MessageBox("Warning! Invalid Account Number","Warning!",MB_OK);
     ExpertRemove();
    }
  
//  if(AccountInfoInteger(ACCOUNT_LOGIN)!=Login_Account||TimeCurrent()>allowed_until)
      if(TimeCurrent()>allowed_until)
      {
      //-----------------------------------------------------------------
      // License expired ... please use this
      //-----------------------------------------------------------------
         ObjectCreate("Rect_20",OBJ_RECTANGLE_LABEL,0,0,0);
         ObjectSetInteger(0,"Rect_20",OBJPROP_XDISTANCE,0);
         ObjectSetInteger(0,"Rect_20",OBJPROP_YDISTANCE,0);
         ObjectSetInteger(0,"Rect_20",OBJPROP_XSIZE,1500); // Longueur
         ObjectSetInteger(0,"Rect_20",OBJPROP_YSIZE,1000); // largeur
         ObjectSetInteger(0,"Rect_20",OBJPROP_BGCOLOR,White); // clrPaleTurquoise C'236,233,216'
         ObjectSetInteger(0,"Rect_20",OBJPROP_BORDER_TYPE,BORDER_FLAT); // BORDER_FLAT BORDER_RAISED BORDER_SUNKEN
         string License =  "Wrong account or License has expired...", "\n", " TEST";
        
         // License
         ObjectCreate("License",OBJ_LABEL,0,0,0);                                
         ObjectSetInteger(0,"License",OBJPROP_XDISTANCE,200);                    
         ObjectSetInteger(0,"License",OBJPROP_YDISTANCE,200);                    
         ObjectSetText("License", "Wrong account or License has expired...", 12, "Times New Roman", Black);
        
         // License_1
         ObjectCreate("License_1",OBJ_LABEL,0,0,0);                                
         ObjectSetInteger(0,"License_1",OBJPROP_XDISTANCE,200);                    
         ObjectSetInteger(0,"License_1",OBJPROP_YDISTANCE,250);                    
         ObjectSetText("License_1", "Please contact CrazyTrader:", 12, "Times New Roman", Black);
        
         // Email
         ObjectCreate("Email",OBJ_LABEL,0,0,0);                                
         ObjectSetInteger(0,"Email",OBJPROP_XDISTANCE,200);                    
         ObjectSetInteger(0,"Email",OBJPROP_YDISTANCE,300);                    
         ObjectSetText("Email", "baptiste.george15@gmail.com", 12, "Times New Roman", Black);
        
         ExpertRemove();
      }
//---
honest_knave
Moderator
2318
honest_knave  
Ziheng Zhuang:

Please note the AccountInfoInteger sometimes returns zero when EA just load or the MT4 is not connected with server.

Yes, it is very common for EAs and Indicators to run these checks before connecting to your broker e.g. upon terminal start.

You'll need to cater for such eventualities unless you want the frustration of your EA removing itself because it ran the check too soon.

Marco vd Heijden
Moderator
5667
Marco vd Heijden  
So you can check TerminalInfoInteger()

TERMINAL_CONNECTED

Connection to a trade server

bool


Before.
Baptiste George
528
Baptiste George  
Marco vd Heijden:
int acc=(int)AccountInfoInteger(ACCOUNT_LOGIN);
   if(acc==0)
    {
     MessageBox("Warning! Invalid Account Number","Warning!",MB_OK);
     ExpertRemove();
    }
  
//  if(AccountInfoInteger(ACCOUNT_LOGIN)!=Login_Account||TimeCurrent()>allowed_until)
      if(TimeCurrent()>allowed_until)
      {
      //-----------------------------------------------------------------
      // License expired ... please use this
      //-----------------------------------------------------------------
         ObjectCreate("Rect_20",OBJ_RECTANGLE_LABEL,0,0,0);
         ObjectSetInteger(0,"Rect_20",OBJPROP_XDISTANCE,0);
         ObjectSetInteger(0,"Rect_20",OBJPROP_YDISTANCE,0);
         ObjectSetInteger(0,"Rect_20",OBJPROP_XSIZE,1500); // Longueur
         ObjectSetInteger(0,"Rect_20",OBJPROP_YSIZE,1000); // largeur
         ObjectSetInteger(0,"Rect_20",OBJPROP_BGCOLOR,White); // clrPaleTurquoise C'236,233,216'
         ObjectSetInteger(0,"Rect_20",OBJPROP_BORDER_TYPE,BORDER_FLAT); // BORDER_FLAT BORDER_RAISED BORDER_SUNKEN
         string License =  "Wrong account or License has expired...", "\n", " TEST";
        
         // License
         ObjectCreate("License",OBJ_LABEL,0,0,0);                                
         ObjectSetInteger(0,"License",OBJPROP_XDISTANCE,200);                    
         ObjectSetInteger(0,"License",OBJPROP_YDISTANCE,200);                    
         ObjectSetText("License", "Wrong account or License has expired...", 12, "Times New Roman", Black);
        
         // License_1
         ObjectCreate("License_1",OBJ_LABEL,0,0,0);                                
         ObjectSetInteger(0,"License_1",OBJPROP_XDISTANCE,200);                    
         ObjectSetInteger(0,"License_1",OBJPROP_YDISTANCE,250);                    
         ObjectSetText("License_1", "Please contact CrazyTrader:", 12, "Times New Roman", Black);
        
         // Email
         ObjectCreate("Email",OBJ_LABEL,0,0,0);                                
         ObjectSetInteger(0,"Email",OBJPROP_XDISTANCE,200);                    
         ObjectSetInteger(0,"Email",OBJPROP_YDISTANCE,300);                    
         ObjectSetText("Email", "baptiste.george15@gmail.com", 12, "Times New Roman", Black);
        
         ExpertRemove();
      }
//---
Working in a wonderfull way : )



Thank you all
To add comments, please log in or register