MQL5 Tutorial

MQL5 Tutorial

By Raimund BauerBusinessTechnologyInvesting
Download on the App Store

All MQL5 Tutorial episodes

  • MQL5 TUTORIAL BASICS – 12 HOW TO OPEN A SIMPLE BUY ORDER
    In this video we want to find out how to open a simple buy position when a bullish candle appears on the chart, in this case we have already opened this buy trade here and now we are going to find out how to code 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 (template)” from template, “Continue”, I will call this file: “SimpleBuyOrder” click on “Continue”, “Continue” and “Finish”. Now we can delete everything above the “OnTick” function and let’s also remove the two comment lines. We start by creating an instance of “CTrade”, “CTrade” will help us to use simple buy and sell functions, to use it we need to include the “Trade.mqh” library, the “Trade.mqh” library comes with MQL5 and now we use it to create an instance called: “trade” that we are going to use later on to open a position. As our trade is going to be a buy position we first need to find out the Ask price, that is done by using the “SymbolInfoDouble” function, for the current symbol we use “SYMBOL_ASK” to get the Ask price and I prefer to use “NormalizeDouble”, “_Digits” to get the right number of digits behind the dot because some currency pairs have five digits behind the dot while others only have three digits behind the dot, so this line will give us the Ask price. With “MqlRates” we create a “PriceInfo” array for the price data, with “ArraySetAsSeries” we sort the price info array (PriceInfo) from the current candle downwards and now we use “CopyRates” to copy the price data into our “PriceInfo” array and we do it for the current symbol and the current period – in my case the current symbol is Euro against US Dollar and the current period is the 1-minute chart – actually we use “_Symbol” here, so let’s do that also in this line. “_Symbol” and “_Period” actually do the same, I don’t know why they did it, we start with candle 0 (zero) and copy the prices for 3 candles in our price info array (PriceInfo) and now we can use it to find out if our last candle is bullish, that would be the case when the close price for candle 1 in our price info array (PriceInfo) is above the open price for our candle 1 in the price info array (PriceInfo). I also want to check another condition; I want to know if we have no other open positions that can be done by using “PositionsTotal” and if that equals 0 (zero) we now can actually open a position and that is where we use the trade instance that we have created here, now use “trade.Buy” to buy 10 micro lot, the second parameter is for the symbol; “NULL”, all capital letters will give us the current symbol on the chart, we need to pay the Ask price, our stop loss will be 300 points below the current price, this parameter here is our take profit, so when the price rises 150 points above the current Ask price we will close the position for a profit, and the last parameter here is used to pass a comment, I don’t need one, but if we cut the last parameter here and set a comma you will see that you could use a “string” to pass a comment and that might be helpful if you want to use several Expert Advisors on one and the same chart but I don’t do that. Actually we could separate the whole buy statement here to make it more readable, let’s add a few comments here, this is the take profit and the last one would be the comment and that’s it. When you are done you can click on the “Compile” button or press F7, you shouldn’t get any errors here and in that case you can click on the little button here or press F4 to go back to Metatrader. In Metatrader you want to click on: “View/ Strategy Tester” or press CTRL and R please pick the “SimpleBuyOrder.ex5” file, enable the visual mode here and start the test. …and now you should see the first bullish candle opens a buy trade, so our little Expert Advisor is working as expected and now you know how to open a buy position for Metatrader and you have co...
    6 min
  • MQL5 TUTORIAL BASICS – 11 HOW TO CALCULATE A SIMPLE MOVING AVERAGE
    In this video want to calculate the value for a Simple Moving Average and output the value on the chart, so let’s find out how to do that with MQL5. Please click on the little button here or press F4 in Metatrader, 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 file: ”SimpleMovingAverage”, click on “Continue”, “Continue” and “Finish”. Now you can delete everything above the “OnTick” function and the two comment lines here. We start by creating an array for the Simple Moving Average (myMovingAverageArray) and you can think of an array like a raw of boxes that contain values. Let’s continue with the definition of the Moving Average (movingAverageDefinition), we use the integrated MQL5 function: “iMA”, if you highlight it and press F1 you will see that it needs a few parameters; the first parameter “_Symbol” is used to automatically find out what kind of symbol is used on the chart – in my case it’s the currency pair: Australian Dollar against Yen – the second parameter “_Period” contains the value of the time frame that is used on the current chart – I’m using the M1 chart for one minute candles right now – the third parameter is the number of candles that we are going to use to calculate the Moving Average, in our case we use 20 candles. When you put your mouse over the Moving Average you will see 20 in round braces behind the Moving Average behind here (Moving Average (20)) that stands for 20 candles. This parameter here is the starting point; we will start the calculation based on the current candle 0 (zero), we use “MODE_SMA” to calculate a Simple Moving Average and we use “PRICE_CLOSE” in the last parameter because we want to calculate the Moving Average values based on the close price. Now we use “CopyBuffer” to fill our Moving Average array (myMovingAverageArray) with data based on the Moving Average Definition (movingAverageDefinition) that we have created here, we start from candle 0 (zero), we do it for buffer 0 (zero) – that’s the red line here, the only Indicator line that we have for a Moving Average. The Bollinger Bands Indicator for example would have 3 lines, so that would be buffer 0 (zero), 1 or 2, we start with the current candle 0 (zero) and we copy the price data for three candles and store it in our array (myMovingAverageArray). To calculate the Moving Average for candle 1 – that’s the last complete candle that appears on the chart – we can use the value for candle 1 in our Moving Average array (myMovingAverageArray) and store it in a variable called: “myMovingAverage20”. Finally we want to use the “Comment” function to create an output on the chart, saying: “MyMovingAverage20:” followed by the value that we have calculated, that’s it so far. Now you can click on the “Compile” button or press F7 on your keyboard – I’m getting a warning here: “possible loss of data due to type conversion” because I am using a floating type (float), that means we have less digits behind the dot but for our simple example that should be enough – so when you are done and when you don’t have any errors, you can click on the little button here or press F4 to go back to Metatrader. In Metatrader we want to click on: “View/ Strategy Tester” or press CTRL and R, please pick the new file: ”SimpleMovingAverage.ex5”, mark the visualization option here and start a test. Now you should see the Moving Average, it’s the red line here on the chart and in the left upper corner we have the calculated value, so let’s have a look at the value for the Moving Average – remember we have calculated it for a candle 1 – in my case it is 83.4845, that’s exactly what we have here in our value and in this little video you have learned how to calculate the values for a Moving Average and how to create an output on the chart and you have done it with a few lines of MQL5 code.
    6 min
  • MQL5 TUTORIAL BASICS – 10 HOW TO CODE A SIMPLE CUSTOM FUNCTION
    In this video we will use MQL5 to create a custom function that will double a counter value each time the price changes. To do that please click on the little button here in Metatrader or press F4 on your keyboard 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 file: “SimpleFunction”, click on “Continue”, “Continue” and “Finish” and now you can remove everything above the “OnTick” function and let’s also delete the two comment lines. We start by creating a static variable for our “counter”; “static” is something that you might not have seen before, in our case we use “static” to create a local variable that will only exist in our function and we want to pass the variable to another function that will be called: “DoubleTheValue” (Double The Value), it doesn’t exist so far so we need to create it and within the round braces we will pass the value of our current “counter” and afterwards to have something on the screen we will use the “Comment” function to output the words: “The counter value” and the current value of the “counter”, so when I compile the code right now I will get an error because the “DoubleTheValue” function is not defined so let’s do that. To create a custom function you start by defining what the function is going to return – in our case the function will return an integer (int) value –, this is the name of the custom function, I call it: “DoubleTheValue” (Double The Value) and here is what the function will take as a parameter. We pass the “counter” – that’s an integer (int) – I call it “CounterValue” in the custom function – you don’t need to use the same name – our function will need two curly braces and when I try to compile it this time we get another error because our function is not going to return anything. So let’s first double the passed value that we have called “CounterValue”, so we take “CounterValue”, multiple it with 2 and the result will be stored in a new variable called: “DoubleValue” and now we can use the “return” operator to return the value to the calling program, that is done by using “return DoubleValue;”, so let’s compile the code one more time and now we don’t see any errors here 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 you want to click on: “View/ Strategy Tester” or press CTRL and R, please pick the new file: “SimpleFunction.ex5”, mark the visualization option here and start a test and now you should see the counter value is doubled each time a new tick comes in so whenever the price changes our custom function is called. This was a very simple example, we only passed one value and we only performed one operation but you could also use the same kind of logic to do more complicated stuff, for example you could go through all the open positions, calculate the profit for a currency pair and return the value to the main function by using the “return” operator and in this little video you have learned how to create a custom function in MQL5 and you have coded it yourself with a few lines of MQL5 code.
    5 min
  • MQL5 TUTORIAL BASICS – 9 HOW USE THE FOR LOOP TO COUNT
    In this video we are going to find out how to increase or decrease a “counter” by using the “for” loop, this one is counting until it reaches the value of 10,000, so let’s find out how to do that. To get started please click on the little icon here or press F4 in Metatrader, 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 file: “SimpleForLoop”, click on “Continue”, “Continue” and “Finish”. Now you can delete everything above the “OnTick” function, let’s also remove the two comment lines. We start by creating a “counter” variable, this one is an integer (int) variable called: “counter” and the initialization value will be 1, we also want to define an end value (endvalue), in our case it’s 10,000 and inside of the “OnTick” function we want to use the “for” loop, now when I mark “for” and press F1 I will see that the “for” loop operator will need 3 expressions and if you have never seen a “for” loop before this might look a little weird but actually it’s not so hard to understand. The first expression here is the starting value, in our case it’s the “counter” value 1. The second expression checks a condition – in our case we want to check if the value of the “counter” is below the “endvalue” – and in the third expression we are doing something with the “counter”, in our case we are increasing it by 1 that’s what “counter++” means, we also could say “counter” equals “counter” plus 1 and whatever is inside this curly braces here will be executed as long as this condition here is true, in our case we just print out the text: “the counter equals” followed by the current value of the “counter”. So far so good, please click on the “Compile” button here and if you don’t see any errors down here you can click on the little symbol here or press F4 to go back to Metatrader and in Metatrader we click on: “View/ Strategy Tester” or we press CTRL and R, let’s pick the new file: “SimpleForLoop.ex5”, please enable the visualization here and start a test. And inside of the “Journal” tab you should see the “counter” is actually working, it increases the value until it has reached 9,999, so far so good but it’s also possible to create a countdown. So let’s exchange the values here, now the “counter” has a starting value of 10,000 and the “endvalue” should be 1, we start with the “counter” value and as long as the “counter” is bigger than the “endvalue” we want to count down and subtract 1 from the current “counter” value. Let’s compile that one, restart the test and this time we have a countdown. Well, this one ends with the last entry: “Counter equals 2” and that’s because in our second expression we have checked if the “counter” is bigger than the “endvalue”. We could also say bigger or equal here, so let’s recompile and this time the last value should be 1 and that’s actually the case. You could also use the “for” loop to increase or decrease the “counter” with other values, so let’s pick 10. One last compilation and this time you see that our countdown is working and we have a step size of 10 and in this little video you have learned how to use the “for” loop to count and increase or decrease “counter” values and you have coded it yourself with a few lines of MQL5 code.
    5 min
  • MQL5 TUTORIAL BASICS – 8 HOW TO USE THE WHILE LOOP
    In this video we are going to find out how to use the “while” statement to wait until something is happening like now; we have waited until the delay counter reached 500,000, so let’s find out how to use the “while” loop 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 (template)” from template, “Continue”, I will call this file: “SimpleWhileLoop”, now I click on “Continue”, “Continue” and “Finish”. We can delete everything above the “OnTick” function and the two comment lines here. So let’s start by creating a delay counter (DelayCounter), we will use an integer variable because we only need whole numbers, we start with the value of 1 and we are going to increase the delay counter in the “OnTick” function, let’s say we have a minimum value of 500,000 and only if our delay counter is above our minimum value of 500,000 we want to do something. Now we can use the “while” statement within the “OnTick” function to check if our delay counter is still below our minimal value and if that is the case we want to do something, first we want to create an output that will show us the text: “DelayCounter:” followed by the calculated value of the current delay counter and afterwards we are going to increase the delay counter by the value of 1 that is done by using “DelayCounter” equals “DelayCounter” plus 1, so let’s compile the code here, this should work without any errors and now we click on the little button here or press F4 to go back to Metatrader. Let’s open the Strategy Tester by clicking on: “View/ Strategy Tester” or you could also press CTRL and R, here we pick the new file: “SimpleWhileLoop.ex5”, please enable the visualization mode here and start your test. And now you see that our counter is working and when it reaches 500,000 this is going to move so everything is fine, but there is a catch; let’s say you would like to increase the delay counter outside the while loop, we still can compile the code without any errors but when we start the next test nothing happens. The whole Strategy Tester is frozen, so why is that? If you highlight the “while” statement and press F1 you should see the “Help” file but nothing happens because everything still is frozen and that’s because we have created an endless loop here. When the first tick comes in and this expression here is true the “while” statement will cause an infinite loop that will never end! We wanted to increase the delay counter here but as we are doing it outside the “while” loop this is never going to happen and so this expression will be true forever and this is one of the reasons why I don’t like to use “while” very often, you can check most of the conditions when you use “if”, so let’s recompile the code here, restart a test and this time we see that our delay counter is working because the “if” statement will only be executed once every time a tick comes in while the “while” statement would run forever. Okay, so if you would like to use the “while” statement you need to make sure that inside of your “while” loop something is going to interrupt the execution or else your “while” loop would run forever. So let’s restart the test and this time it counts like it is supposed to do and in this little video you have learned how to use the “while” statement and how to avoid never-ending loops and you have coded it yourself with a few lines of MQL5 code.
    6 min
  • MQL5 TUTORIAL BASICS – 7 HOW TO USE SWITCH AND CASE
    In this video we are going to find out how to use the “switch” and the “case” statement to change the control-flow of an Expert Advisor. This is an automated Expert Advisor; it doesn’t do very much right now, all we have is an output: “customer wants RSI” and now we want to find out how to change this value by using the “switch” and “case” command. To do that please click on the little icon here or press F4. 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 file: “SimpleSwitchCase”, click on “Continue”, “Continue” and “Finish” and now we can remove everything above the “OnTick” function and lets also remove the two comments here. We start by using an integer variable called: “choice” and that should have the value 5. Inside of the “OnTick” function we also use a string variable called: “entry”, we don’t assign any value here, because we want to define the entry based on our choice here. That is done by using the “switch” statement, we want to go through different options for our choice, so in the case that the customer chooses 5: “the customer wants RSI”. We are using a plus and an equal sign here and I will explain why we do that later on, for now we want to break. This “break” statement here now will leave the “switch-case loop” as soon as this code here has been executed. Let’s add one more here; in the case that our choice is 4 the entry should become “the customer wants Bollinger Bands”, again we use the “break” statement here to leave our “switch and case construct” here. Let’s add another one; in the case that our “choice” variable has the value 3 we want to add “customer wants MacD” to our “entry” statement. You could also use an expression like 1 plus 1 (1+1) instead of a number here but the case statement will not take any variables, otherwise you would get an error here. Let’s also add a “default” option; “default” will be executed whenever none of the above values are true and in that case we would like to have our “entry” statement: “the customer does not know”. Let’s add two curly brackets here and afterwards we would like to create an output for our “entry” by using the “Comment” function. When you are done please click on the “Compile” button here that should work without any errors or warnings and in that case we can click on a little button here or press F4 to go back to Metatrader. In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, here we want to pick the new file: “SimpleSwitchCase.ex5”, please enable the option for the visualization here and start a test. Here is our output: “the customer wants RSI”, so let’s change the choice to 3 here, recompile the code, start another test and this time we get the output: “the customer wants MacD” because that is what is equal to our “choice” 3. Let’s change that to 11, recompile the code and this time we get the output: “the customer does not know” because 11 is not in our choices list so we get the default output here. Okay, there is something special about these “switch” and “case” statements and that is the possibility to remove the “break” statement, let’s do it for the first two “case” statements here , set the “choice” back to 5, recompile the code, start another test and this time we get the text: “the customer wants RSI”, “the customer wants Bollinger Bands” and “the customer wants MacD” and that is because now the first three parts of our “switch-case-construct” have been executed. So please remember whenever you leave out the “break” operator here our little Expert Advisor program will not leave the loop but continue to check the next condition. In this little video you have learned how to use the “switch” and “case” statement and you have done it with a few lines of MQL5 code.
    6 min
  • MQL5 TUTORIAL BASICS – 6 SIMPLE IF CONDITION
    In this video we are going to find out if some condition is true, whenever you use an automated program like this Expert Advisor here you obviously need to check if something is true or false, for example if the Stochastic is above or below the dotted lines here or if the price is above or below the Moving Average and now we want to find out how to do that. Please click on a little icon here or press F4 and now you should see the Metaeditor and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “SimpleIfCondition”, now click on “Continue”, “Continue” and “Finish”. Now you can delete everything that is above the “OnTick” function and let’s also remove the two comment lines here, we are going to start by using two integer variables “a” is 5 and “b” should be 3 and if “a” is greater than 5 I would like to see the text: “a is greater than 5” and if that is not the case I can use the “else” statement, so whenever none of the conditions are true I would like to see the text: “Conditions not true”, so that’s about it. Please click on the “Compile” button or press F7, we don’t have any errors here… Oh, I’ve got a warning because I forgot the “Comment” statement and now everything is okay, so let’s click on a little button here or press F4 to go back to Metatrader. And in Metatrader we click on: “View/ Strategy Tester”, you could also press CTRL and R and here we want to pick the file: “SimpleIfCondition.ex5”, please enable the visualization mode here and start a test. And now we get the output: “Conditions not true” because “a” is not greater than 5, so let’s add another “if” statement here where we check if “a” is equal to 5. Now let’s recompile the code, stop the test, start a new one and this time the output is: “a equals 5”. Now what will happen if we add another “if” statement here to check if “b” equals 3? Let’s recompile the code, start another test and now we get only the output that “b equals 3”, the statement here is ignored and what we could do now is we could use two “if” statements. In the first one we will check if “a is 5”, the second one will check if “b equals 3” and the output will be: “a equals 5 and b equals 3”. Let’s recompile the code and in our next test we will get the output “a equals 5 and b equals 3”. So far so good but if you add anything here, for example we want that “c equals a plus b” and we want to output the value for c, so when we click on the “Compile” button now we get two errors here and the reason is that whenever we use more than one line behind the ”if” statement we need to use two curly braces, so let’s recompile the code and now it works and now in our last test we get the output: “c equals 8”. This was a very basic example, there are a lot of other additional ways to check conditions but in this little video you have learned how to check if a condition is true by using the “if” statement and you have coded yourself with a few lines of MQL5 code.
    5 min
  • MQL5 TUTORIAL BASICS 5 – HOW TO DO CALCULATIONS
    In this video we want to talk about simple calculations, obviously when you use an Expert Advisor like this one to do automated trading you need to do some calculations. For example, in my case I have calculated the max number of positions that are allowed and you see that the currency pair profit is calculated, so let’s find out how to do some basic calculations! To do that please click on the little icon here or press F4 to open your Metaeditor window and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: ”SimpleCalculations”, click on “Continue”, “Continue” and “Finish” and now you can delete everything above the “OnTick” function here, let’s also remove the two comment lines. First we need two “int” variables; “a” equals 5 and “b” equals 3, we use “Comment” to output the result from “a” plus “b”. Let’s click the “Compile” button here, we don’t have any errors so now we can click here or press F4 to go back to Metatrader. In Metatrader we click on: “View/ Strategy Tester”, let’s pick the new “SimpleCalculations.ex5” file, enable the visualization mode and start your test, and here is the output, the result is 8 because 5 plus 3 is 8, so let’s use the next one; “a” minus “b”, recompile, start a new test and this time our result is 2 because 5 minus 3 is 2. Let’s multiply the two values; 5 times 3, recompile and this time the result is 15. We can also divide, “a” divided by “b”, what do you think? Oh, the result is 1! – and the reason is: 5 divided by 3 is 1 because we used integer variables! So we have no floating type values here and that’s where most people get crazy because results don’t match what they expect, so let’s use “double” as a data type, recompile and this time the result is 1.6666666667, that is better! What would you think is the results if you calculate “a” plus “a” times “b”? “a” is 5, so “a” plus “a” would be 10, “b” is 3, so 3 times 10 would be 30. Let’s compile it and our result is 20! – and the reason is that multiplication or division is always calculated first! If you want to change that you need to use brackets because what’s inside the brackets is calculated even before multiplication or division and this time our result is 30! If you press F1 and open the MQL5 Reference you will find lots of other math functions and I would suggest that you write little programs like this one to find out how they work because in the future you will have more complicated calculations and that makes it even harder to find out what is working and why, but in this short video you have learned how to do very basic math calculations and you have done it yourself with a few lines of MQL5 code.
    5 min
  • MQL5 TUTORIAL BASICS – 4 WHAT ARE DATA TYPES
    In this video we want to talk about data types and what data types are. In our case in this strategy test we see that the local time has a special format and whenever you calculate something it is important to choose the right type of data type, so let’s find out how to do that. We start by clicking on this little icon here or you can also press F4, now you should see the Metaeditor and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “SimpleDataTypes”, click on “Continue”, “Continue” and “Finish” now you can delete everything above the “OnTick” function and the two comment lines here. Let’s start with the most obvious type of data and that is a text, in our case we use the data type: “string” to assign this text to a string variable that is called: “Text”, but you couldn’t use them to calculate anything. If you want to calculate anything you would need to use the right kind of value. For example to get the balance value for our account we use a “double” type, “double” is a floating point type and by using the function “AccountInfoDouble” in combination with this expression here – it’s all uppercase – we should get the right value, so let’s see, we will use the “Comment” function to output the “Text” followed by the calculated value. Let’s click on the “Compile” button here or press F7 and that should work without any errors and if that is the case you can click on a little icon here or press a F4 to go back to Metatrader. In the last video we have learned how to use this Strategy Tester, so let’s click on: “File/ Strategy Tester”, here we pick the new file: “SimpleDataTypes” and start a new test, and now you should see the value is 100,000.0, let’s change that here, start another test and this time you will see the digits behind the dot and that is why we use “double” when we do anything with floating type values. You already know the “TimeLocal” function from the previous video and that will return a variable of the type “datetime”, so let’s create an output for this one, recompile the code, stop the previous test and start a new one and now you see the output is in a special kind of formatted value, so “datetime” is what we want to use whenever we need something with time and date. For whole numbers you can use the “integer” type, in this case for the account number, we get it by using “AccountInfoInteger”, using this constant for account log in (ACCOUNT_LOGIN), let’s see how this looks like and here it is. When you expect only true or false as a statement you use the “bool” type, so let’s see how the output for this one looks like, and now we see the output: “The value is: true”. These have been a few common data types, if you click on “Help” or press F1 you should find the MQL5 Reference article about data types and you will learn that there are a few more types that you can use, complex data types are also possible. I would suggest to write little test programs like this one because in this little video you learned how to output different data types directly on your chart and you have coded it yourself with a few lines of MQL5 code.
    5 min
  • MQL5 TUTORIAL BASICS – 3 HOW TO USE THE STRATEGY TESTER
    In this video we want to find out how to use the Strategy Tester. This is a strategy test or also called a back test, we use it to use historical data and trade an Expert Advisor to find out if it’s profitable or not, so let’s find out how to do that. Last time we have created a simple template with an output for this text: “Hello MQL5” and now we want to do a strategy test or back test with this simple example, to do that we click on; “View/ Strategy Tester” or press CTRL and R. Now you should see this “Strategy Tester” panel here, we can pick a file, in our case we will start with the simple Expert Advisor (SimpleExpertAdvisor) that we have created last time. We are going to use the currency pair: Australian Dollar against the Canadian Dollar (AUDCAD) for 1 minute and we want to pick a custom period in our case the year 2017. This is one of the advantages in Metatrader 5, you don’t need to download historical data anymore, this will happen automatically as soon as you pick a period where you don’t have any historical data. It’s all done in the background, this setting is for the quality; it’s OHLC for open, high, low and close. Whenever you point your mouse over a candle you will see an open, high, low and close price for that candle and that’s what this is. Every tick for a candle that contains several price changes is simulated and this is something that a lot of people don’t know. If this big candle here would be 24 hours/ day candle every price change within these 24 hours except for the open, the high, the low end the close price would be calculated on a random basis even if you pick “Every tick” here. If you would like to learn more about how it works just open the “Help” file and read the documentation. I never use forwarding because I don’t believe that anybody can predict the future, this execution setting could simulate a slow Network, I don’t use that either. This is the balance on your testing account, you can set that to any value you want for US Dollar, Euro or whatever currency you prefer. This is the leverage; the higher the leverage the more money you can trade with a small account. Optimization is something that we will discuss in a later video, for now just click on “Start” and now you should see the text: “Hello MQL5” on your chart, this is not very spectacular, so let’s change that and use the function: “TimeLocal”, recompile the code and when we restart the test we will now see an output for the local time that is calculated every time the price changes and in this video you have learned how to use the Strategy Tester and how to use the function: “TimeLocal” to output the local time for the Strategy Tester directly on your chart and you have coded it yourself with a few lines of MQL5 code.
    5 min