MQL5 Tutorial

MQL5 Tutorial

By Raimund BauerBusinessTechnologyInvesting
Download on the App Store

All MQL5 Tutorial episodes

  • MQL5 TUTORIAL BASICS – 58 SIMPLE DYNAMIC BUY POSITION SIZE
    In this video, we are going to find out how to dynamically calculate position sizes for buy trades, in this case, based on the equity, 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 Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple dynamic buy position size, click on continue, continue and finish, now you can delete everything above the on tick function and the two comment lines here. We start with an include statement to include the file trade dot mqh, this file comes with mql5 and we are going to use it to open positions. To do that we need to create an instance of the class ctrade, we will call that one trade and inside of the on tick function we need to calculate a few things, first we want to calculate the ask price, that is a double value because it’s a floating type, the variable name is ask and we can calculate the ask price by using symbol info double, for the current symbol on the chart, we use symbol underscore ask and with normalize double and underscore digits we automatically calculate the right number of digits behind the dot for the currency pair on the chart. Afterwards, we want to calculate the equity, the equity is what is left over after we have paid for costs and open trades and to calculate it we use account info double, the parameter we use is account underscore equity – all in capital letters. Let’s repeat that for the balance. The account balance is calculated by using account info double and here is the parameter, account underscore balance, this one is also in capital letters. Afterwards, we are going to calculate the position size, this is a double value and we use normalize double to cut the results to two digits behind the dot because when we divide the equity by 100,000 the result might have six to eight digits behind the dot and that would cause an error because when we try to open a new position we would get a journal entry that the position size is wrong and this is going to prevent that. So let’s check the conditions! First, we want to know if the equity is equal or bigger than the balance, the second condition would be, we want to know if the return value for positions total is zero, if that is the case we don’t have any open positions and that is when we use trade dot buy to open a buy trade for the dynamically calculated position size that we have calculated here. Finally, we use the comment statement to create an output on the chart that will show us the balance, the equity and the calculated position size. That’s about it! 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, for now, please click on the compile button or press F7. I have an error because this curly bracket is too much, let’s repeat the compilation process and this time it worked without any errors. If this is true for you you can click on the little button here or press F4 on your keyboard 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 dynamic buy position size dot ex5, mark the option for the visual mode and start a test. The expert advisor is going to open positions and we can see that the position size is calculated based on the equity and in this little video you have learned how to calculate a dynamic position size for buy positions and you have coded it yourself with a few lines of mql5 code.
    6 min
  • MQL5 TUTORIAL BASICS – 57 HOW TO CREATE METAQUOTES DEMO ACCOUNTS INSIDE METATRADER
    In this video we are going to create an original MetaQuotes demo account for Metatrader 5, usually, you get one of these demo accounts right away when you install Metatrader but from time to time you might need another one, so let’s find out how to do that! This is the robot trading system demo version that can be downloaded on the new website algorithmictradingsystem.com, it’s free but it will only run with original MetaQuotes demo accounts. The reason is very simple, as MetaQuotes is the provider for the software that we are using, MetaQuotes demo accounts are available everywhere in the world and if you want to download one of the free expert advisor versions and compare your results with mine it’s a good idea to use a real MetaQuotes demo account because depending on the broker you use you might have very different conditions. For example, my leverage setting is 1 to 500 and that would not be possible with German brokers. You see that my RoboForex account also supports the same setting but other things like spread and swap, these might be different so let’s create one of these free accounts here, just right click on accounts, select open an account, here you should already see the MetaQuotes software cooperation, otherwise you could find it here. We want this entry now let’s click on continue, and the pre-selected entry is open a demo account to trade virtual money without risk, that’s what we are going to do so let’s click on continue, I have to fill in my credentials here and very important we want to use the hedge mode. Until 2016 or so Metatrader 5 was only able to work with the netting mode, netting mode means that you couldn’t have more than one position. A hedging account will have the word hedge inside of the account description and this is what we need if we want to trade several positions at the same time, that’s exactly what we are doing right now in the strategy tester so let’s mark this option, select a good leverage like 1 to 500, one hundred thousand dollars or euro, agree to the terms and conditions here and click on continue and now you should see the credentials for your brand new MetaQuotes demo account. You can click this link to copy the registration information to your clipboard and you can paste the content into notepad or any other editor, now let’s click on finish and here is our new account right away, it’s already pre-activated here. Now let’s go to the website algorithmictradingsystem.com, click onto the results link and here you can download the demo version for a lot of entries, you can download it for free and it will work with your original Metatrader 5 demo account so let’s do that! I want to select the two files, click on file, open data folder inside of Metatrader and navigate to mql5, experts, I will paste the files here, let’s right-click on expert advisors and select refresh, here is the new file, we can now select it in the strategy tester, to save some time I will disable the visible mode here and start a test. This is how it looks like, this was a very low-risk setting, let’s select eighteen, restart the test and here you can see the results for the demo version, in this case for the Stochastic oscillator, in this case, the results look very promising with a download from algorithmictradingsystem.com and in this little video you have learned how to create an original MetaQuotes demo account inside of Metatrader and you have done it yourself within a few minutes.
    6 min
  • MQL5 TUTORIAL BASICS – 56 SIMPLE CLOSE TIMER
    In this video, we are going to create a timer that is able to close positions that are not profitable, in this case after one hour. This was a question from one of the premium course members, so let’s find out how to code that with mql5. 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 close timer, click on continue, continue and finish. Now you can delete everything above the on tick function and the two comment lines here. We start with an include statement to include the file trade dot mqh, it contains the class ctrade so we create an instance of that class that will be used to open some test positions. Inside of the on tick function we need to calculate the ask price and the bid price. This is done by using symbol info double for the current symbol on the chart. We use symbol underscore ask or symbol underscore bid and with normalize double and underscore digits we automatically calculate the number of digits behind the dot. Afterwards, we want to open some test positions, we wouldn’t do that on a real account but to have something to close I need to open some positions in the strategy tester. In my case, if positions total equals zero and we have no open positions we use trade dot buy or trade dot sell to open one buy and one sell position. And afterwards, we want to call a function called check close timer, this one doesn’t exist so far so we need to create it now. We use void because we have no return value and we use check close timer for the function name. Let’s use a for loop to go through all the open positions. For each position, I want to use position get ticket to get the ticket number. I also want to calculate the position open time, we can get it by using position get integer. The parameter is position underscore time but this is a date time variable and I would like to use mql date time to create a structure so if you mark that and press F1 you will see that the date time structure has eight return values here. One of the values is the hour and that’s what we need. Now we use time to struct to convert the position open time that we have calculated here into our structure and that makes it possible to extract the opening hour for this position from our structure. Now we need to get the current hour of the local time. We start by using time local to get the date time value. Now we create another structure, this one will be called my local time. Once again we use time to struct to convert the local time that we have calculated here into our structure and afterwards we extract the current hour because this makes it possible to calculate the difference by simply subtracting the opening hour from the current hour. Please remember this will only work for the same trading day otherwise you would need to check if the date has changed. Now let’s create a few print statements here. Usually, I would prefer to use comment statements but we need these outputs for each position so let’s calculate the position profit that is done by using position get double and the parameter is position underscore profit and after some hours and in my case after the first hour is over we want to check if the position profit is negative and if that is the case we use trade dot position close for our current ticket to close the position. Finally, we want to end the for loop and the function 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 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, you shouldn’t get any errors and if that is the case you can click on a little button here or press F4 to go back to Metatrader.
    7 min
  • MQL5 TUTORIAL BASICS – 55 HOW TO CALCULATE THE DAY OF THE WEEK
    In this video, we are going to calculate the day of the week, the date and the current time. This is a question from one of the premium course members who wanted to calculate the current weekday so let’s find out how to do that with mql5. 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 date calculation, 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. To get started we want to use the function time local, this returns the local time of a computer, in our case, it’s the time in the strategy test. In my case, it’s the date from February 2019, not my local computer time from today and I would like to get hours and minutes so I use time to string to convert the local time that we have calculated here and I use the parameter time underscore minutes – all in capital letters – that will return the hours and the minutes in this format. If you need the seconds you can also use time seconds that would output the hour, the minute and the second. Now that we have the time I would also like to calculate the date and the year. This is almost similar but this time we are using time underscore date as the second parameter but actually, we wanted to calculate the day of the week and to get that value we need to do some more things. First, we use mql date time, if you mark that and press F1 you will learn that this type of date structure contains eight fields, it will return integer values and it also contains the day and the day of the week. Afterwards, we use time to struct for the local time that we have calculated above and the date time structure that we have created here. Time to struct will convert the value into a structure and now we can actually calculate the number for the day of the week by using date time structure dot day of week. So if you cut out this part and press the dot button you will see that you can now get each of these values. For example, date of year would deliver the current number of days for the year while the day of week will return the number of the day in the week and that’s what we need. But humans prefer text values instead of numbers so we want to create a string variable called weekday, so far it does not have any value so let’s add the values. If the day of the week equals one the weekday would be Monday, value two stands for Tuesday, and so on. Actually when we fast forward the backtest we will see that from Friday to Monday we don’t see any weekdays here, that’s because the markets are closed so actually we could leave out Saturday and Sunday. One special thing, depending on the country where you live, you will think that Monday is the first day of the week. In Germany, Sunday would be day seven but in this case, it has the value zero. Now let’s create a chart output here by using the comment statement. We will see the text the date is, followed by the year and the date and in a new line I want to see today is and the weekday and the third line will output the time is and the hours and minutes. 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, for now, please click on the compile button. You shouldn’t get 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 date calculation dot ex5, mark the option for the visual mode here and start a test. Here we are! The expert advisor is running, we see a date, today is Thursday, the time is running,
    7 min
  • MQL5 TUTORIAL BASICS – 54 SIMPLE IFORCE EXPERT ADVISOR
    In this video we are going to create an expert advisor for this oscillator, it’s the force index indicator. Usually, oscillators are used to confirm signals but we are going to produce buy and sell signals, so let’s find out how to do that. To get started please click on 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 file, expert advisor from template, continue, I will call this file simple iforce expert advisor, click on continue, continue and finish. Now we can delete everything above the on tick function and the two command lines here. We start with an include statement to include the file trade dot mqh, this file comes with mql5 and it provides simplified trading functions. Afterwards, we are going to create an instance of the class ctrade, that will be called trade and we are going to use it later on to open positions. Inside of the on tick function we start by calculating the ask price, that can be done by using symbol info double for the current symbol on the chart, we use symbol underscore ask to calculate the ask price and with normalize double and underscore digits we are going to automatically calculate the number of digits behind the dot. Afterwards, we repeat the process for the bid price, the calculation is similar but this time we are using symbol underscore bid – all in capital letters – and that will give us the bid price. Let’s create a string variable called signal for our signal but we don’t assign any value here because we are going to calculate that later. To do that we first need to create an array that will be called my price array and to get the force index calculated we are using the function iforce that is integrated with mql5 and we need to pass a few parameters. The first parameter is for the current symbol on the chart, the second one is for the currently selected period on that chart. This value here is thirteen and if you click on insert, indicators, oscillators, force index you will see that thirteen is the period for the number of candles that we are going to use to calculate the indicator value. The method is simple, we are using the tick mode and that’s actually what we are doing here, thirteen candles, mode sma and the last parameter is volume underscore tick. Now we use array set as series to sort our array from the current candle downwards and with copy buffer, we fill our array with price data according to the force index definition that we have created here for buffer zero, from the current candle zero, we want to have the price data for three candles and we want to store the results in our price array. Once that is done we can calculate the value for the force index value, we do that by looking at candle zero in our price array and I have also used normalize double and a six here to get the output with six digits behind the dot. Let’s repeat the calculation but this time we are doing it for candle one, so now we can calculate if we had a cross over. For a buy trade, we are looking at the force index value for the current candle and if it is below zero and the last force index value was above zero that would be a cross over and in that case, we want to buy. Otherwise, if the force index value now is above zero and if the last force index value was below zero that would be a cross over in the other direction and now we assign sell to our signal because we want to sell. Please remember, usually this is an oscillator that is used to confirm trend signals but if our signal equals sell and the return value for positions total is below one that would mean we have a sell signal and no open position and now we use trade dot sell to sell ten micro lot. In the other case if the signal equals buy and we have no open positions we use trade dot buy and buy ten micro lot. Finally, we want to create a chart output, we do that with the comment statement and that will output the text the current signal is followed ...
    8 min
  • MQL5 TUTORIAL BASICS – 53 SIMPLE FIBONACCI OBJECT
    In this video we are going to create such a Fibonacci object, this was a request from one of our course members, so let’s find out how to do that with mql5. To start 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 Fibonacci object, click on continue, continue and finish. Now you can delete everything above the on tick function and the two comment lines here. Inside of the on tick function we want to create a few variables for the highest and the lowest candle, these are integer variables because it’s only the number of the highest and lowest candle. We also create two arrays for the highest and the lowest prices and with array set as series we are going to sort the arrays from the current candle downwards, let’s also do that with the second array and now we can fill the arrays, we are using copy high to fill the high array with the highest prices of those candles, I would like to calculate the values based on one hundred candles. And for the lowest values in the candles, we use copy low, both for the current symbol on the chart and the currently selected period, we start with candle zero, that’s the current candle and copy the values for one hundred candles in each of the arrays. Now we can use array maximum to calculate the value for the highest candle in our high array and we use array minimum to calculate the lowest candle in our low array but we also need some price values, so let’s use mql rates to create a price information array, this one also needs to be sorted with array set as series. Now we copy all the price data for the whole chart by using copy rates for the current symbol on the chart and the currently selected period for all the bars on the chart into our price information array, we use object delete to remove formal Fibonacci objects, we don’t have any objects at the very first time but afterwards, we delete the old object before we draw a new one and now we use object.create to actually create the Fibonacci object on our chart. For the current symbol on the chart, the name will be Fibonacci, the type of the object is obj underscore fibo, if you mark it and press F1 you will see that we have lots of different object types, this is the one that we are going to use, we want to use the main window to draw the object, the left border will be candle number one hundred, the right border is candle zero, the upper border is where the highest candle price is and the lower border will be drawn on the lowest low of these one hundred candles. That’s about it. If you don’t know 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 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, you shouldn’t get 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, we click on view, strategy tester or press control and r, please pick the new file simple Fibonacci object dot ex5, mark the visual mode here and start a test. Here we are! Our Fibonacci object is drawn on the chart, now we want to stop the test, let’s calculate some values, this can be done by using object get. In our case, we use object get integer to get the time property for time values and we use object get double to get the object property for the price, if you mark this one and press F1 you will see that each object has lots of properties that can be different for each type of object, you can set a property by using object set, for example, the color or something like that or you can get the property by using object get and now we create a chart output with the comment statement that will output the time stamps and the price levels directly on our chart.
    8 min
  • MQL5 TUTORIAL BASICS – 52 SIMPLE EXTERNAL CANDLE NUMBER EA
    In this video we are going to create an expert advisor that is able to calculate the number of candles that are used for a simple moving average, in this case, we are using twenty candles, we can change the number of candles that are used 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 Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple external candle number ea, click on continue, continue and finish. Now you can delete everything above the on tick function and the two comment lines here. We start with an include statement to include the file trade dot mqh, this is part of mql5 and the file provides a few simplified trading functions that we are going to use to open positions. Afterwards, we want to create an external input, this is the input modifier and it will create an external variable for the number of candles that can be changed without changing the source code. Inside of the on tick function we first need to calculate the ask price and the bid price that is done by using symbol info double for the current symbol on the chart, we use symbol underscore ask or symbol underscore bid and with normalize double and underscore digits we automatically calculate the right number of digits behind the dot that depends on each currency pair. Now let’s use mql rates to create a price array that will be called price info, we use array set as series to sort the price info array from the current candle downwards and we use copy rates to fill the price array for the current symbol and the currently selected period starting from candle zero for three candles and store the values in the price info array. Actually, we could use underscore symbol and underscore period because when you mark underscore symbol and press F1 you will see that both functions do the same and that’s also true for underscore period. Now we need to create a string variable called signal, this one has no value so far because we are going to calculate the value later and to do that we need a second array, this one is called my moving average array, we will use it for the simple moving average values and to calculate the moving average we use the included function ima for the current symbol on the chart and the currently selected period on that chart. We use the number of candles that we have defined here, the default value is one, this one here stands for a shift value but we don’t need the shift value, you could use it to set a value for a horizontal shift to move the moving average to the right or to the left but we don’t want to do that. We want to calculate a simple moving average so we use mode underscore sma here, ema would be an exponential moving average for example and the values should be calculated based on the close price. Now let’s also sort this array by using array set as series and afterwards we can fill it with price data that is done by using copy buffer according to the moving average definition that we have created here. We do that for buffer zero – that is the red line here – we want to start with the current candle zero and we want to fill it with data for three candles. Now it’s time to check for the entry conditions so if the close price for candle one in the price info array is bigger than the value for the moving average array for candle one and if it was below the simple moving average before we consider that to be a buy signal so we assign the value buy to our signal. In the other case if the close price for candle one is now below the moving average value and if it was above the moving average before we consider that to be a sell signal so now we assign the word sell to our signal and if the signal equals sell and the return value for positions total is below one – that would mean that we don’t have any open positions – and now we use trade dot sell to sel...
    9 min
  • MQL5 TUTORIAL BASICS – 51 HOW TO DO MASS TESTING
    In this video we are going to do mass testing with a random entry, we use buy and sell signals here, those are created by a random generator. You might be familiar with this kind of testing, that’s the visual mode but it’s also possible to remove the hook here. Let’s do a quick test here for the year twenty eighteen, click on start, here is the graph, it only took a few seconds. In this case, we made a profit of three hundred and one dollars and forty-eight cents. Let’s repeat it with the same settings, this time we lost twenty-four dollars and seventy-seven cents, let’s do one more. And this was also a loss, we lost one hundred ninety-three dollars, so for the same time span we have different results each time because we are using random generated entries and now we would like to do a mass test, so let’s go to settings, this is the source code from the last expert advisor that we have created in the video before and here we have an input value, it’s an integer called mass test and this is an external variable that can be changed without changing the source code and that’s exactly what we need because this makes it possible to set the values for the mass test here but right now it doesn’t work, we can’t change anything because before we do that we need to enable the optimization here. So let’s click on optimization and choose fast generic based algorithm, now we go back to inputs and this time we can change the value here, so let’s click on start and now you should see some optimization results on this tab here. We did fifteen tests in a few seconds, each value here is represented by a dot here and all the dots that are above this mark here stand for a profit, so I would say we had more profitable results than losses but we want to find out exactly. So let’s right-click here, select export to xml, I will call this file masstest dot xml, save it, this is what it looks like in your web browser, not very spectacular but it’s also possible to open it in a spreadsheet calculation. Here we are, this is the profit column and now we can calculate the end result here and we made an overall profit of two thousand nine hundred and twenty-one dollars even with some minor losses here that could still be random so you will be able to do a hundred or even a thousand tests with this kind of mass testing and that is the power of automated trading because discretionary traders only see this kind of information and they see it much slower but now you know how to do mass test with random based entries in a very short time and you can do it yourself with a few lines of mql5 code.
    5 min
  • MQL5 TUTORIAL BASICS – 50 SIMPLE RANDOM ENTRY EXPERT ADVISOR
    In this video we are going to trade random entries, you might find random entries very strange but I promise that you might find the results very interesting, so 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 simple random entry ea, click on continue, continue and finish. Now you can delete everything above the on tick function and the two comment lines here, we start with an include function to include the file trade dot mqh, this one comes with simplified trading functions. Now we create an instance of ctrade that will be called trade and in the next step we will create an input variable that will be an integer variable called mass test and the first initial value is one, that one will become interesting in the next video when we talk about mass testing. Inside of the on tick function we want to calculate the ask price that is done by using symbol info double for the current symbol on the chart, we use symbol underscore ask – all in capital letters – to calculate the ask price and with normalized double and underscore digits we are going to automatically calculate the right number of digits behind the dot that depends on the currency pair we use because some currency pairs have three digits behind the dot while others have five digits behind the dot. Let’s repeat that process, this time we want to calculate the bid price, everything is the same except of this parameter, this time we are using symbol underscore bid – all in capital letters – and for the signal we create a string variable that is called signal, so far we have no value because that’s what we are going to calculate now. Our random generator needs an initial value and we use get tick count to do that, get tick count returns the number of milliseconds that have passed since the system was started, math srand sets the starting point for the pseudorandom integers, so let’s actually calculate a random number by using math rand and this expression here will create either zero or a one and when the random number equals zero we want to set our signal to buy, otherwise, if the random number equals one our signal should have the value sell because now we want to sell. So if the signal equals sell and positions total is below one – that would mean we have a sell signal and no open positions – and now we use trade dot sell to sell ten micro lot. Otherwise, if the signal equals buy and we have no open positions we use trade dot buy and buy ten micro lot. Finally, we want to create a chart output that is done by using the comment function and it will output the text the signal is now followed by the current signal. That’s about it, if you have no clue what all the code here does or if you think that this was too fast for you maybe you want to watch one of the other videos from this basic video series first or maybe even the premium course that you can buy on our website might be interesting for you. For now, please click on the compile button, you shouldn’t get any errors here and if this is the case you can click on a little button here or press a F4 to go back to Metatrader. In Metatrader we pick an empty chart, right-click, select templates, save template and save it as tester dot tpl because this is what we are going to see in the backtest. Now you want to click on view, strategy tester or press control and r, we want to do a single test, please pick the new file simple random entry ea dot ex5, mark the visual mode here and start a test. Here is our little expert advisor, it is running and it constantly produces buy and sell signals, so let’s set that one to full speed, here we have some results so let’s stop that for now, repeat the test, start it again and this time we have different results. Let’s do another one,
    7 min
  • MQL5 TUTORIAL BASICS – 49 SIMPLE WILLIAMS PERCENT RANGE EA
    In this expert advisor, we are going to trade this oscillator, it’s the Williams Percent Range oscillator, we are going to create buy and sell signals to open trades, so 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 one simple Williams percent range ea, 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. We start with an include statement to include the file trade dot mqh this one is included in mql5 and it will give us some trade functions that we are going to use to open and close positions. First, we need to create an instance of the class ctrade that will be called trade. To open a position we need to know either the ask or the bid price, we can calculate that by using symbol info double for the current symbol on the chart, we either use symbol ask or symbol bid – all in capital letters – and with normalize double and underscore digits we calculate the right number of digits behind the dot because that could be three digits or five digits depending on the currency pair. Now we create a string variable called signal for our signal, we don’t assign a value here because that is going to be calculated later on. Let’s create an array, I will call this one wpr array and here is the definition, we use the included function iwpr, that comes with mql5 for the current symbol on the chart and the currently selected period on that chart. And I would like to calculate the result for fourteen candles, that’s also what we see here and it’s the default value. We sort the array from the current candle downwards by using array set as series for our wpr array and with copy buffer, we fill our wpr array according to the definition that we have created here. We do that for buffer zero – that’s the blue line here. We start with the current candle zero and we copy the prices for three candles and store them in the array. To calculate the current value we just have to look inside our array and grab the value for candle zero, once again I use normalize double and I would like to have a value with two digits behind the dot because that’s how the oscillator is calculated here. Now let’s define the buy signal. We would have a buy signal if the current wpr value is below minus eighty but above minus one hundred, so that is the range here below the lower dotted line and if this is true we want our signal to have the value buy. Otherwise, if the wpr value is bigger than minus twenty but below zero and that would be true when it’s above the upper dotted line here in this range that’s when we want to sell so now we assign the word sell to our signal. And when our signal equals sell and positions total is below one – or in other words, we don’t have any open positions – we use trade dot sell to sell ten micro lot. Otherwise, if the signal equals buy and we also have no open positions we use trade dot buy and buy ten micro lot. Finally, we use comment to output the text, the signal is now followed by the calculated signal. That’s about it. If this was too fast for you or if you have no clue what all the code here does, maybe you want to watch one of the other videos in this basic video series or maybe even the premium course might be interesting for you, you can find that one on our website. For now, if you are finished please click on the compile button or press F7, in my case I have no errors and if this is true for you you can click on the little button here or you can press F4 on your keyboard to go back to Metatrader. And in Metatrader we click on view, strategy tester or press control and r, please pick the new file simple williams percent range ea dot ex5, please enable the visual mode here and start a test.
    7 min