MQL5 TUTORIAL BASICS – 71 SIMPLE ARROW SYMBOLS

video

In this video we are going to draw symbols on our chart, you see that we have different symbols appearing here, so let’s find out how to do that with mql5.
To get started please click on a little symbol here or press F4 on your keyboard. Now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file, simple arrow symbols, click on continue, continue and finish.
Now you can delete everything above the ontick function and the two comment lines here.
First, we want to calculate the ask price this is done by using symbol info double for the current symbol on the chart, we use symbol underscore ask and with normalize double and underscore digits we calculate the right number of digits behind dot.
Let’s also repeat that for the bid price, it’s almost the same except for the variable name and we are going to use symbol underscore bid in this. I would like to place the object in the middle so let’s calculate that one. We get the medium price when we add up the two values and divide them by two.
Now let’s use the random generator to draw random symbols for the initialization I use mathsrand and gettickcount, when you mark mathsrand and press F1 you will see that it is generating a series of pseudorandom integer values and when we use gettickcount we get the number of milliseconds since we started the system so in this combination we will get a unique value and we will use that value to now use mathrand that will return another integer value, in our case, we will calculate a number within that range and to draw our symbol we now use object create for the current currency pair on the chart, this is the name of the object, it’s called my object and I would like to have an arrow so I use the object type obj underscore arrow here, now let’s press F1 and you will see that arrows are just one of many available types but we can have several shapes, the next parameter is used to define if the arrow should be drawn in the upper or the lower window. This would be window zero but if you use oscillators you could have a second window below the candles, we don’t need that.
Time current is used for the last known server time, in our case, the object will be drawn here because that’s the current time and the anchor point for the object should be the medium price, so let’s set the value on the main chart for the object with the name my object, I would like to set the value for the object property arrowcode and that is where we use the random arrow code that we have generated here.
Objectsetinteger is a way to set several values, for example, I can also set the object property width, in my case I would like to use the value twenty for bigger objects and each time when the tick comes in I would like to use objectmove to move our existing object to the current point in time.
Finally, let’s create a chart output for the ask price, the bid price, the medium price and that’s about it.
Well, if you don’t understand what all the code here does or if this was too fast for you maybe you want to watch one of the other videos in this basic video series or maybe even the premium course on our website might be interesting for you. If you are a premium course member and have ideas for a video like this one please let me know.
This was a suggestion that I have received this week, for now, please click on the compile button or press F7 and if we don’t have any errors here we can click on the little button here or F4 to go back to Metatrader.
Inside of Metatrader please click on view, strategy tester or press control and r. Here we want to pick the new file, simple arrow symbols dot ex5, please also mark the option for the visual mode here and start a test.
Here we are! You can see that we have different symbols each time, not every return value will have a valid symbol code but in this video, you have learned how to create an expert advisor that is able to draw symbols directly on the chart and you have coded it yourself with a few lines of mql5 code.