MQL5 Tutorial

MQL5 TUTORIAL BASICS – 92 SIMPLE DEVIATION CHANNEL OBJECT


Listen Later

In this video, we are going to create a channel object for a so-called deviation channel. Let’s find out how to do that with MQL5. To get started, please click on the 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 SimpleDevChannel. Click on Continue, Continue and Finish. Now you can delete everything above the OnTick function, and let’s also remove the two comment lines here. First, we want to calculate the number of candles on the chart. That can be done by using ChartGetInteger. For the chart id zero. We use CHART_FIRST_VISIBLE_BAR. The last parameter here is for the sub window. In our case, that is sub window zero. That’s the window with the candles. If you like oscillators, you know that those are drawn in a separate window below the candles. But, we don’t want to do that, so we use zero here. Now let’s create a variable for the lowest candle, and we also need to create an array for the low prices for each candle. I will call this one low, and as you might have guessed, we also want to create a variable for the highest candle and the array for the highest prices called high. Now we use ArraySetAsSeries for both arrays to sort them from the current candle downwards. Now let’s fill the low array by using CopyLow for the current symbol on the chart and the currently selected period on that chart. We will start with candle zero for all the candles on the chart and copy the lowest prices into the low array. Of course, we need to repeat that for the highest prices. Therefore, we use CopyHigh. That will give us all the highest bar prices for the current symbol on the chart and the currently selected period, starting from candle zero for all the candles on the chart and the values will be stored in the high array. To get the lowest candle on the chart, we use ArrayMinimum. That will give us the lowest element in the array, and we are looking for it in the low array, starting from candle zero for all the candles on the chart, and store the lowest candle number in this variable. That’s the number of the candle, not the value. You might have expected that we also need to do that for the highest candle. This time we use ArrayMaximum, and we want to search inside of the high array, starting from candle zero for all the candles on the chart and store the result in the variable highest candle. Let’s continue and use MqlRates to get all the price information that we need. It will create an array called price information, and we use ArraySetAsSeries to also sort this one from the current candle downwards. Afterwards, we use CopyRates for the current symbol on the chart and the currently selected period, starting from candle zero, that’s the current candle, for all the candles on the chart and store the result in our price information array. Let’s use ObjectDelete to delete any former objects for the current symbol on the chart. It will delete objects called simple channel object, and we will not have such an object on the very first time we code the function. But afterwards, we want to make sure that we delete the old channel before we draw a new one. That is done by using ObjectCreate. Let’s go through all the parameters we need. The first one, _Symbol, is for the current currency pair. The second one is the name of the object. I have called it Simple Channel Object. The third parameter is the type of the object. In this case, we are using OBG_STANDARD DEVIATION CHANNEL. If you mark that and press F1, you will see that it is just one of the possible object types. It will draw a standard deviation channel object, right on the chart. In the next parameter, we need to define that we want to have the object on the candle chart. That’s window number zero. I would like the object to be drawn for all the candles on the chart. I have to subtract one candle here because this is always a point i...
...more
View all episodesView all episodes
Download on the App Store

MQL5 TutorialBy Raimund Bauer