Trader’s Tech – Writing Your Own EA Part 90 – Version Control

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 89, we wrapped up our discussion of Graphical Chart Objects. This time we’ll discuss version control of your EA.

If you’re writing your EA for your own use, then this article will be less important to you. If your EA is in use by others, you will want to think about controlling and numbering the versions of your EA. I’m going to discuss how I do it. You may have a better idea. If you do, please share it. Like I’ve said many times, if we stop learning we die.

For starters, I have this little block of code near the top of my EA – right after the #include and #property tags:

//------ Header Vars ------
string   Title="EPIC"; 
string   Prefix="EPIC_";
string   Version="v04.00B01";
int      TradeFileVersion=1;
string   uTradeFileName="_TradeFile.bin";
datetime ExpireDate=D'2013.11.10 00:01';

 

As usual, I start new sections with some sort of comment header. I know, I’m a little OCD about that. But again, like I’ve said many times, you’ll be glad you were OCD about organization in six months when you’ve got to do a modification to your EA.

The first variable I initialize is a string called Title. This is used when I add comments to an order or send data to another program. This is the publicly identifying name.

The next variable is a string called Prefix. All my objects, files, Global Variables (big G),  and other things created by this EA will begin with the Prefix string. So I can identify them in the case that some other programmer (or I) used the same name in an EA or indicator that may be in use in a common area (e.g. same MT4 platform, same chart) Also, this allows me to delete them as a group.

Next is the string Version. This is displayed in the lower left corner of the chart so I can always determine if my users have the latest version of the EA.

The next is the integer TradeFileVersion. This may be different depending on the name of your file. For more information about it, I discussed file version numbers here.

The next is a string uTradeFileName. Again, this may be different depending on the names and number of files you will be saving. When a file is created, I will prepend the Prefix and possibly the pair name to the file name. Unfortunately, MT4 won’t allow you to put the code to prepend a prefix or anything else in a variable initialization.

And lastly, we have a datetime variable called ExpireDate. This variable is used to “expire” the EA so it can’t be used past its useful date. This is to be sure your users don’t continue to use an old version – that they always are sure they update to the latest. I’ll go into more details regarding this in a future installment.

As I mentioned, I usually display the version number in the lower left corner of the chart. This line goes in the init() function:

DrawVersion();

Then my DrawVersion() function is part of my generic start code:

void DrawVersion()
   {
   string name;
   name = StringConcatenate(Prefix,"Version");
   ObjectCreate(name,OBJ_LABEL,0,0,0);
   ObjectSetText(name,Version,8,"Verdana",Black);
   ObjectSet(name,OBJPROP_CORNER,2);
   ObjectSet(name,OBJPROP_XDISTANCE,5);
   ObjectSet(name,OBJPROP_YDISTANCE,2);
   } //void DrawVersion()

 

I may substitute variables for the font, font size and color in the ObjectSetText() function so I can adjust to the chart color.

As for the version number, I usually start my EA with v0.10. I will increase the minor number on each modification or bug fix (v0.11, v0.12 and so on.) When I’m out of the initial beta testing, I will change it to v01.00, again increasing the minor number on small mods and bug fixes.  When I do a complete rewrite (programs are ALWAYS better when you rewrite them – at least they are for me), I will use v02.00B00 for the beta version – increasing the B number on mods. That will become v02.00 on completion of beta testing and so on. You’ll notice that my EA EPIC (a trade management EA) is in beta test on version 04.

The version number is right at the top of the code, so it’s easy to keep it updated. And, of course, each update (minor or major) is documented with a text file describing the changes in detail. That’s the hardest part for me; keeping track of the changes.

Now you know how I do version control. Next time we’ll discuss another important aspect of programming, error trapping. 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.

Winner’s Edge Trading, as seen on:

Winner's Edge Trading in the news