MQL5 Tutorial

MQL5 Tutorial

By Raimund BauerBusinessTechnologyInvesting
Download on the App Store

All MQL5 Tutorial episodes

  • MQL5 TUTORIAL – COMMON BACKTESTING ERRORS
    Today I wanted to talk about a few things that might go wrong in your back testing process. From time to time you will find that the back test doesn’t create the results that you might have been expected, there are countless reasons for that, and in this video I wanted to go through a few very common reasons. Here is a typical mail from a customer who wants to say that the Forex Trading Framework doesn’t work as shown in the video. In this case we would have made 425 Dollars; we have traded the Forex Trading Framework. If you click on the “Inputs” tab here you will find a user adjustable variable for the trading risk, the default setting is 1 and I will now change that to 10, start another test and this time we should see very different results. It will take a few more seconds until our test is finished, we are now in June and now our test is finished and with just one setting we changed the result to 7,720 Dollars profit, so if you see the “Inputs” tab, make sure that you adjust the values. Another common problem would be an account size that is too low. Let’s try 30 US Dollars. Now I start the test and it is finished immediately, we made a loss that was bigger than the account size. Let’s change it to 300 Dollars. This time we lost 259 Dollars and we have grounded the account within 19 days. Let’s try 3,000 US Dollars, it goes up first, this looks very promising and this time we turned a 3,000 Dollar account into a 7,720 Dollar profit but it was pure luck. This account size is far too small. I prefer 100,000 US Dollar upwards. Most of the time I trade 300,000 Dollars now. Something else that might influence your results is if you trade every tick open high low and close prices or open prices only. Let’s start this test and we made 7,720 Dollars again but it depends on the strategy you use, you might get very different results if you trade open prices only. Usually I would suggest to trade open high low and close prices. Let’s create a position size that can’t be traded to cause an error and this time the graph is flat and we see lots of errors here in our “Journal” tab saying that we have tried to trade an invalid volume. If you see those kinds of errors in your journal just Google for MQL5 error codes and you will find the site with quotes of errors and warnings on mql5.com. Just click on the “Return Codes” and you will find a long list of things that might go wrong depending if your broker supports everything you do. A common error is: invalid stops. For example if your trailing stop or your stop-loss is too close. We have caused the invalid volume error here, so let’s go back to the correct version, recompile the code, start a new test and now it works again. Okay, now you have seen a few very common errors that you might want to avoid for your own back testing and if you see something that doesn’t work out as expected please make sure to click on the “Journal” tab and look for the course. Let’s set the visualization option here for the next test, it’s always a good idea to spend some time to watch your trading system because that’s when you really see if it works as you wanted it to work. You can also undock the lower part to see the graph here. It’s always a good idea to spend some time to check out if your trading system works as designed and now you know how you can find the most common errors in your back testing.
    6 min
  • MQL5 TUTORIAL – ADVANCED ADAPTIVE MOVING AVERAGE
    In this video we are going to talk about the Adaptive Moving Average, it’s the little red line here and it looks like a Simple Moving Average but actually Mr. Perry J Kaufmann created this version to produce less false signals. In this little video we are going to create an entry module that can be traded with the main module. In my case it’s the Forex Trading Framework and it will use the Adaptive Moving Average to calculate buy or sell signals. To do that please click on the little button here or press F4 in your Metatrader. This is the framework I’m using; basically it’s a collection of functions that can manage a trade once it is opened. We want to create a file named: “CheckEntry_AMA.mq5” and use the… and use a function called: “CheckEntry” to return a signal. When a new tick comes in we pass the signal to the “CheckForTick” function to check if we want to open a new trade. Now please click on “File/ New/ Expert Advisor” from template (template), “Continue” (Next). I will call this one: “CheckEntryAMA”. Now click on “Continue” (Next), “Continue” (Next) and “Finish”. Now you can delete everything above the “OnTick” function and the two comment lines here. Let’s adjust this one. First we need to create an array for the prices by using “MqlRates” and it will be called: “PriceInfo[]”. Now we sort the price array from the current candle downwards by using “ArraySetAsSeries” and we fill the price array (PriceInfo[]) with price data by using “CopyRates” for the current symbol on the chart and the selected period. We start with the first bar and this expression here will give us all the bars on chart and the result will be stored in the array: “PriceInfo[]”. Let’s create a string variable for the signal; it’s of the type string and it will be called signal and it doesn’t contain any value now because that value will be calculated later. We need another array for the price data of the Indicator that will be called: “myPriceArray[]” and it’s of the type double so it now can contain floating type values. Let’s define the properties of the Adaptive Moving Average Expert Advisor; that can be done by using the “iAMA” function for the current symbol and the current period and here we have several numbers; a 9 a 2 and a 30. When you insert an Adaptive Moving Average on your chart you will see the 9 stands for the period – that’s the number of candles that are used for the calculation – the 2 is used for the Exponential Moving Average; the fast one, and there is also another Exponential Moving Average; the slow one, that has the value 30 and here is a shift value that is 0 – that’s this parameter – and the results are calculated based on the close prices, so we use “PRICE_CLOSE” for our last parameter. Let’s use “ArraySetAsSeries” to store the second array from the current candle downwards, and with “CopyBuffer” we fill our price array for buffer 0 – that’s the first and only line of our Indicator – from candle 0 (that’s the current candle) for 3 candles and store the result in our price array (myPriceArray[]). Now we can get the value of the current candle, all we need to do is to look at candle 0 in our price array and with “NormalizedDouble” and the 6 we cut the digits behind the dot. Actually a 5 would also be okay, in this case the value is 0.992601, that’s 6 digits, so let’s change that back to 6 and now that we have the value and the price we want to find out if the Adaptive Moving Average Value (AdaptiveMovingAverageValue) is bigger than the close price of the current candle in our price info array (myPriceInfo[]), so if it’s above our candles we assign the word: “sell” to our signal. In the other case if the Adaptive Moving Average Value (AdaptiveMovingAverageValue) is below the close price for candle 0 in our price info array (myPriceInfo[]) that would be a buy signal so we assign the word: “buy” to our signal variable. The final step is to return the signal to the main module by using the “return” function for the signal.
    8 min
  • MQL5 TUTORIAL – HIGHEST LOWEST AND AVERAGE PRICE
    In this video we are going to calculate the highest the lowest and the average price for a particular number of candles. If we pause the Expert Advisor we can see that the lowest price was 1.20083, the highest price was 1.20089 and the average price is 1.20086. Now how can we create an Expert Advisor that is able to calculate those prices? To do that please click on the little button here 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” from template (template), “Continue” (Next). I will call this file: Simple Highest Lowest and Average Price (SimpleHighestLowestAndAveragePrice.mq5). – let’s correct that – and click on “Continue” (Next), “Continue” (Next) and “Finish”. Now you can remove everything above the “OnTick” function and the two comment lines here. First we create a variable for the highest and the lowest candle. Both variables will be of the type: “int” because it’s the number of the candle and we will call them highest candle (HighestCandle) and lowest candle (lowestCandle). We also need two arrays for the highest and lowest candles; one array will be called: high (High[]) and the other one: low (Low[]). Now we need to sort both arrays downwards from the current candle by using “ArraySetAsSeries” for the high and the low array. The built-in function: “CopyHigh” gets the history data of the highest bar prices for the selected symbol and period, it takes the current currency pair and the currently selected period on the chart, and we need the data from candle 0 for 10 candles and copy the result in our high array that we have created here. Let’s do the same for the lowest price of 10 candles but this time the result will be stored in the array with a name: “Low”. To calculate the highest candle of 10 candles we use the function: “ArrayMaximum”, it searches the largest element in our array and for the highest candle we look into the high array (High), we start to look for the highest value from candle zero and we want to find it within the first 10 values. For the lowest value we do exactly the same but this time we use the function: “ArrayMinimum”, it does the same as “ArrayMaximum” but in this case it finds the lowest element in our numeric array. Let’s create another array for the price information (PriceInformation[]) of the candles, that can be done by using “MqlRates” because this one stores the information about prices volumes and spread, let’s also sort this one from the current to the oldest candle by using “ArraySetAsSeries” and with “CopyRates” we fill our price information array (PriceInformation[]) for the current symbol and the currently selected period from the current bar zero for all the bars that are available, and the result will be stored in the price information array (PriceInformation[]). It would be enough to calculate it for 10 bars here but maybe you want to write down this expression because it will give you all the bars that are on your chart. Now the highest price is the highest point of the highest candle in our price information array (PriceInformation[]) and the lowest price is the lowest price from the lowest candle in our price information array (PriceInformation[]). To get the average price we add the highest price and the lowest price divided by 2 and with “NormalizedDouble” and a 6 we make sure that we get one digit more otherwise the average price would be rounded. With 6 instead of 5 digits it’s easier for us to see if it is calculated correctly and last but not least we use the “Comment” function to output the highest price, the average price, and the lowest price each value in a new line. Now if you’re done you can press F7 to compile your code or if you have enabled the toolbar you could click on the compile button here, and if it works without any errors and warnings you can click here or press F4 to go back to Metatrader. In Metatrader you want to click on “View/ Strategy Tester” or press CTR...
    7 min
  • MQL5 TUTORIAL – THE SECRET OF RISK MULTIPLICATION
    In this video I wanted to talk about something I do very often; it’s back testing on a massive scale. What you see in the background here is the graph for the currency pair, Australian against Canadian Dollar and what I’m looking for is, I like the equity line to be as close to the balance line as possible. Ideal would be if the green line would be as straight as the blue line here so, my main goal is to find out how to do that because if you have small draw-downs you would need less capital and that would mean that you could make more money with lower risk. You see the green graph below here – that’s the deposit load – it’s below the 1% mark. We started the test with a balance of $300,000 Dollars; right now the balance is above 380,000 Dollars. Now the test has finished and in our results we would have made 39513 Dollars by trading the Forex Trading Framework for the year 2017. Now most people would like these kinds of results and I would receive mails from people who ask me to tell them which kind of entry I use. Well, I use all these entries here and usually I don’t trade for just one year I have already traded all these entries here for seven years. This is a chart that shows ten years for the Australian Dollar against the Canadian Dollar and all these images here represent the result of one of these tests. This chart is for the BWMFI entry – that’s the Bill Williams Market Facilitation Index – and you see that we have made a good outcome with a very low risk because the green line – the equity – never was below $300,000, so that’s what we are looking for. This one is for the RSI — and the RSI produced a big draw-down here – we have been lucky because the draw-down also is above the $300,000 mark but if you would see the same draw-down here right in the beginning you would have made a big loss. So, even this system is cashflow positive and profitable human traders would have had a very hard time during the draw-down because that’s where people freak out and close everything to avoid further losses. Now let’s get back to our system that we have just traded with the cross over entry, now I will out-comment this one and trade the RSI, let’s press F7 to recompile the code and now I go back into Metatrader by pressing F4 or hitting the little button here. I will now start another test, it’s the same system with a different entry, let’s look at the graph. We are now in February a small draw-down in March, now it’s cashflow positive, in June it’s still rising, we face another drawdown in July, now we are three-quarters through the year; the equity is above $320,000 and now the system is finished and we made 39,513 Dollars, the equity looks okay. Now let’s change the input for the trading risk to 25, I will disable the visualization and start another test with the exact same system and this time it should go very fast, we are already in March, we already had to draw-downs below $300,000 Dollars, in October we hit the 350,000 equity mark and this is the final result; the total net profit is 57,486 Dollars and now most of you would say; well this is a very good system. Now let’s change the currency pair and try the Euro /US Dollar (EUR/USD) with the same settings, big draw-down here, another one here, now it rises, here comes the biggest draw-down so far, it gets even worse, we are down to 126,000 Dollars and this is the end result: a minus of 146,819 Dollars! Now, does this mean it’s a bad system? Let’s change the trading risk from 25 to 4 and start another test. Now we have a much lower risk and the result is positive; it’s a net profit of 3,164 Dollars, so if you are looking to create systems like this you need to adjust your risk settings! The current Forex Trading Framework has a simple switch for that and this little setting might make the difference between a big loss with huge draw-downs and the equity curve you have always dreamed of.
    7 min
  • MQL5 TUTORIAL – ADVANCED RELATIVE VIGOR INDEX
    This time we want to trade the Relative Vigor Index that’s the Indicator here. On the chart you can see that it is going to create buy or sell signals depending on the value of these two lines here. If both lines are above the dotted line that would be a sell signal and when both lines are below the dotted line that would be considered to be a buy signal. Now how can we create an Expert Advisor that is able to trade the relative vigor index in full speed? To do that, please click the little button here or press F4 on your keyboard and now you should see the Metaeditor window. I’m going to use the Forex Trading Framework from October 2017 and the new entry module will be called: CheckEntry_RVI. So let’s copy that, click on “File /New /Expert Advisor” from template (template), Continue (Next). I need to include the past to the Forex Trading Framework here, paste the name for the new entry module, click on continue, continue and finish. Now everything above the “OnTick” function and the two comment lines here can be removed. First we need to create a string for the signal that will also be called signal and we don’t assign a value here because that needs to be calculated. In this case I need two arrays because the Indicator uses two different lines here and you see the two lines also have different values. Let’s define the properties for the Expert Advisor, this time we are using the “iRVI” function and we need to pass the current symbol on the chart, the selected period on the chart and the third parameter is a 10. When you have a look at the Indicator itself you will also find the 10 here, let’s right-click on the properties and we see that the ten is the period for the calculation. Okay. Now we use “ArraySetAsSeries” for both of our arrays to sort the arrays from the current candle downwards and with “CopyBuffer” we use the RVI definition (RVIDefinition) we have created here to fill buffer 0 and buffer 1 from the current candle 0 for 3 candles and store the values in price array 0 (myPriceArray0) and price array 1 (myPriceArray1) and now we can calculate the current value for line 0 and line 1 all we need to do is to get the value for candle 0 from my price array 0 (myPriceArray0) or my price array 1 (myPriceArray1) and store the results in the variable called: “RVIValue0” or “RVIValue1” and with “NormalizedDouble” and a 3 we make sure that we get 3 digits behind the dot, that’s also what you see when you hover with the mouse over one of the two lines here. Now let’s create a buy signal. If “RVIValue0” is below “RVIValue1” and if both RVI values are below zero – that would be the case when both of the lines are below the dotted line here – we would consider that to be a buy signal so we assign the word “buy” to the signal. In the other case if “RVIValue0” is greater than “RVIValue1” and if both RVI values are above 0 – so now both lines need to be above the dotted line here – we would assign the world “sell” to our signal. Finally we return the signal to our main module by using the “return” function in my case I use the Forex Trading Framework from October 2017 as a main module. Basically a framework is a collection of functions that are able to open and handle trades, for example this function here would set the position size, you could also code your own framework or get the demo version on forextradingframework.com and because I am going to call the “CheckEntry” function down below here I need to rename our function here to “CheckEntry” and it’s a string type function because we are going to set and return a string. Now let’s save the file here, I need to recompile my framework, that worked without any errors so now I 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 on your keyboard and in the “Strategy Tester” panel I select the Forex Trading Framework from October 2017. Let’s enable the visualization mode here and st...
    7 min
  • MQL5 TUTORIAL – ADVANCED MASS BACKTESTING
    In this video I wanted to talk to you about mass testing. Usually when you do a back test you will enable the visualization mode here and click on start and now you can watch the automated trades. This is already very fast but it still takes a lot of time, I guess this test would take about two minutes and if you want to trade several currency pairs and do a back testing process for a dozen different Forex charts, this can be very time consuming. In this video we want to find out how we can speed up the testing process. To do this please stop the current test and disable the visualization mode. When I start a new test without the visualization this is much faster. You probably already know this. In our case we made a net profit of 152 Dollars and now I would like to do it for a dozen currency pairs or more. The way to do this is to enable the optimization mode here, the last option is called: “All symbols selected in Market Watch” (MarketWatch). So what is MarketWatch (market watch)? You can enable it by clicking on “View /Market Watch” or pressing CTRL + M on your keyboard. Now you should see the little window here, it contains several currency pairs; you could also add new currency pairs here. In my case I have about a dozen currency pairs. Now let’s click on “Start” and you should see a tab called: “Agents”. I’ve got an 8 core processor so 8 different threads are going to start here, this is pretty fast. The first few processes already have been finished and in a few seconds we should be done and here are our results. Well that was pretty fast, wasn’t it? Now you can right click in the table here, export everything to XML, let’s save the file and now your spreadsheet calculation tool should pop up. In my case its LibreOffice Calc, and these are the profits for all the currency pairs. So let’s add them up and we would have made 3989 Dollars profit. You can also right click in the “Market Watch” window and select a set like: “forex all” or click on “Show all” and when I restart the test now it says it is doing 46 different currency pairs. Now you know how to do a quick test for a dozen currency pairs or more and you can do it in a fraction of the time.
    4 min
  • MQL5 TUTORIAL – ADVANCED IVIDYA EA
    In this video we are talking about the Variable Index Dynamic Average Indicator and how to automate it. It’s the red line here and we use the function “iVIDyA” to create it. It takes a few parameters here, so let’s go through everything. Let’s create an Expert Advisor that returns the handle of the Variable Index Dynamic Average Indicator. If you click on “Insert /Indicators /Trend /Variable Index Dynamic Average” you will see that we have a CMO period of 9 and an EMA period of 12 and we are going to use that later on, and you will also see the values when you place your mouse above the Indicator here or click properties. Here is also a shift value of zero and we are going to apply the close price to calculate the value. Okay. To create it please click on the little button here 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” from template (template), Continue (Next). I will use the name: “CheckEntry_ IVIDYA” here, now let’s click on continue, continue and finish. Now you can delete everything above the “OnTick” function and the two comment lines here. This time we will also delete the “OnTick” function because we need one that is named “CHECK_ENTRY” and here we are going to create a variable called signal; that’s a string variable that does not have any value now because we are going to calculate that later. We use “MqlRates” to create an array for the price data and we need to sort the array from the current candle downwards, that can be done by using “ArraySetAsSeries” for our “PriceArray” we have created here. Now we want to fill the “PriceArray” with data for 3 candles. That can be done by using “CopyRates” for the current symbol and the currently selected period on the chart. We will start with candle 0, copy the value for 3 candles and store them in the “PriceArray”. Now we need to create another array for the Expert Advisor and once again we use “ArraySetAsSeries” to sort it from the current candle downwards. Let’s define the actual Expert Advisor by using the “iVIDyA” function for the current symbol on the chart and the currently selected period, and here is a 9 and a 12. These are the values that we have seen here when we click on properties from the CMO period and the EMA period and here is a zero for the shift value and we use “PRICE_CLOSE” because we want to calculate the Expert Advisor based on the close prices. The “iVIDyA” function is described in the help, press F1 to see the description of any function you like and now we use “CopyBuffer” and the Expert Adviser definition to copy for buffer 0 from the current candle 0 for 3 candles and store the data in the “EAArray”. Now we can calculate the current value just by getting candle 0 from our Expert Advisor array we have created here and if the calculated value is above the close price for candle 1 in our “PriceArray” that’s a buy signal so we assign the word “buy” and if the calculated value is below the close price for candle 1 in the “PriceArray” that would be a sell signal. Now we can return the signal to our main module by using the “Return” function. In my case I’m using the Forex Trading Framework basically a framework is a collection of predefined functions and you can trade any entry you like with it. After the compilation please click here to go back to Metatrader, and here you want to click on “View /Strategy Tester” or press CTRL + R and in the strategy tester you want to select the Forex Trading Framework, a currency pair, or the main module that you use. Now mark the visualization and start your test, let’s enable the graphical overlay and go for full speed. Okay. Now you know how to create the IVIDYA Expert Advisor entry with a few lines of MQL5 code.
    7 min
  • MQL5 TUTORIAL – NEW MOBILE APP
    In this video I wanted to show you the new app I have created. Actually I didn’t want to make one, but there were some requests and I understand that people are getting mobile, so here it is! I have created it with the MIT App Inventor, that’s a very simple program and when you click on one of the buttons here something will happen. This is the current RSS feed for the podcast, you can watch the videos directly on your mobile phone. This button here is for the Youtube Channel. Here are lots of other videos for you to watch. This button here will show you a list of books I like; some of them are really helpful to make progress in automated trading. I will update that list later. This button here leads to the statistics, here you can see how my trading systems are doing, the one with the phone here is to get my phone number and my contact data on Google Business and this button here will show you current promotions and bonuses; like a watcher for 25% off I hope the PayPal payment works on the mobile phone. So that basically it for now. I have lots of additional space here, so if you miss anything just tell me so that I can implement it in the next version of the MQL5 Tutorial App.
    3 min
  • MQL5 Tutorial – The Risk Multiplier
    In this video I wanted to talk about something I call a “Risk Multiplier”. This is the German version of the current trading framework for Forex. From time to time people ask me what is a framework good for? Well, basically you can think of it as a set of rules or a playing field. You know the difference between a baseball field and a football field and perhaps a tennis court. Each playing field is little bit different because the goals of the game are a little bit different and the Forex Framework is my optimal playing field for trading Forex but for now let’s focus on this risk multiplier here. It has a standard value of 1.05, I will now change that to 0.8 – this is a dynamic value that can be changed without changing anything in the code. Now let’s select the year 2016 and the currency pair Australian Dollar against the Canadian Dollar and start a test, you will see this graphical representation here, it is very flat for some time and now the period for back-testing is finished. We click on the “Results” page and we made a total net profit of 3 Dollars and 76 Cents, now you will say this isn’t worth the effort and the risk, so let’s see what happens if we right click and we set the default settings again. Now the risk multiplier is 1.05. Let’s start another test here! It looks similar but here it starts to change and now you can see that we have much larger draw-downs here because the risk is higher but that’s also true for the profit. Look at this! When you have a balance that is very high and you see the equity going down, that’s probably the moment when you want to get out of the system. It looks like a good system when you see it on the demo account, but believe me when you are trading with real money this is a whole different game! Okay. We are reaching November now and now our back-test has finished, let’s click on the “Results” and we made 189 233 Dollars and 71 Cents and we only changed one thing; the risk multiplier. Let’s change the currency pair here, start another test, now we have a result, we made a total net profit of 133 dollars and 30 Cents. Set the default risk, start the next test. This time is the total net profit of 487 Dollars and 86 Cents. Let’s increase the risk multiplier to 1.2, start another test and see what happens! This time we made a total net profit of 105 491 Dollars and 34 Cents, so that’s a completely different game. We didn’t change anything in the code, we didn’t change the entry, and all we changed was this risk multiplier. This is how it looks like in the current German version of the Trading Framework I am testing, so you could use this code in your own trading framework and if you don’t know how to code something like this you can go to the MQL5 course and learn how to do it yourself or visit the website: forextradingframework.com but remember if you have a balance that is above 400 000 and you see a drawdown that’s going below 250 000 and it’s real money that might give you a very hard time and a few sleepless nights. Not many people can do that but if you are one of the few who can, it’s possible to earn a good amount of money with this.
    6 min
  • MQL5 TUTORIAL – SIMPLE ITEMA EXPERT ADVISOR
    This time we are talking about the ITEMA Indicator. This is for the Triple Exponential Moving Average Indicator. You see this red line here. If we pass the strategy test and hover over the red line you will see that it is called the Triple Exponential Moving Average and its calculated based on 14 candles. In this video we are going to find out how to create an Expert Advisor to calculate a Triple Exponential Moving Average Indicator and how to improve the frequency of the signals that are created. To do that please click the little button here in your 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” from template (template), Continue (Next). I will call this one: “Simple ITEMA” (SimpleITEMA). Click on continue, continue and finish. Now everything above the “OnTick” function can be removed, let’s also delete the two comment lines. First we need to create an array for the prices, that’s done by using “MqlRates” and the array will be called: “PriceArray”. We use the MQL5 built-in function “ArraySetAsSeries” to sort the price array from the current candle downwards and with “CopyRates” we fill the array for 3 candles. That’s enough to calculate the current candle and calculate crossovers. “CopyRates” takes a few parameters, first one is the symbol parameter – that’s for the current currency pair on the chart – the second one is for the currently selected period on the chart. We start with candle zero; that’s the current candle, copy the data for 3 candles and store it in the price array. In the next step we to create another array for the Expert Advisor data, that will be called “EAArray” and the Expert Advisor array also need to be sorted by using “ArraySetAsSeries”. Now it’s time to actually define the ITEMA Expert Advisor. That is done by using the built-in function: “iTEMA”, it takes a few parameters: the first one once again is the currency pair on the chart, the second one is once again the selected period on the chart, these are 14 candles because if you click on “Insert -Indicators -Trend -Triple Exponential Moving Average” you will see that the default value for the built-in indicator also is 14 candles. We use a shift value of 0 here and it applies to the close price, so that’s what we are using here: shift value 0 and “PRICE_CLOSE “. Now that we have created the definition we use “CopyBuffer” for the ITEMA definition (iTEMADefinition) we have created here. The 0 is for the first buffer, this 0 stands for the current candle, the 3 is to copy 3 candles and we want to save it in the array called: “EAArray”. Now that we have done that we calculate the ITEMA value (ITEMAVALUE) for the current candle 0 in our array. I use float, usually it’s a double and if you press F1 you will see that a double variable is 8 bytes in size, a float variable only takes half of the size and it’s better to read for us humans. So, let’s create a chart output depending on the direction. If the ITEMA value is bigger than the close price of the first candle in the price array – remember the first candle is always this one, this is candle zero, candle one, candle two and so on – so, if this expression is true we use the “Comment” function to output the text: “iTEMA IS SHORT”, followed by the calculated ITEMA value. In the other case if the close price for candle one in our price array is above the ITEMA value we will output: “iTEMA IS LONG”, also followed by the value. Okay, that’s it. When you are done you can click on the compile button here, we get a warning that says that we have a possible loss of data due to type conversion, that’s because I used a float variable here but for this little Expert Advisor that is okay. So, if the compilation works without any errors you can click the little button here or press F4 to go back to Metatrader. In Metatrader please click on “View -Strategy Tester” or press CTRL and R and now you should select the file: Sim...
    8 min