Trader’s Tech – Writing Your Own EA Part 25 – Compiling

Forex RobotIt’s a beautiful Friday morning on the farm, currently sunny and 68°F, it’s awesome! Between the roosters, the peacock and the coffee, I’m definitely wide awake. I’m blessed to have the opportunity to spend time here.

If you’re new to this series and want to check it out from the beginning, you can find that here.

In Part 24 we bench checked our code. I had a few brain farts while doing these articles. I’m pretty sure I fixed them all in that code. For those who may have missed it, there is a posting of the completed code in that article. Today, we’ll copy/paste our code into MetaEditor and compile. We’ll also discuss a few tricks for solving compilation errors.

Go to the Part 24 article, highlight the code (and nothing but the code), hold CTRL and press C. That will copy the code to your clipboard. Open your MetaEditor (if you can’t remember how to do that, look here), open the file you created here, highlight all the code in the file, hold CTRL and press V. That will replace the code in the file with the code from your clipboard. Click File/Save to save your work. We’re now ready to compile.



Trader's Tech - EA Compiling 1Compiling your EA is a highly complex and difficult process consisting of clicking the Compile button and viewing the results of the compilation in the window on the bottom. Just kidding about the complex. That’s all there is to it. Just for practice, I’m going to simulate some compilation errors and show you some tips for getting a “clean” compilation.  The real complex part begins after we succeed in getting a clean compilation.





Trader's Tech - EA Compiling 2 I removed the semicolon after the MagicNumber initialization and compiled again. You see the results in the bottom window. You will notice there are four compile errors. Often when you make a typo, you will see multiple errors after the compilation. Typically, I just fix the first error and it often clears up many or all of the remaining errors. Once the compiler discovers missing punctuation, sometimes it doesn’t know how to resolve the remaining code, so it generates a bunch of errors that will all be fixed by repairing the first error. To find the location of the error, double click on the error line in the bottom window and you will see the red circle with the dash appear to the left of the line where the error manifested. Often, as in this case, this will be the line after the actual error. The more you program, the quicker you will be at finding these errors. In fact, you may find many of them during your bench check. Let’s fix this error and simulate another.


Trader's Tech - EA Compiling 3This error is a little more subtle and the compiler doesn’t make the problem immediately obvious. I changed the A in currMA2 to a lower case. I do these sorts of things when I type too fast. Especially if I’m typing on the lame keyboard on my laptop. I love my laptop, but the keyboard is terrible. I digress. Notice the error appears with the first instance of the “misspelled” currMA2 when the real error is in the declaration of the variable. This is an example of the finickiness of compilers. Now, let’s do one more, the dreaded unbalanced left parenthesis (or brace.)




Trader's Tech - EA Compiling 3Our EA doesn’t have any really complex lines with nested upon nested parentheses, but that does happen often. I’m sure we’ll see a few lines like that in future installments of this series. But for example’s sake, I removed the right parenthesis immediately after NormalizeDouble(TradeSize,2, so you can see what happens. Notice the compilation results. If you were to double-click this line, it would show you the last line of the program. Not very helpful. In some programs it has taken me hours to find this error.  What I usually do is use the /* and */ to comment out whole sections of the program. You have to comment out logical sections that won’t generate other errors. For example, you can comment out a whole function, but to do so, you leave the function name and the braces after the function name, but comment out all the code in the function. Then re-compile. If the error still occurs, you know the error is not in that function – or you find out you have multiple errors. And of course if there error doesn’t occur, you know it’s in that function. Sometimes you just have to count all the parentheses to find the missing one. It’s the most annoying compilation error you can get. The same goes for missing braces.

I’ve mentioned before that I like to type the EA directly into the MetaEditor and compile the portions as I get them completed. That usually makes finding these errors much easier.

OK. We’ve finally got a compiled EA to play with. Next week we’ll discuss how to test your EA for functionality and troubleshoot it if it’s not working properly.

Thanks for your attention. Please follow me on Twitter and LinkedIn.




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