Writing Your Own EA Part 100 – EA Expiration Dates
by
, 06-20-2014 at 11:23 AM (2218 Views)
Writing Your Own EA Part 100 – EA Expiration Dates
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:
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:Code:datetime ExpireDate=D'2014.01.10 00:01';
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:Code:if(ExpireDate - TimeCurrent() < 172800) Alert("This version of the EPIC is about to expire. Please downl
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:Code:if(TimeCurrent() > ExpireDate) Alert("This version of the EPIC has expired. Please download the latest version");
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.Code:if(TimeCurrent() > ExpireDate) { Print("This version of SMI has expired. Please download the latest version"); } //if(TimeCurrent() > ExpireDate) else { //Enter start() function code here }
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.
Of course, the name of the global variable is declared in the string variable NoExpireCode near the top of the EA:Code:if(GlobalVariableCheck(StringConcatenate(Prefix,Symbol(),NoExpireCode))) { ExpireDate = D'2043.11.10 00:01'; } //if(GlobalVariableCheck(StringConcatenate(Prefix,Symbol(),NoExpireCode)))
And that’s all there is to it. Thanks for your attentionCode:string NoExpireCode="EPICNEC29485";