MQL4 TUTORIAL BASICS – 90 SIMPLE LOW PRICE TREND LINE OBJECT

video

In this video we are going to draw a line object from the lowest low of the lowest candle of the chart to the current low of the current candle, so let’s find out how to do that with mql4.
To get started please click on a little icon 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 low price line, 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 number of candles on the chart and that can be done by using the function, window first visible bar. If you mark that and press F1 you will see that it returns the index of the first visible bar in the current chart window so the current candle is always candle zero and the first visible bar is the first candle here on the left side.
Now let’s find out which one is the lowest candle and we can calculate that by using the function, ilowest for the current symbol on the chart and the currently selected period on that chart, we are going to use mode underscore low because mode underscore low will give us the low price for the candles, in this case for all the candles on the chart starting with candle zero – that’s the current candle – and the result will be stored in the variable called lowest candle.
Afterwards, we want to delete formal line objects that are called simple low line trend. The first time we run the code we will not find such an object but afterwards, we want to make sure that the old objects are deleted before we draw a new one.
And that is done by using object create, we need to pass a few parameters here.
The first parameter is zero and it stands for the current chart, the second parameter is for the name of the object, parameter three is for the object type, we use obj underscore trend. There are lots of different object types that are available.
Now we need to tell Metatrader where to draw the object and I would like to draw the line in the main window that’s the one with the candles. For the starting point, we want to start at the time in point where we have the lowest candle, this here is the timeline, the next parameter is for the price point of the lowest candle, this is the price value-line, so now we have defined the starting point, and I would like the line to be drawn to the current candle zero and once again we need to provide the time followed by the value that’s the low of the current candle zero and now our object is finished.
Let’s change a few properties!
To do that we use object set integer for the chart id zero and the object that is called simple low line trend, we want to change the object property color and I would like to have a red line.
Similar is it to change the object property style, we have object set integer, same chart id and the same name for the object but this time we change another property called object property underscore style, I would like to have a solid line, so I use style underscore solid. If you prefer another style you could use something like style underscore dot for a dotted line.
Now let’s continue!
This time I would like to change the property object property width, I use one because I want a thin line and finally, let’s set the object property ray to true that will draw the line from the lowest low to the current low and into the future. Now we are finished.
If you have no idea 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 the basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button or press F7 on your keyboard, you shouldn’t get any errors here and if you have some that might be caused by a simple mistake.
In the last video, I missed a semicolon here and after I clicked on the compile button, I have a bunch of errors because I missed a single semicolon, so please keep that in mind if you have a lot of errors here, it might be just a small thing and after I recompile now I don’t have any errors and if that is the case you can click on a little button here or press F4 to go back to Metatrader.
And in Metatrader you want to click on view, strategy tester or press control and r, please pick the new file, simple low price line dot ex4, mark the option for the visual mode and start your test.
Here we are! Our line object is drawn very fast and our little expert advisor is working as expected and in this little video you have learned how to create a dynamic line object that is drawn from the lowest low of the lowest candle on the chart to the low of the current candle and you have coded it yourself with a few lines of mql4 code.