MQL5 TUTORIAL – Envelopes Indicator explained (in 4 min)

 

https://mql5tutorial.com/?s=envelopes

 

In this video, we are going to create an Expert Advisor that uses Envelopes to generate trading signals. Let’s see how we can do that. We start by opening MetaEditor, which can be done by clicking the little icon or pressing F4. First, we define the OnTick function, which is called every time a new tick is received for the symbol. Inside this function, we create an array named Price Information to store price data. We then sort this array from the current candle to the oldest candle using the Array Set As Series function. Next, we copy the price data into the Price Information array using the Copy Rates function. The parameters for this function are the symbol, the period, the starting position (0 for the current candle), the number of bars to copy, and the array to store the data. We then create two arrays, Upper Band Array and Lower Band Array, to store the values of the upper and lower bands of the Envelopes indicator. These arrays are also sorted from the current candle downwards using the Array Set As Series function. We define the Envelopes indicator using the iEnvelopes function. The parameters for this function are the symbol, the period, the number of periods for the moving average (14), the shift value (0), the type of moving average (MODE_SMA), the applied price (PRICE_CLOSE), and the deviation (0.100).

 

We then copy the upper and lower band values into the respective arrays using the Copy Buffer function. The parameters for this function are the handle of the indicator, the buffer number (0 for the upper band and 1 for the lower band), the starting position (0 for the current candle), the number of values to copy (3), and the array to store the data. Next, we calculate the values of the upper and lower bands for the current candle using the Normalize Double function, which rounds the values to six decimal places. We then generate trading signals based on the closing price of the previous candle. If the closing price is above the upper band, we display an “UPPER SIGNAL” comment on the chart. If the closing price is below the lower band, we display a “LOWER SIGNAL” comment on the chart. If the closing price is between the upper and lower bands, we display the values of the upper and lower bands.

 

Finally, we compile the code by pressing F7. If this was too fast for you or if you don’t understand what all the code is doing, you may want to check out the Premium course on our website, or watch one of the basic videos first. If the compilation is successful, we go back to MetaTrader by pressing F4 or clicking on the icon. Back in MetaTrader, we press Control and R to start the strategy tester, pick the Expert Advisor that we have just created, enable the visual mode, and start a strategy test. We should then see the Expert Advisor on the chart. If you are already a Premium course member and have an idea for a video like this one, you can send us an email. In this video, we have learned how to create an Expert Advisor that uses Envelopes to generate trading signals with a few lines of MQL code. Thanks for watching, and I will see you in the next video.