Here is one of my earliest EA's. I used the code from Firedaves Universal MA Cross EA, and modified it a little. My understanding of the MQL4 programming language was based from modifying this code, and at this early stage I barely knew what was happening.
I had started adding comments to my code by then, and it's funny to look back and see what I wrote.
When I started out programming EA's, I named them with my name, "Dan", and a number. Later as I realized that this was going to take longer than I thought, I progressed to adding a description of what it was (dan-cci-robot, for example).
The original code was one main routine, with a couple of helper sub-routines which at the time, I barely understood. The was no real trigger in these EA's - they would open a market order as soon as conditions were met, and close them as soon as the conditions were no longer met.
At the beginning of 2011, I got brave and learned a little more about MQL4 and developed the "danw0" code. These robots often did have a trigger, and were able to hedge, but would only open a BUY hedge after a SELL order was opened.
Later still came the "danw2" code, which allowed multiple orders in any configuration I wanted, and forms the basis of my latest series of robots.
I experimented briefly with another code modification called "danw3", which was just "danw2" code but used templates to keep the routines. At this time I often came up with ideas for improving the subroutines or needed to fix bugs, and it became time consuming to go through all of my robots, adjusting the code in each one.
After a while, however, the need for these modifications pretty much stopped, so I stuck with the "danw2" label.
There were further modifications to the "danw2" code, but by then I started including changes in comments within the code, as well as a 'last modified' date, which proved handy, even if I'm sometimes lazy in updating it.
None of this probably makes much sense to you right now, but as I start posting later versions of my robots, you'll see what I mean.
Anyway, back to "dan12-OK" EA. For some reason I thought this one was working somewhat, and added "OK" to the name. I thought I was narrowing down a successful EA. "What's so hard about this Forex stuff?", I thought.
This EA checks two moving averages, 3 EMA and 40 SMMA. Stop-loss is set to 100, and take-profit at 200. With these settings it probably should be used on the 4hr time frame, but I used most EA's on the 5m and 15m charts. More entries, I thought.
I hadn't yet figured out how to use triggers to get into trades, so it opens a trade as soon as conditions are met, no matter where in relation the 2 MA's are to each other. I was thinking that the initial order might be way off, but after that it should open approximately when the MA's cross.
I did add a sort of trend check on the fast moving average to see if it was still going the right way, by counting back 5 bars and comparing the value to the current bar.
Also, I realized I didn't want it to open any orders if the two MA's were TOO far apart, so I calculated the difference in the MA's, and if they were too great, it wouldn't place an order.
There's some code where I tried to work out the angle of the moving averages, but I had no idea what I was doing, and commented it out.
Everything being in order, it will open a trade, and close it when the EA's are on the wrong side of each other again. What could possibly go wrong?