How to get the course direction


To make good trading decisions it is useful to know if it is going up or down. We want to change our little Expert Advisor to print out “it is going down” when it is going down and in the other case we want to print out “it is going up”. So how can that be done? Let’s bring up the Metaeditor with the F4 key and I have already changed the code here. The first thing we do is to declare a string variable that is called direction – without any value. In the OnTick() function that will run every time when the price changes we want to show a comment on the chart and if the close price from candle two is lower than the close price from candle one, we want the comment to be “it is going up”. In the other case we want it to be “it is going down”. In our case this candle is still building, so the candle before would be candle one, the next one would be candle two, candle three and so on. Let’s see if that works. Okay, it says it is going down and that is right. Now it is going up with green candles. The direction might change very often and we would like to have a little bit more convinience, so let’s change that. We stop the test, bring up the Metaeditor and change candle two to candle ten. Let’s compile the code and see what hapens when we start it again. It should be more stable now. It says it is going down and even if the color of the candle changes nothing happens. And the prediction of the direction is much more stable now. This is a very easy way to print out the trend direction directly on the chart and it should help you to make better decisions in which direction you want to open your next position.