How to Set An EA To Expire in EX4 Format?

 
I am new to coding and would like to add a code to expire an EA in say 10 days. How do I do this?

Thank you
 
tcr1016:
I am new to coding and would like to add a code to expire an EA in say 10 days. How do I do this?

Thank you
I tried this code, but did not work. What did I do wrong? If not where should I put it?
string expire_date = "2006.06.11";
datetime e_d = StrToTime(expire_date);
 
if (CurTime() >= e_d)
{
Alert ("The trial version has been expired!");
return(0);
}
 

That part should work, depending on where you put it in your program.

Post all your code so we can see what else you are doing,

 
phy:

That part should work, depending on where you put it in your program.

Post all your code so we can see what else you are doing,

I am getting errors and it does not work. Help
extern string ExpertName = "Close All Open & Pending Trades";
 
string expire_date = "2006.06.11";
datetime e_d = StrToTime(expire_date);
 
if (CurTime() >= e_d)
{
Alert ("The trial version has been expired!");
return(0);
}
//Start++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int start()
{
  int total = OrdersTotal();
  for(int i=total-1;i>=0;i--)
  {
    OrderSelect(i, SELECT_BY_POS);
    int type   = OrderType();
 
    bool result = false;
    
    switch(type)
    {
      //Close opened long positions
      case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
                          break;
      
      //Close opened short positions
      case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
                          break;
 
      //Close pending orders
      case OP_BUYLIMIT  :
      case OP_BUYSTOP   :
      case OP_SELLLIMIT :
      case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
    }
    
    if(result == false)
    {
      Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
      Sleep(3000);
    }  
  }
  
  return(0);
}
 

Are you trying to create a script or an indicator?

Ah, an EA... Ok...

Put your expiration code after start(){

 
phy:

Are you trying to create a script or an indicator?

Ah, an EA... Ok...

Put your expiration code after start(){

Is there a way the expiration countdown can start when they first attach it to a chart? Say 10 days after they first activate the EA?
 

Yes. Examples:

---

(easy)

Have the EA create a file containing the time of the first run. (this is easy to defeat, if they know it is there)

Have the EA check for existence of the file, if it is there, read it, if not there create it.

Use the date in the file.

---

(hard)

Create a DLL

Have it "phone home" to your server for permission, accessing a database of your authorized users.

---

 
phy:

Yes. Examples:

---

(easy)

Have the EA create a file containing the time of the first run. (this is easy to defeat, if they know it is there)

Have the EA check for existence of the file, if it is there, read it, if not there create it.

Use the date in the file.

---

(hard)

Create a DLL

Have it "phone home" to your server for permission, accessing a database of your authorized users.

---

I would rather have a file to be created when the EA is activated in say a hidden file burried somewhere in another folder no one would look. Then it starts the countdown. What is the code for that? Could I also choose what folder it goes into?? I am really new at coding. Your first code was easy to understand.
 

See MQL4 Reference File Functions and read up, give some of the functions a try, you probably won't hurt anything

 
do you have a link on how to do it??
 
tcr1016:
do you have a link on how to do it??

tcr1016:
phy:

Yes. Examples:

---

(easy)

Have the EA create a file containing the time of the first run. (this is easy to defeat, if they know it is there)

Have the EA check for existence of the file, if it is there, read it, if not there create it.

Use the date in the file.

---

(hard)

Create a DLL

Have it "phone home" to your server for permission, accessing a database of your authorized users.

---

I would rather have a file to be created when the EA is activated in say a hidden file burried somewhere in another folder no one would look. Then it starts the countdown. What is the code for that? Could I also choose what folder it goes into?? I am really new at coding. Your first code was easy to understand.
If you can code it I can shoot you $25.00. How does that sound?
Reason: