All that rain we had in Indiana, well apparently we dragged it with us to Texas. I’m pretty sure Texas is supposed to be quite a bit drier than this.
In Part 42 we wrapped up a couple of modifications to our EA. I’m going to do a little change up for a couple of articles here. Not a big change up, we’ll still talk about programming our EA.
I want to start by apologizing to all you readers who have sent me comments. I’ve been woefully lacking in my answering questions and responding to article comments. I want you to know that I appreciate you taking your time to tell me your opinions and ask your questions. I’ve gone back and responded to most of them. Some of them, I’m going to address right here in this an the next few articles.
I especially want to thank one gentleman in particular, a fellow professional programmer, for keeping me honest. I don’t have his permission to use his name, but I’m sure he knows who he is. I appreciate your input greatly, my friend. Programming is mostly art rather than science but it’s art with a good portion of science mixed in. There are often dozens or hundreds of ways to perform each task. The job of the programmer is scientific in that it’s dependent on us to find the most efficient and effective way to perform the task. This gentleman has offered some suggestions that will greatly improve our EA. I’ll be discussing one of them in this article.
This will involve a modification to our included function MAXover(). As you may recall, MAXover() is the function that tests whether our moving averages have crossed over or not. The internal function iMA(), which we use to determine the current location of the moving averages, returns the price, a value of type double. Using that information, we could be comparing moving average values that are 1/1000th of a pip different from each other and assigning them a position relative to each other, when the distance between them is actually meaningless. To meaningfully determine whether a moving average is above or below another moving average, we have to include what we would call a guard band to be sure that there is actually a functional difference between the values of each moving average. We must start by determining what a functional difference between the moving averages would be. That will help ensure that we are not taking a trade based on a meaningless crossover.
For the purposes of this article, I’m going to use 1/10 pip for our guard band. We may want to change that after some additional thought and experimentation. Since we will need our conversion value, AdjPoint, to convert from Pips to Price, and since included functions don’t recognize global variables from the main code, we have to add code to MAXover() to calculate AdjPoint. We’ll just put that code near the top somewhere:
int FiveDig; if(Digits == 5 || Digits == 3) FiveDig = 10; else FiveDig = 1; AdjPoint = Point * FiveDig;
Next we will need to change this code in our MAXover() function:
//are we above? if(MA1_CurrVal > MA2_CurrVal) //yes we're above CurrLoc=1; else if(MA1_CurrVal < MA2_CurrVal) //No, below CurrLoc=-1; else CurrLoc=0; //Were we previously above if(MA1_PrevVal > MA2_PrevVal) //yes we're above PrevLoc=1; else if(MA1_PrevVal < MA2_PrevVal) //no, below PrevLoc=-1; else PrevLoc=0;
double GuardBand=0.1; //are we above? if(MathAbs(MA1_CurrVal - MA2_CurrVal) < GuardBand * AdjPoint) CurrLoc=0; else if(MA1_CurrVal > MA2_CurrVal) //yes we're above CurrLoc=1; else if(MA1_CurrVal < MA2_CurrVal) //No, below CurrLoc=-1; //Were we previously above if(MathAbs(MA1_PrevVal - MA2_PrevVal) < GuardBand * AdjPoint) CurrLoc=0; else if(MA1_PrevVal > MA2_PrevVal) //yes we're above PrevLoc=1; else if(MA1_PrevVal < MA2_PrevVal) //no, below PrevLoc=-1;
As you can see, we added the variable GuardBand and assigned it to 0.1 pips. That way, if we want to change that value, we only need to change it in one spot. Then, we started the testing to see if the difference between the moving averages was less than our GuardBand. If it is, we will assign a CurrLoc of 0 and skipped the rest of the tests. Then as before, if the difference is greater than GuardBand, we determine which is above and which is below. We removed the default else statement, since the value will always fall in one of the three if statements we have provided.
Now we are safe from 1/100000000th pip crossovers. Thanks again to my fellow programmer for this suggestion. I think this was a very important modification to our EA. If there are any other programmers out there that would like to provide input that would be awesome! I think we can learn a lot from each other. I’ve been programming for over 35 years and I still love to learn new ideas and techniques. If we stop learning we die.
If anyone has a question. Please don’t hesitate to comment. I will endeavor to keep up with the comments much better in the future.
Thanks for your attention and please follow me on Twitter and LinkedIn.
Winner’s Edge Trading, as seen on: