Trader’s Tech – Writing Your Own EA Part 5 – Planning External Variables

Forex RobotIn part 4 of this series, we identified the first five External Variables necessary for our Simple Moving Average Cross EA. In this installment we will continue with our external variables.

So far, we have identified the following variables that will need to be available to the end user of the EA:

1) LotSize
2) MA1
3) MA2
4) SLPoints
5) TPPoints

For our simple EA, the last External Variable we need to discuss is something MT4 calls the Magic Number. The magic number is used by EAs to know what trades and orders belong to the EA and what belongs to other EAs. We have to be sure the magic number is unique to this EA across your whole trading platform. If you are running other EAs on this trading platform (I usually don’t recommend that, but sometimes it’s necessary), you need to find out what magic number is being used by the other EAs. Then assign a unique magic number to this EA. When I program EAs, I always test for orders by searching for the symbol and the magic number. That way, you can run your EA on multiple pairs without having to change the magic number between the pairs.

Now that we have our list of External Variables, we need to figure out what type of variables they have to be. For simplicity’s sake, I’ll only discuss the two types of variables we need for these Externals:

1) Double – a double is a variable that takes up 8 bytes (you don’t need to remember that.) Just remember that we use a double variable type to represent a price level or a lot size. A double will allow you to represent a positive or negative number with decimal places. For those of you who are experienced programmers you may be interested to know that MQL4 does not have a 4-byte float variable type, so double is used even for lot sizes with only 2 decimal places.

2) Integer – an integer is a variable that takes up 1 to 4 bytes, depending on how we specify it. By default it uses 4 bytes and, again for simplicity’s sake, we’ll just use that default value. An integer will allow you to represent a positive or negative whole number without decimal places. We use an integer variable type to represent pips, points, magic numbers and other such numbers without decimal places.

So, now we assign the variable type to each of our External variables:

1) LotSize – Double – we can specify lot sizes down to a micro-lot (0.01.)
2) MA1 – Integer – We are specifying the number of look-back bars for our moving average.
3) MA2 – Integer
4) SLPoints – Integer – We are specifying a whole number of points for stop loss.
5) TPPoints – Integer
6) MagicNumber – Integer – The magic number is specified as an integer.

Whew! That was way too much like school…. Did you ever think you would need to draw on that information?  I think that’s probably enough for today. Next time, we’ll be talking about our default values for these variables and we’ll start to discuss program structure.

Thanks for your attention. Please follow me on Twitter.

here_for_you_001


Connect_With_Winners_Edge

Get trade set ups everyday!

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