- Introduction to Creating a Simple Expert Advisor in MQL5 (00:00 – 00:07) Discussing the need for MQL5 to calculate price direction for an expert advisor and the plan to create one that outputs text based on price movement.
- Setting Up a New Expert Advisor for Price Information (00:07 – 00:31) Demonstrating how to create a new expert advisor named “Simple Price Info,” including the initial setup and deletion of unnecessary lines.
- Creating and Sorting an Array for Price Information (00:31 – 00:57) Instructions on creating an array to hold price information and sorting it from the newest to the oldest candle.
- Filling the Array with Price Data from the Chart (00:57 – 01:14) Steps to fill the array with price information for each candle on the chart using the
- Determining Price Direction and Outputting Text (01:14 – 01:37) Coding the expert advisor to print “It is going up” if the last candle’s close price is higher than the previous one, and “It is going down” if it’s lower.
- Compiling the Code and Testing the Expert Advisor (01:37 – 01:56) Compiling the code, opening the strategy tester, and selecting the “Simple Price Info” expert advisor for testing with visualization.
- Observing the Expert Advisor at Work and Its Outputs (01:56 – 02:07) Watching the expert advisor in action as it prints out the current direction of the price on the chart.
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 396 times – 505.00 B