Trader’s Tech – Writing Your Own EA Part 100 – EA Expiration Dates

Forex Robot If you’re new to this series and want to check it out from the beginning, you can find that here. And look here for a list of all the programming articles.

In Part 99 we wrapped out discussion of price and trade size validation. As promised, this time we’ll talk about setting expiration dates in your code.

Why have an expiration date? Well, one reason is for added security for your EA. If it expires periodically, bootleg copies of your EA will stop working. But this is not my primary reason for expiring my EAs. In fact, anyone with sufficient technical expertise could easily defeat an expiration date on an EA (unless it was included in a DLL – we’ll discuss that in a future installment.) A more important reason for expiring my EAs is to force the users to upgrade to the latest version. Many times, nagging bugs have been corrected in newer versions, but users will continue to use the old, buggy version of the EA and not take the trouble of updating. As a result, your EA gets a bad reputation because of bugs that have long since been fixed.

So, here’s what we do to cause an EA to expire. It’s only a few lines of code and it’s pretty easy to implement. We start by declaring the datetime variable ExpireDate:

datetime ExpireDate=D'2014.01.10 00:01';

 

This line goes near the top just under the version number declaration so it’s easy to find and update. Next we put a warning line in the init() function:

if(ExpireDate - TimeCurrent() < 172800)
   Alert("This version of the EPIC is about to expire. Please download the latest version");

This generates an MT4 alert if the indicator or EA is about to expire. 172800 is three days worth of seconds. You can set the warning to any amount of time you wish (converted to seconds.) This will give you users time to get the upgrade and get it installed. The idea here is to be sure they update their EA, not to create problems for them. Next we put the actual expiration alert code in the init() function:

if(TimeCurrent() > ExpireDate)
   Alert("This version of the EPIC has expired. Please download the latest version");

 

This will generate an MT4 alert when the EA expires. This is not enough to stop the EA from running, only generates an annoying alert every time the init() function executes. To stop the EA, you have to add this code to the start() function:

if(TimeCurrent() > ExpireDate)
   {
   Print("This version of SMI has expired. Please download the latest version");
   } //if(TimeCurrent() > ExpireDate)
 else
   {
   //Enter start() function code here
   }

 

This code will put a line in the experts log every tick after expiration. That may not be a good idea. But the start() function code will only run when the current time is less (earlier) than the ExpireDate.

One other thing I do is add this code to the beginning of the init() function to bypass the ExpireDate code. I use different codes for each EA, but this will allow a user who knows the code to defeat the expire date of the EA using a Global Variable.

if(GlobalVariableCheck(StringConcatenate(Prefix,Symbol(),NoExpireCode)))
   {
   ExpireDate = D'2043.11.10 00:01';
   } //if(GlobalVariableCheck(StringConcatenate(Prefix,Symbol(),NoExpireCode)))

 

Of course, the name of the global variable is declared in the string variable NoExpireCode near the top of the EA:

string NoExpireCode="EPICNEC29485";

 

And that’s all there is to it. Thanks for your attention and please follow me on Twitter and LinkedIn.

Tim

The following two tabs change content below.
Winners Edge Trading was founded in 2009 and is working to create the most current and useful Forex information and training available on the internet.

Latest posts by admin (see all)

Winner’s Edge Trading, as seen on:

Winner's Edge Trading in the news