In part 6 of our series, we began our discussion of Program Structure and functions. I’m going to take this article to give you a little insight as to how I design programs.
First, a small disclaimer: Every programmer has his own quirks and traits; his own way of doing things. I’ve been a programmer for a very long time (*cough* *cough*40 years*cough.) So I’m definitely set in my ways. I’ve used a dozen or so languages in those years, so my style doesn’t really conform to any particular language style. My conventions for naming variables, my style for commenting my program and so on, stem from many different arenas. Just remember that my quirks don’t necessarily have to be your quirks. If you don’t like the way I do something or how I name something, feel free to change it up. If you have a question as to why I do a certain thing – please don’t hesitate to ask it. I’ve been doing this long enough that I’m not going to be offended by someone who wants to do it their own way. Just like trading, programming is very individualized.
A few tips:
When naming your functions and variables, be very descriptive. The old cryptic ’70s variable names (a, b, zr, qn, etc.) are no longer necessary. In MQL4, variable names can be, within reason, as long as you want them to be. Just remember, you may have to type them many times. If you type fast, that shouldn’t be a problem. But a very descriptive variable name will keep you from having to look at your variable list too often. There are a few protected words that can’t be used as variables (Bid, Ask for example), but the MQL4 editor will change the color of any names you use that have other meanings. Variable names are case sensitive – in other words, Widget and widget are two different variables. So make sure you get that straight or you may not get the results you’re expecting (remember when I said that computers are picky?)
I highly recommend including copious comments and notes in your code because, six months from now, you will have no clue what you were thinking when you wrote the code. The notes will help you keep your ducks lined up. If you want to add a comment in MQL4, just precede it with double forward slashes (//). Everything after the slashes will be ignored by the compiler. If you want to have several lines of comments, you can precede each line with the double slashes or you can start the whole section with slash-star (/*) and end it with star-slash (*/). Everything in between will be ignored by the compiler. This bears repeating – USE LOTS OF COMMENTS!!
When I first learned to program, flow-charts were all the rage. Of course, programming was via punch card and you couldn’t make a small program change and try it out in two minutes like you can now – doing that back then often took hours, so planning was even more important then. I no longer use flow charts. I now use what we call pseudo-code (fake code.) I “write” the program using pseudo-code and drop that into my program editor in the form of comments and then fill in all the spaces with actual code. This works very well for me, but as you learn to program (if you don’t already know), you will develop your own style of program planning. Pseudo-code is not anything special or rigid, it’s just something that will be a place-holder for real code. Sometimes it is actual code, often it isn’t.
Well, it looks like I’ve gone over my allotment again this time. Next time we’ll start “blowing some code” as we old programmers used to say and get some of our program structure designed. Have a great weekend and follow me on Twitter.
Latest posts by admin (see all)
- How To Trade The Fractal Indicator - April 3, 2017
- How to Use Candlestick Patterns to Start Winning More Trades - March 19, 2017
- Weekly Review Strike 3.0 - December 16, 2016
Winner’s Edge Trading, as seen on: