Help on adding expiration date to script and account number registration

 
Hello programmers, P
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX||
string Expired_com= "Demo Version HAS EXPIRED ";
bool ExpiredTime_ON=true;
int eyear=2050;  int emonth=12 ;  int expired_date=31; //Expired Time 


  if(ExpiredTime_ON)
     {
      if((Year()>eyear) || (Year()==eyear && Month()>emonth) || (Year()==eyear && Month()==emonth && Day()>expired_date))
        {

         if(ObjectFind("expiredlabel") != 0)
           {
            ObjectCreate("expiredlabel", OBJ_LABEL, 0,0,0);
            ObjectSetText("expiredlabel",Expired_com,14, "Impact", Red);
            ObjectSet("expiredlabel", OBJPROP_XDISTANCE,5);
            ObjectSet("expiredlabel", OBJPROP_YDISTANCE,30);
            ObjectSet("expiredlabel", OBJPROP_CORNER, 0);

            ObjectCreate("Contact_Me", OBJ_LABEL, 0,0,0);
            ObjectSetText("Contact_Me",Contact_Person,14, "Impact", SkyBlue);
            ObjectSet("Contact_Me", OBJPROP_XDISTANCE,5);
            ObjectSet("Contact_Me", OBJPROP_YDISTANCE,50);
            ObjectSet("Contact_Me", OBJPROP_CORNER, 0);
           }
        // return(0);
        }

lease I need some help in adding an expiration date to my script. I used the code below but even after the expiration time the script still runs. Additionally, I will love to restrict the script to running only on some accounts numbers so it will not run with on every account except that which has been added in the source file. In help in this direction will be highly appreciated. thanks
 
//+------------------------------------------------------------------+
//|                                         TimeLimitProtectedEA.mq5 |
//|                                      Copyright 2012, Investeo.pl |
//|                                           http://www.investeo.pl |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, Investeo.pl"
#property link      "http://www.investeo.pl"
#property version   "1.00"
                           
datetime allowed_until = D'2012.02.11 00:00'; 
                             
int password_status = -1;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   printf("This EA is valid until %s", TimeToString(allowed_until, TIME_DATE|TIME_MINUTES));
   datetime now = TimeCurrent();
   
   if (now < allowed_until) 
         Print("EA time limit verified, EA init time : " + TimeToString(now, TIME_DATE|TIME_MINUTES));
   
    
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
  if (TimeCurrent() < allowed_until) 
    {        
    }
   else Print("EA expired."); 
  }
 
Gabriel Nsor #:
if (now < allowed_until)

If you use this logic (positive confirmation) allowed_until must be in the future.

I tested it with a future date and it worked. 

datetime allowed_until = D'2024.02.11 00:00'; 

With past dates it detects expiry. This bit works ok too

   if(TimeCurrent() < allowed_until)
 
Gabriel Nsor:
Additionally, I will love to restrict the script to running only on some accounts numbers so it will not run with on every account except that which has been added in the source file. In help in this direction will be highly appreciated. thanks

Easy enough - the simplest way is to create a delimited string of the allowed accounts numbers and use StringFind() to check if the current account is in the list - you could do the opposite if you want to create an exclusion list.

An Array of account numbers is a bit more elegant, but needs a little more coding - if your list of account numbers is not too large, a string is easiest. If it runs just once during OnInit() it is unlikely to affect performance later on.

 
R4tna C #:

Easy enough - the simplest way is to create a delimited string of the allowed accounts numbers and use StringFind() to check if the current account is in the list - you could do the opposite if you want to create an exclusion list.

An Array of account numbers is a bit more elegant, but needs a little more coding - if your list of account numbers is not too large, a string is easiest. If it runs just once during OnInit() it is unlikely to affect performance later on.

Thanks so very much sir for your response! Let me apply your suggestion.
 
Please I'm using the code below to restrict account numbers and it works perfectly on EAs but doesn't seem to work on my script.. don't know if there's an additional code I need to add?? The script still places and modifies orders on accounts that are not included unlike the EA 
 
//+------------------------------------------------------------------+
//|                                           AccountProtectedEA.mq5 |
//|                                      Copyright 2012, Investeo.pl |
//|                                           http://www.investeo.pl |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, Investeo.pl"
#property link      "http://www.investeo.pl"
#property version   "1.00"


const string allowed_broker = "MetaQuotes Software Corp.";
const long allowed_accounts[] = { 979890, 436290, 646490, 225690, 279260 };
                             
int password_status = -1;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   string broker = AccountInfoString(ACCOUNT_COMPANY);
   long account = AccountInfoInteger(ACCOUNT_LOGIN);
   
   printf("The name of the broker = %s", broker);
   printf("Account number =  %d", account);
   
   if (broker == allowed_broker) 
      for (int i=0; i<ArraySize(allowed_accounts); i++)
       if (account == allowed_accounts[i]) { 
         password_status = 1;
         Print("EA account verified");
         break;
       }
   if (password_status == -1) Print("EA is not allowed to run on this account."); 
    
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
  if (password_status == 1) 
  {
    // password correct
  } 
  }
 

The first thing to do is use braces {} - omitting them has no benefit in my opinion

The MQL editor automatically generates code like this:

  if(condition)
    {
     for(int i=0;i<total;i++)
       {
        if(condition)
          {
           
          }
        
       }
    }


This section of code should be made to follow that pattern - try that and see if it fixes the issue. If not, debug it

if (broker == allowed_broker) 
      for (int i=0; i<ArraySize(allowed_accounts); i++)
       if (account == allowed_accounts[i]) { 
         password_status = 1;
         Print("EA account verified");
         break;
       }
 
R4tna C #:

The first thing to do is use braces {} - omitting them has no benefit in my opinion

The MQL editor automatically generates code like this:


This section of code should be made to follow that pattern - try that and see if it fixes the issue. If not, debug it

Thanks a zillion sir! Let me apply that 
Reason: