MQL4 TUTORIAL BASICS – 67 SIMPLE VERTICAL LINE

video

In this video we are going to create an expert advisor that is able to draw a vertical line for each sell position, it is going to open a position whenever we have the highest of one hundred candles, so let’s find out how to do that with mql4.
To get started please click on a little button 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 vertical 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 identify the highest of the one hundred candles that can be done by using the function ihighest for the current symbol on the chart and the currently selected period on that chart. We use mode high because we want to find the highest candle, we want to do that for the last one hundred candles and we start with the current candle zero.
And if the highest candle equals the current candle – that would be the case when the last candle here would be higher than this one – and if orders total equals zero (that would be the case when we have no open positions) that’s when we use order send for the current symbol to sell ten micro lot.
Afterwards, we want to call a custom function called draw v line and we pass the number for the highest candle as a parameter.
Well, this function doesn’t exist so we need to code it in a few seconds but before we do that we want to create a chart output using the comment statement. This will output the text, the highest of the last one hundred candles, is candle number, followed by the calculated highest candle and it will also output the text, the highest price is and the price for that candle.
Our user-defined function will have no return value, the name is, draw v line and we pass an integer value for the highest candle – remember this is the number of the highest candle, not the price – and before we draw a line we want to delete an old-line if we have one because we only want to see one of those vertical lines on the chart.
Afterwards, we use object create to create an object that is called, line. The type of the object is obj underscore vline, if you mark that and press F1 you will see that we have a lot of deferent object types here, we will draw this one, that’s a vertical line, the reference has lots of options for that line.
For example, this is how you would change the color or you could use object set integer for the current chart and change the line width.
We want to draw the object on the main chart that is chart number zero. Some indicators would be below the candles that would be the chart number one, for example for the macd and the line should be drawn for the current candle, this parameter here is for the high of the highest candle that is the current candle 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 first or maybe even the premium course on our website might be interesting for you. This was actually one of the ideas from a premium course member and if you are already a premium course member and if you have an idea for a video like this one, please let me know.
But for now, please click on the compile button or press F7 on your keyboard, I don’t have any errors and if that is the case you can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader, please click on view, strategy tester or press control and r, now pick the new file, simple vertical line dot ex4, mark the option for the visual mode here and start a test.
Here we are! The expert advisor is running, I want to zoom into the chart by pressing the minus key on the keyboard and speed that up a little bit.
Here we are! This is the first sell trade, this was the highest candle at that time and in this little video you have learned how to create an expert advisor that is able to draw a vertical line whenever you open a sell position and you have coded it yourself with a few lines of mql4 code.

MQL4 Tutorial searches: