
Human traders can see if the price is going up or down, but we need MQL 5 to calculate it for our Expert Advisor.
So now we will create a simple Expert Advisor that will bring out the text: “It is going down”, when it’s going down and when the direction changes it will say “it’s going up”.
Now how can we do that? First of all we need to create a new Export Advisor.
I will call it Simple Price Info, continue, continue and finished.
We will delete everything above the Ontick function and the two comment lines, and the first thing we need is an array to hold our price information that can be done by MQLrates.
This will create our array, afterwards we want to sort it from a new to the oldest candle that is done with the arraysetasseries function and it looks like this and now we want to fill our array with the price information, that is done with the function CopyRates and this is how we do it.
So now MQL 5 knows each price for every candle on the chart and if the last candle is higher than the candle before, we want our expert advisor to print out a line, “It is going up.”
And this is how we do that, but if the close price of the last candle is lower than the candle before, we want it to print on the chart, “It is going down.”
And this is how it can be done in MQL 5.
And this is how we do that, so let’s compile the code, hit the F4 key, bring up the Strategy Tester and select Simple Price Info.ex5.
Please set the check mark here for the visualization and start the test.
And here is our little Expert Advisor at work.
So now you know how you get the price of each and every candle and how to print out the current direction of the price on your chart.
Download “MQL5 Simple Price Info Expert Advisor from MQL5 Tutorial”
SimplePriceInfo.txt – Downloaded 391 times – 505.00 B