MQL5 Tutorial

MQL5 Tutorial

By Raimund BauerBusinessTechnologyInvesting
Download on the App Store

All MQL5 Tutorial episodes

  • MQL5TUTORIAL – HOW TO GET ADVANCED STATISTICS FOR 3 LIVE SYSTEMS
    TO THE STATISTICS I have added the statistics for the new $1000 Platin Group System on the webpage Platinsystem.org so you can now analyze and take apart every detail. By now our first Platin System trading account has been online for a few weeks. We have crossed the 3 percent profit mark at the beginning of the week and we are approaching the $350 profit line. Thanks to a tip of a member named Rafael from Brazil I now have 3 streaming servers online that automatically trade the $1000 Platin Group System on Youtube for three different accounts. You will find them on my YouTube channels for MQL4 Tutorial, MQL5 Tutorial and Algorithmic Trading System.com.   I lately noticed an error in the system that caused an inconsistency when I updated something in the source code. The reason was that the system was unable to deal with positions that had been opened before it was restarted during live operation. That is not happening while you do strategy tests, therefore it only comes up while trading live. And that is why it is so important to not only rely on strategy test results. So usually I do strategy tests on demo accounts until a system is ready to go into beta stage. Then I use so-called Cent accounts to see how the system behaves on a real money account in daily operation. And, as I often say to my clients, it is never a problem to scale up an account once everything works as it should. But this time I do it in a different way. And the reason is, that one of the premium course members came up with a system that he wanted me to investigate as he thought the good results had been caused because of a special entry. I didn’t believe that and therefore I exchanged the entry signal to see if the results still would be good.   And guess what? That actually was the case so I took the whole thing apart and started to build my own version of the approach. About 3 months later the first Alpha version of the Platin System was ready and here we are now, just a few weeks later, with 3 systems in the beta stage. Therefore I have added the statistics on Platinsystem.org so you can check out the details and find out if this is something you might want to trade. Just click on the statistics sheet and you can see details about each and every trade. And most of the time the system has very little drawdowns and the average trade duration is only a few hours. If you are already a Premium Course Member I am curious about your thoughts about the current system, because I am planning to offer an upgrade to existing Premium Course members who have what it takes to get good results.   If you think about becoming a premium course member, that is still possible on the website. I have taken the sales page for the RobotTradingSystem offline to invest that time for the new Platinum group which might be interesting for some existing members, but I have to admit that it is an expensive solution as it includes consulting and a few things that I have never offered before. One big thing is collaboration, so Rafael, if you see this video and if you are interested to become a Platin Group Member I have a coupon code for you. I still search for the original email and the attachment that got everything started in spring to give credit to the premium member who helped me to get the idea. But I wanted you to be able to check out the embedded statistics on PlatinSystem.org and probably you get a few valuable new insights as I did. I am curious about your response and I will see you in the next video.
    4 min
  • MQL5 TUTORIAL – SIMPLE STOCHASTIC STANDALONE EXPERT ADVISOR
    In this video we are going to create a standalone version for the Stochastic Oscillator, this is a very simple Oscillator; whenever the two lines crossed below the lower line here that would be a buy signal and whenever the two lines cross above that would be a sell signal. This Expert Advisor is actually going to trade and we will see the signal here on the chart. Now how can we create an Expert Advisor for the Stochastic Indicator? To do that please click on a little button here or press F4 and now you should see the Metaeditor window and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this version: “SimpleStochasticStandaloneEA”, click on “Continue”, “Continue” and “Finish” and now we can delete everything above the “OnTick” function and the two comment lines here. First we want to include the file: “Trade.mqh” and we want to create an instance of the class: “CTrade”, let’s call that one: “trade” and inside the “OnTick” function we create a string for the signal that is called: “signal” and we don’t assign a value now because we need to calculate that later on. To really trade something we need to calculate the Ask and the Bid price, that is done by using “SymbolInfoDouble” for the current symbol on the chart and we use “SYMBOL_ASK” to get the Ask price and “SYMBOL_BID” to get the Bid price and with “NormalizeDouble” and “_Digits” we get the right number of digits – this currency pair has 3 digits and other currency pairs may have 5 digits – and that’s a way to calculate the right value. Now we need 2 arrays; the first one is called K array (KArray) the second one D array (DArray) and when you click on: “Insert/ Indicators/ Oscillators/ Stochastic Oscillator”, you would see the same period values here: 5 for the K period and 3 for the D period, so we use “ArraySetAsSeries” to sort the “KArray” and the “DArray” from the current candle downwards and now we can call the “iStochastic” function that is included with MQL5 for the current symbol and the current period, here are our values: 5, 3 and another 3; that’s K period, D period and slowing. We use ”MODE_SMA” and “STO_LOWHIGH” – that’s the method here – SMA stands for Simple Moving Average and “Price field” is “Low/High”. Let’s fill the array with “CopyBuffer”, the first one is for the first buffer that’s buffer 0 (zero) – that’s for the “KArray”, the second one is for buffer 1 – that’s for the “DArray”. We start at candle 0 (zero) and fill it for 3 candles, and that makes it possible to calculate the current K value (KValue) by looking at the value of candle 0 (zero) of the “KArray” and the current D value by looking at the candle 0 (zero) of the “DArray” and because we need to find out if we had a crossover we also do the same and calculate the same values for candle 1. The buy signal would be true if both values are below 20 – so that’s the case when both lines are below the dotted line here – so “KValue0” would be less than 20 and “DValue0” would also be less than 20 and if the “KValue” has crossed the “DValue” from below – so now “KValue0” would be bigger than “DValue0” but “KValue1” was below “DValue1” – that would be a buy signal so we assign the word: ”buy” to our signal. We also have the sell signal, that’s if both values are above 80, that would be the case when both lines are above the upper dotted line here and if the “KValue” has crossed the “DValue” from above – so “KValue0” is below “DValue0” but “KValue1” was above “DValue1” – that would be a sell signal so we assign the word: “sell” to our signal. And if the signal equals sell and we have no open position – so “PositionsTotal” is less than 1 – we use “trade.Sell” to sell 10 micro lot in the other case if the signal equals buy and we have no open positions we use “trade.Buy” to buy 10 micro lot. Finally we are going to create a chart output by using the “Comment” function that will output the words: “The current signal is:” and the calculated “signal...
    7 min
  • MQL5 TUTORIAL ENGLISH – SETUP YOUR ADVANCED STATISTICS
    This video is about publishing statistics on the Internet. You see, I announced a while ago that I would be offering a four-digit platinum group membership with a brand new trading system in a short period of time. Now this is one of the pre-versions and we have an account hosted at Robo Forex Pro that has this account number here. And unlike my other habits, I’m now on FXBlue.com. Because with MyFxBook I was not able to reliably publish the account statistics on a Linux machine. Because this MetaTrader here runs on a Linux device and I have now built my own trading distribution built on Debian.   In fact, I also managed to install FX Blue’s Expert Advisor on the Linux machine in MetaTrader. The whole thing runs here under Play on Linux and currently the Expert Advisor is red, because we get no new trading signals, it is weekend. But you can already see here, the last update was at 10:26 a.m. The account details are also visible. Fx Blue has different functionalities here. One can monitor certain core values. The whole thing can be displayed as a chart. Currently we have made 279 trades on the Euro US Dollar chart. With a total profit of 204.11 $. The net result is $89.16. Interestingly, we have 230 buy trades and 49 sell trades, although the Euro US Dollar has just this week reached its lowest level since the turn of the millennium.   If you want, you can take a closer look at all these details here. I think it’s set up quite well. Then there is the whole thing here again as a print statement or you can download it here in Excel. On my Linux machine here I don’t have an Excel installation now, because it’s a so-called Stick PC. It runs silently in the background with just two gigabytes of memory, but it is more than powerful enough to run our Expert Advisor and has the advantage that we don’t have to worry about getting any Windows updates installed in the middle of the night and then the computer might even be restarted.   So if you had problems in the past to establish the advanced statistics of MyFxBook on a Linux PC, you can set it up on the FXBlue.Com website here via this live tab map. This is pretty straightforward for MetaTrader 4 and MetaTrader 5 and allows you to collect such advanced statistics for your own account here in the future. This is very useful to improve your results in the long run. That’s it so far for today. Thanks for watching and see you in the next video.
    3 min
  • MQL5 TUTORIAL ENGLISCH – POSSIBLE OR PROBABLE?
    The topic today is possibilities and probabilities. Because once again I have received a request from a course member. And the question was whether it is possible to implement a certain profit expectation in practice. My answer was that it depends on a lot of factors and one of these factors is probability. My favorite example on this subject is a man named Roy Sullivan. Roy Sullivan was a park ranger in the United States and he was struck by lightning a full seven times in his life. The likelihood of something like that happening is vanishingly small. Nevertheless, it has become 100% reality for Roy Sullivan. That means even with a very low probability, it’s entirely possible that the consequences could be devastating. For example, one could also think about the statistics for plane crashes and make the argument that flying is the safest way to travel. Yet, there are always reports of plane crashes and for the people who are affected by that situation on the plane, it is 100% a nightmare. So the idea with trading is to find something that brings both of those things together in a way that gives us the best possible results.   That means we need to find something that is possible and that has a fairly high probability of producing positive results. Thankfully, in automated trading, there’s the ability to find that out via a pretty intensive series of tests. What’s going on here in the background of this video is what I spend most of my time doing. In fact, programming an automated trading system is not that time consuming. Most of the time is spent on thorough testing. And the goal is always the same, to increase the probability of a good result as much as possible and to make the system as stable as possible. Of course, many people will now say with the results from this video that the profit expectation is too low and that one could get much more out of such a system. But I can argue that I have been testing this system intensively for only three months. That means I have already done many 100 test series like this one. I’m currently doing that on three different computers with three different account types. And it’s always about making the system a little bit more stable and less about getting a few more dollars out of it in profit expectation.   In fact, with what you see on the screen here, I’m able to trade in different currency pairs from the turn of the millennium historical data to the present day without the system going down the tubes. And the goal here is to get a system stable enough so that you can ensure stable operations over long periods of time. Beginners are often on the hunt for a quick profit. But professionals like Ray Dalio know that the key is to find something that works for the long term based on fundamental laws. If you have the time and the inclination, you should take a closer look at Ray Dalio’s book Principles. I learned a lot from it. And when this system is ready here, there will be an exclusive offer to some existing customers who meet the necessary criteria to be able to trade such a system profitably. However, the price for this will be in the four-digit range, since consulting is also included. But until all this is ready to go, it will surely take a few more months. If this is interesting for you, then you can register in advance.   In this video, I simply wanted to show what is not only possible, but also probable. Because as soon as you can guarantee the most stable operation possible, it’s no problem to continue optimizing a functioning system in the long term. That’s it for today. Thanks for watching and see you in the next video.
    4 min
  • MQL5 TUTORIAL BASICS – 132 STANDALONE BOLLINGER BANDS RSI EXPERT ADVISOR
    In this video we are going to create an Expert Advisor like this one that is able to trade the Bollinger Band signal and it also uses the RSI Oscillator as a filter.   So let’s find out how to do that with MQL5.   To get started, please click on the little button here or press F4 on your keyboard.   Now you should see the meta editor window and here we have a pre coded version for the Bollinger Bands RSI Expert Advisor the first thing we do is to use the include function to include the file trade Mqh.   This one comes with MQL5 and it provides some simplified trading functions and we also use to include two more modules that we are going to create later on.   The first one is to check the entry for the bollinger bands and the second one is for the RSI Oscillator. We start by calculating the ask price and the bid price.   That is done by using symbol info double for the current symbol on the chart.   We either use symbol underscore ask or symbol underscore bit and with normalize double and underscore digits we make sure to calculate the right number of digits behind the dot, that is depending on the currency pair we use.   Now we use Ctrade to create an instance called trade. That will be used to open the trades later on. And we create an array called price info by using MQL rates.   We do that outside of the ontick function because we need the same thing here in the bollinger bands module and in the on tick function we start with array set as series.   To sort our price info array from the current candle downwards. Then we can use copy rates to fill our price info array for the current symbol on the chart and the currently selected period on that chart starting from candle zero for three candles.   And to calculate the current price we look into the price info array, especially at candles zero and at close price. Now let’s find out how to get the trading signal.   That can be done by using a function called check entry bollinger and this function exists in this module here.   It is called Check entry bollinger and it will give back a string value to our main module.   We start by creating a string variable for the signal.   Now we create three arrays for the middle, the upper and the lower band.   Array and we sort all three arrays by using array set as series.   Afterwards we use the built in iBands function of MQL5 for the current symbol on the chart and the currently selected period on the chart.   We want to calculate the values for 20 candles, no shift value and the deviation value is two.   The results will be calculated based on the close price.   Let’s continue to fill our arrays with copy buffer according to the bollinger bands definition that we have created above. We are going to do that for buffer zero.   That’s the middle band array, buffer one for the upper band array and buffer two for the lower band array.   All three values are starting from candle zero.   That’s the current candle and we want to copy the values for three candles and store them in the according arrays.   That makes it possible to get the current values for the middle band, the upper band and the lower band by looking at candle zero in the according arrays.   That will give us the price for the current candle and we do that again for candle one. That’s the candle before the current one.   And if the close price for candle one of our price info array was below the lower bollinger band, and if it is now above the lower bollinger band, that would mean we have a buy signal.   In the other case, if the close price for candle one was above the upper band, and if it is now below the upper band for kennel zero that would mean we have a sell signal and that’s when we assign the word sell to our signal.   And finally we return our signal to the main module. And that’s where we check the filter. By using a function check entry RSI, we can find that one in the second module.   It is called Checkentry RSI and it returns a string value.
    9 min
  • MQL5 TUTORIAL – 131 STANDALONE EMA MACD EXPERT ADVISOR
    In this video we are going to create an expert advisor that uses two exponential moving averages and the MACD as a filter to create, buy and sell signals. So let’s find out how to do that with MQL5. To get started, please click on the IDE button or press F4 on your keyboard. Here we have the pre-coded solution. We start by importing the file Trade.Mqh. This one comes with MQL5 and it provides a few functions for position management.   The next two include statements here are for the modules that we use to create the EMA crossover signal and the MACD filter signal. We use normalise double and symbol info double for the current symbol on the chart to calculate the Ask price by using symbol underscore Ask and the Bid price by using symbol underscore Bid.   And with normalise double and underscore digits, we make sure that we can calculate the right number of digits behind the dot. That is a different number depending on the currency pair you use . Now let’s create an instance of the class Ctrade. That will be called Trade and we are going to use it to open positions later on. Inside of the Ontick function we use MQL rates to create an array for the price data. And with array set as series we sort our price info array from the current candle downwards. And with copyrates we fill the price array with price data for the current symbol on the chart and the currently selected period on the chart. Starting from candle zero for three candles and we store the result in our price info array. To calculate the current price we declare a double variable and that will get the price info value for candle zero.   Actually we are going to use the close price and as candle zero isn’t finished so far, the close price is the current price. In the next step we are going to find out if we have a trading signal by using the function Check entry EMA. That’s the one in this module. And afterwards we use a filter signal and check the entry signal for the MACD. That’s the one in this module. And if the trading signal equals buy and the filter also equals buy and we have no open positions, that’s when we use trade buy to buy ten microlot. In the other case, if the trading signal equals Sell and the filter signal also equals Sell and we have no open positions, that’s when we use trade sell to sell ten microlot. Finally, we use the comment statement to output the trading signal and the filter signal on our chart. That’s it for the main module. Now let’s check the EMA crossover module.   Here we have a function called Checkentry EMA. First we need to define a string variable for the entry. Then we will create an array for the 20 candles moving average and for the 50 candles moving average to do that, we use the IMA function for the current symbol on the chart and the currently selected period on that chart. We do that for 20 candles or for 50 candles. We don’t use a shift value, so we set that to zero. We use Mode EMA for the close price and we repeat the whole thing here for the second moving average. Afterwards, we use array set as series for the moving average array for 20 candles, and we do that again for the moving average array for 50 candles. And with copy buffer we can fill our moving average array according to the definition that we have created above. The EMA only has one line, and we copy the values from the current candle for three candles and store them in the moving average array for 20 candles or below in the moving average array for 50 candles.   And if the moving average for 20 candles is currently above the one for 50 candles, and if it was below for candle one before, that’s when we have a Buy signal, and that’s when we assign the word Buy to our entry signal. In the other case, if the moving average array for 20 candles now is below the moving average array for 50 candles, and if it was above for candle one, that’s the candle before, that’s when we have a sell signal, and that’s when we assign the word sell to our signal. Finally,
    10 min
  • MQL5 TUTORIAL GRUNDLAGEN – 130 HOW TO IMPROVE YOUR RESULTS WITH MASSTESTS
    In this video we are going to talk about mass tests and why most people don’t get the reason why automated trading works even when you blow up an account. So let’s find out how to do that. This is a system that I’m testing right now. I hope it won’t blow up my computer while I’m recording because it uses lots of performance as it is doing 101 tests here. And that is for eleven years.   Here is the current setting. I’m testing the Australian dollar against the yen and I’m doing it for 2010 until 2021. So that’s exactly eleven years. And the little dots here on the screen are results because I’m using a fast generic based algorithm to do all these tests here. That will take some more minutes.   But you already can see that we have good results, a good expected pay off. But when you look at the drawdown, you will see that it can be as high as 70%. So at some point in time in these eleven years, your system will go down and down and you will be convinced that it’s going to crash. For some people, even a drawdown of 22% might be too much, while others are able to stand about 70%. And if you scroll down here, you will see that we have lots of different results, a different number of trades, different values for the expected payoff.   And that is because I’m trading a random entry here. Now you might ask why should anybody trade a random entry? And here is the answer. Let’s think of a coin toss. If you flip a coin, there is a random chance that you will get heads or tails and that’s about 50 / 50.   It might be possible that you lose the coin or that you throw it behind the cupboard. But most of the time you will get either heads or tails. The more often you do that, the clearer is the result. And that’s exactly why I’m doing eleven years for ten or 20 currency pairs and why I use a random entry to find out if it really works. Well, this currency pair looks very good.   And this result also is okay. Some people might already give up when they see something like this. Here we have losses. The red dots mean that we have less money than we had before we started to trade for eleven years. And this result is even worse. But let’s have a look at the results here.   Even without counting, you might see more green dots than red dots here. It’s even more obvious, I would think that we have 10 to 12% losses here and about 85% to 88% small or bigger profits. Now, most people want to avoid these losses here and once they see a loss, they stop testing. Or they see a big draw down and they stop testing. But let’s sort the results from the last test. I have done a few dozen today.   This is the current one. And all the 101 automated tests for eleven years have been profitable. And I wouldn’t have been able to get this result if I didn’t do all the other tests here. So if you see something like this where you make more losses than profits, a simple change of a single parameter could change the whole thing. And the next result could look like this one. But here is where most people get out and say “I have just proven that it doesn’t work”! So really do mass tests for long periods and for lots of currency pairs. You can right click and export the files for Excel. So let’s save this file. And now I will pick the next currency pair and start over again. Here you can see that we have four cores who will do 25 tests each. That will take maybe about 20 minutes.   Here is the current status and now you see the first results here. We would have made three times a good profit. And one time we would have lost almost the whole account. But please stick to the idea with the coin toss here. If you would flip a coin four times and you would get two and a half of what you have put in for three times, would it be a good idea to do that? This is a little later.   Once again we have made good profits and two times we have made a big loss. Is it worth to trade a system like this one? Well that is exactly what you need to answer.
    8 min
  • MQL5 TUTORIAL BASICS – 129 SIMPLE BOLLINGER BANDS EXPERT ADVISOR
    In this video we are going to create a bollinger bands standalone expert advisor that is going to actually trade the bollinger band signals. We have already made a sell trade here and now we want to find out how we can do that in MQL5.   To do that please click on the little button here or press F4 in your Metatrader.   Now you should see the Metaeditor window. And here you want to click on file, New. Expert Advisor from template, Continue.   I will call this one Simple Bollinger band stand alone.   Click on Continue, continue and Finish.   And now you can delete everything that is above the OnTick function and we will also remove the two comment lines here.   First we need to include the trade mqh file.   It will enable us to create a ctrade instance that will be called Trade and we are using it later to open a position. In the Ontick function we first need to create an empty string.   We will call it entry. And we don’t assign a value because we are going to calculate that now.   But before we do that we need to get the ask price and bid price.   That is done by using symbol info double for the current symbol.   We use symbol underscore ask to get the ask price and simple underscore bid to get the bid price.   The normalize double function in combination with underscore digits will help us to get the number of digits for the current symbol of the current chart.   Because we have currency pairs with only three digits and other ones with five digits behind the dot.   We also need to create an array for the prices that will be called price info.   We use MQL rates for that.   MQL rate stores the information about prices like open, high, low and close.   Now we sort the price array from the current candle downwards by using array set as series for our price info.   Array that we have created here.   And after we have done that we use copy rates for our price info array to fill the array with price data for the current symbol and the currently selected period on the chart from the current candle zero for three candles and we store the result in our price info array.   We also need to create an array for several prices for the upper and the lower band of the bollinger bands. This is the upper band, this is the lower band.   And whenever the price breaks out here and reenters into the bollinger bands, that would be a signal.   When it does it from below, that’s a buy signal and when it does it from above like here, that would be a sell signal.   Let’s also use array set as series to sort the upper band array and the lower band array.   And now we actually define the bollinger bands by using the builtin  Ibands definition for the current symbol on the chart under currently selected period we will use 20 candles.   If you click on Insert, Indicators, Trend, Bollinger Bands you will see that we use a period of 20 candles.   We have a shift value of zero.   And the deviation value is two. Also what we use here and the calculation will be based on the close price.   Let’s copy the price info into that array by using copy buffer for the bollinger bands definition that we have created here.   Buffer one and buffer two are used to calculate the upper and the lower band from the current candle zero for three candles. And the result will be stored in the upper band array or the lower band array.   Let’s calculate the expert advisor for the current candle. My upper band value will be the value for candle zero in the upper band array. The lower band value will be the value for candle zero in the lower band array.   And to calculate a crossover, we would also need to calculate the expert advisor for the candle before. That is candle 1 and we store the results in the variable my last upper band value and my last lower band value.   Now we want to check if we have a re entry from below.   That would be true if the close price for candle zero – that’s the current price – is above my lower band value,
    8 min
  • MQL5 TUTORIAL BASICS – 128 SIMPLE LONG TERM TREND
    In this video we are going to measure the long term trend and calculate if we want to open, buy or sell trades. So let’s find out how to do that with MQL5.   To get started please click on the little button here.   It is now called IDE. Now you should see the Meta Editor window and a bunch of new icons and here you want to click on File, new File, Expert Advisor from Template, continue I will call this file Simple Long Term Trend. Click on Continue, continue and finish. Now you can delete everything above the on tick function and let’s also remove the two comment lines here. First we want to include the file Trade.Mqh. This one is part of MQL5 and it provides some simplified trading functions and now we can create an instance of the Class C trade.   This is called Trade and we are going to use it to open new positions. Inside of the on tick function we first need to create a string variable for the entry.   We use Normalize Double and Symbol Info Double to calculate the ask and the bid price for the current symbol on the chart.   We either use symbol underscore Ask or underscore Bid and with underscore digits and normalize Double we make sure that we calculate either three or five digits behind the dot. That is depending on the currency pair. Now let’s create two arrays. The first one is called My Moving Average Array 950. The second one is called My Moving Average Array 1000 because this is for 1000 candles and this is for 950 candles. Let’s continue and define the properties. We are going to use the integrated IMA function for the current symbol on the chart and the currently selected period on that chart. In this case for 950 candles. We don’t need any shift value and we are going to use Mode EMA for Exponential Moving Average and this should be calculated based on the close price.   Let’s repeat that and calculate the other one.   Everything is similar but this time we are going to use 1000 candles. Afterwards we can use array set as series to sort the moving average for the 950 candles and 1000 candles from the current candle downwards and with copy buffer we fill the Moving Average arrays according to the definition that we have created before. For buffer zero starting from candle zero and we want to copy the price values for three candles and store them in the array for 950 candles or in the array for 1000 candles.   Because that makes it possible to calculate the entry signal and if the Moving average array for 950 candles for the current candle zero is bigger than the moving Average array for a thousand candles for candle zero that would mean we have a buy signal and that’s when we assign buy to our entry signal. In the other case, if the Moving Average array for 950 candles for candle zero is below the Moving Average array value for 1000 candles for candle zero that would mean we have a sell signal and that’s when we assign the word sell to our entry signal.   Finally we want to check if the entry signal equals sell and if positions total is below one that would mean we have a sell signal and we have no open positions and that’s when we want to use trade sell to sell ten micro lot.   In the other case if the entry signal equals buy and we have no open positions we use trade dot buy to buy ten microlot. These parts here is the stop loss and the take profit value. You see that I have chosen 50 points for each value and this is the very interesting part.   If you play around with the settings here you will find out what you can do to improve your results. So really do that! For now we are done.   I have to remove the additional bracket here. Now let’s click on the compile button.   Or Press F7 on your keyboard.   That should work without 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 please click on view, strategy tester or press control and R. Please pick the new file simple long term trend EX5,
    7 min
  • MQL5 TUTORIAL – SIMPLE ENVELOPES STANDALONE EXPERT ADVISOR
    In this video we are going to find out how to create an Expert Advisor that is able to trade buy and sell trades for this Indicator; it’s called the Envelopes Indicator, we have just opened a new position everything is traded automatically and it will also output buy and sell signals directly on the chart. So how are we going to code it in MQL5? To do that please click the 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/ Expert Advisor (template)” from template, I will call this one: “SimpleEnvelopeStandaloneExpertAdvisor”, click on “Continue”, “Continue” and “Finish”, let’s delete everything above the “OnTick” function and remove the two comment lines here. We start by including the file: “Trade.mqh” that comes with MQL5 and afterwards we create an instance from “CTrade” that is called: “trade” and we are going to use it to open new positions later on. Inside of the “OnTick” function we need to calculate the Ask price and the Bid price that can be done by using: “SymbolInfoDouble” for the current symbol on the chart, with SYMBOL_ASK” we will get the Ask price and with “SYMBOL_BID” we will get the Bid price. If you click on a currency pair you will see a red and a blue line, the red is the Ask price and the blue is the Bid price. There are some currency pairs with 3 digits behind the dot and others have 5 digits, so we use “NormalizeDouble” and “_Digits” to automatically calculate the right number of digits for the current currency pair. Now we create a string called: “signal”, we will assign the signal later on, right now it’s empty, let’s create an array for the prices (PriceInformation), we use “MqlRates”, if you mark “MqlRates” and press F1 you will learn that it stores the information about prices, volumes and spread and the array will be called: “PriceInformation”. We sort the array downwards from the current candle by using “ArraySetAsSeries” and with “CopyRates” we fill the price information array (PriceInformation) for the current symbol and the currently selected period on the chart. We start with the current candle 0 (zero) and we will fill it with price information for 3 candles. The Envelopes Indicator has 2 bands, the blue one and the red one, so we also need two arrays for the upper band array (UpperBandArray) and the lower band array (LowerBandArray), these will also be sorted by using “ArraySetAsSeries” and now we can create our envelopes definition (EnvelopesDefinition) by using the “iEnvelopes” function that is included with MQL5. This one also needs a few parameters: the first one is for the current symbol on the chart the second one for the period we are using, it will be calculated based on 14 candles and if you click on: “Insert/ Indicators/ Trend/ Envelopes” you will see the 14 candle period here, the shift value is 0 (zero), the deviation is 0.100 and the calculation will be based on the close prices and that’s exactly what we use here for the rest of the parameters. Now we use “CopyBuffer” to fill our upper and our lower band array according to the envelopes definition (EnvelopesDefinition) that we have created here, the first one will be filled for the buffer 0 (zero), the second one for the buffer 1, we start with candle 0 (zero) and copy the data for 3 candles. Let’s calculate the current value for the array values (myUpperBandValue and myLowerBandValue), when you hover with your mouse you will see that there is a value that is constantly changing and that’s what we need so we look at candle 0 (zero) in the upper band array (UpperBandArray) and the lower band array (LowerBandArray) and we use “NormalizeDouble” and a 6 to get only 6 digits behind the dot – that’s what “NormalizeDouble” does, its rounding floating point numbers to a specified accuracy – for the first parameter we say what we want to get rounded, the second parameter is for the number of digits we need and if the last candle closed below the lower b...
    8 min