MQL5 Tutorial

MQL5 Tutorial

By Raimund BauerBusinessTechnologyInvesting
Download on the App Store

All MQL5 Tutorial episodes

  • MQL5 Tutorial – Simple Williams Percent Range Robot with MQL5
    You might have heard of the Williams’ percent range indicator? It can be inserted by clicking on insert, indicators, oscillators, Williams’ percent range. This is a very easy oscillator. It has one line. It was created by Larry Williams and it has a negative scale -100 means you have the lowest low of the past n days. Thats fourteen, because if you click on properties of Williams’ percent range you will see that it is calculating for a period of fourteen candles and if it’s hitting the zero line, that means it’s the highest high of the past n days. The idea is, to find peaks that are outside this range. So here you would like to sell and here you would like to buy. Now how can we create an Expert Advisor for this indicator? Well first we click on this little button or hit the F4 key to bring up the MetaEditor and there we will select file, new, expert advisor from template continue, and we will call this one simple Williams percent range. Click on continue, continue, finish and delete everything above the OnTick function. Now let’s remove the two comment lines here and in the first step we are going to create an array for our prices. This one is called WPR array. Now we need to define it. This is done by using the iWPR function for the current symbol on the chart and the selected period on the chart, for example this could be the Euro against the U.S. dollar on the one minute chart. And we need to define for how many candles we want to calculate the indicator. We would choose fourteen here, because the default indicator in Meta Trader is also defined that way. And in the next step we want to sort the price array from the current candle downwards by using the function arraysetasseries for the array we have created here. And now we will use the copybuffer function to fill our WPR array for the one line it has, from the current candle zero downwards for three candles. And we do it according to the definition we have created here. So let’s calculate the value. We will use the normalizedouble function to get the candle zero, that’s the current candle on my chart from the price array and we want to have an output with two digits behind the dot, because that will match the MetaTrader indicator that is built in. Okay, the last thing is the output on the chart. We will use the comment function to print out the text WPR value and the calculated value from this line. So let’s compile the source code here and we have zero errors and no warnings. So now we can click on the button over here or press the F4 key to bring up the MetaTrader. And in the MetaTrader we click on View, strategy tester or hit the control and the R key, that will show that strategy tester panel here and here we will select the simple Williams percent range.ex5 file. Let’s enlarge the panel a little bit more to enable the visualization mode here and start your test. And now it’s going to calculate the value here and if it’s below this dotted line her, you won’t expect to see a price change in the other direction. Let’s see if this is true – and here we are. And in the other case when it’s above this dotted line here, you would expect the price to fall. It took a little while, but it actually happened. You might also notice that it gave several false signals here. So let’s stop that test and change the value to 100, compile the code again, start another test and now it should create far less signals. Let’s zoom in here and you will see: here is a peak and if you would have sold here, you would have made a large profit. Let’s speed that up a little bit and it re-entered here and now it goes up and this also would have been profitable. Okay now you know how you can create an Expert Advisor for the Williams’ percent range indicator and you’ve done it with a few lines of source code in MQL 5.
    6 min
  • MQL5 Tutorial – Simple trend based sell stop
    In this video we are talking about a sell stop that is triggered whenever we have a trend that is going down. That is called it a short trend and if this value is negative we will create a sell stop here that is triggered when the price crosses the line we have set for our pending sell position. Now how can we create an Expert Advisor that will open a pending sell stop when we have a short trend and when we have no other orders or positions? Well, to do that please click on the little button here or press F4 in your Meta Trader and now you should see the Meta Editor and here you want to click on File, New, Expert Advisor from Template, Continue. I will call it Simple Sell Stop, Continue, Continue and finish and now you can delete everything above the OnTick function. To open our Sell Stop we need to include the trade.mqh file. That’s a library that is included with MQL 5 and it will enable us to create an instance of the Class Ctrade. In this case it will have the name trade and we will use this one to open our Sell Stop. Let’s remove the two comment lines here and in the OnTick function we are going to create an array for several prices. We want to use a simple moving average, that’s the red line here and that can be done by using the function iMA for the current symbol on the chart and the currently selected period on the chart. Our moving average will be calculated for one hundred candles. It will have shift value of zero, we will use Mode SMA because Mode_SMA stands for a Simple Moving Average and we use Price_Close because we want our iMA to be calculated for the close price of the candles. Now that we have done that we want to sort the price array from the current candle downwards by using array set as series for the moving average array we have created here. With Copybuffer we want to fill the moving average array according to the moving average definition that we have created here, for the first and only buffer, starting from the current candle zero, for ten candles. And one more thing, to open a sell stop position we need the bid price and we get the bid price by using Symbol Info Double for the current symbol and we use Symbol_Bid and with NormalizeDouble and _Digits we get the right number of digits behind the dot, because depending on the currency pair you will have either three digits or five digits. Now let’s calculate the long term trend, it’s a double value. We will call it Trend100 and we will calculate it by taking the value of the current candle and subtracting the value of the candle before. And if that is negative that would mean the trend is falling, because Trend One hundred is below zero. We want to check another condition, because we only want to open another pending order if no open positions or orders exist. That can be calculated by checking if the result of PositionsTotal() equals zero, and checking if the result of OrdersTotal() also equals zero. And if that is true we use trade.sellstop for ten micro lots. The sell stop will be one hundred points below the current bid price, for the current symbol, we have not defined a stop loss and the take profit will be three hundred points below the current bid price. We use ORDER_TIME_GTC because ORDER_TIME_GTC is good until we cancel the order manually so it doesn’t expire. So the expiration time here is zero and the last parameter is also zero. This one would stand for a comment but we don’t need one. That’s almost it. To see what’s going on we want to use the comment function to output the text, “Trend100” and the calculate trend on our chart Now let’s click on compile or press the F7 key and the compilation process worked without any errors, so now 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 you can also press control and R on your keyboard. And in the Strategy Tester you want to select the SimpleSellStop.ex5 file,
    8 min
  • MQL5 Tutorial – Simple Order Cancel Order EA
    Today we want to talk about a system that is called OCO that is the short term for Order Cancels Order. If you look on our chart we have a sell stop here and we have a buy stop there and here is where the price is and if the price moves to the sell stop that would trigger a short position. And if the price rises and hits the buy stop we would have a long position. Now what’s the difference between an order and a position? You use an order if you want to open a position so you can place your orders in the market and if the price moves and hits your pending order it will become a position. You see that we have cancelled the other order now. It’s no longer here, so let’s find out how to create an Expert Advisor that can cancel pending orders. To do that please click on the little button here or press the F4 key and once you have done that piece click on File, New, Expert Advisor from Template, Continue. I will call it Simple Cancel Order, Continue, continue and finish and now you want to remove everything above the OnTick function and the two comment lines here. And to have anything to close we first need to import the file trade mqh by using the include function. We want to create an instance of the Class Ctrade and that will have the name trade. In the first step we need to get the account balance that is done by using account info double, Account_Balance. Now we need to get the equity by using account info double, Account_Equity and we also need the ask prize here we use symbol info Double_Symbol for the current chart and the constant Symbol_Ask. We also use normalized Double_Digits because we have currency pairs with five digits and other currency pairs with three digits and now we do exactly the same to get the bid price, but this time we use Symbol_Bid. Now if we have no open position and no order, so if positions total equals zero and if orders total also equals zero, we need to open a pending order for a buy stop and another one for the sell stop, the position size is ten micro lot. In both cases the buy stop order will be placed one hundred points above the ask price and the sell stop order will be placed one hundred points below the bid price. For the current symbol we have not defined a stop loss, the take profit is three hundred points above the ask price and two hundred, no let’s also use three hundred points below the bid price. We use other time GTC that means the order will stay until we cancel it, so we have no expiration time here. If we would use an expiration time we would use this parameter to define it and the last parameter here is for a comment but we don’t need that. If we are trading right now – that would mean that the balance has different value than our equity. We want to cancel the open orders so let’s create a function called cancel order. It’s a void type because it doesn’t need to return any kind of value and here we use For Loop. It starts by using orders total minus one and until the value for the counter is zero that means as long as we have open orders it will go through all the open orders. We use order get ticket for the current order to find out the ticket number and it now will delete the pending orders by using Trade.OrderDelete for the order ticket that we have calculated here. And the last thing we need to do is to close the For Loop and the cancel order function. Now let’s compile the code by clicking the little button here or pressing the F7 and that did actually work without any errors. So now please click here or press F4 to go back into Meta Trader. And in MetaTrader you want to click on View, Strategy Tester or press control and R, and here you want to select the Simple Cancel Order.ex5 file, select any currency pair and enable the visualisation mode. After you have done that please start your test. And here you see two pending orders; one is a buy stop and another one is a sell stop so let’s zoom in and see how it works. That’s a little bit slow so let’s speed it up here.
    7 min
  • MQL5 Tutorial – How to spot a doji on your chart
    From time to time people ask about candle patterns. Is it possible to use MQL5 to detect something like a Doji? So if you don’t know what a Doji is this would be one, it’s a candle where the open price and the close prize are exactly the same. If you visit Wikipedia you will learn that a Doji is formed when opening and closing prices are virtually the same and if that happens on the lower end of the candle it would be a Grave Stone Doji and when it happens on the upper end of the candle it would be a Dragon-Fly Doji. So let’s create a simple Expert Advisor in MQL5 that is able to find a Doji on your chart. To do that please click on the little button here in your Meta Trader or press you F4 key, that will bring up the MetaEditor here, and here you want to select File, New, Expert Advisor from Template, Continue, I will call this Expert Advisor Simple Doji, Continue, Continue and finish. And now you can delete everything above the OnTick function here and let’s remove the two comment lines. Now we will use MQLrates to create an array for price information and with arraysetasseries we will sort our price information array from the current candle to the oldest candle. Now we want to copy our price data into the array. To do that we use copy rates for the current symbol on the chart and the currently selected period. We will start with the current candle, that is candle zero and we will collect all the bars that are currently on the chart for that symbol and that period we have selected here. All that price data will be stored in the price information array you have created here. And now we want to calculate if the last open price equals the last close price. That is done by using the IF statement and if open price for candle one in our price information array equals the close price of candle one in our price information array, we use comment to output on our chart ‘Candle one is a Doji.’ Now in the other case when the open price of candle one in our price information array doesn’t equal the close price of candle one in our price information array, we would create a chart output that candle one is not a Doji. Now let’s compile the code here and that was successful, we don’t have any errors and any warnings so now we can click on a little button here to go back to Meta Trader. And in Meta Trader you want to click on View, Strategy Tester or press Control and R on your keyboard to bring up the Strategy Tester panel. Here you want to select the Simple Doji.ex5 file, pick any currency here and please enable the visualisation option before you start your test. And this is how it looks like. You will see the text ‘Candle One is not a Doji’ but the text will change every time when we see a Doji on our chart. So this would be one and this would be another one so now you know how to spot a Doji on your chart and you have coded it in five minutes with a few lines of MQL 5 codes.
    5 min
  • MQL5 Tutorial – Advanced Bollinger Band Trading
    Today I would like to talk about my favourite entry, this is the Bollinger Band’s indicator and right now it is trading several different positions. The Bollinger bands was the first indicator that actually made a profit for me and from that day on I was convinced that I could make it. Now about three years later it is running in my own framework and I will speed it up a little bit and show you the results here. And while this strategy test is running, let me explain how I do it. I import some framework components that will do all the trade management, all the marked functions here are part of the Golden Goose framework so the only thing I have to do is to include the mq5 file for the entry. In the OnTick function I check for an entry and afterwards I call the trade management by calling the Check For Tick function with the entry signal. And the entry signal in our case is included in an mq5 module called Check Entry Bollinger bands. Create an array for the prices by using mql rates and the array has the name price info and with arraysetasseries our price info array is sorted from the current candle downwards. With copyrates we fill the array with price data for the current symbol and the current period from the current candle zero for three candles and the result will be stored in the price info array we have created here. If you would like to have more than three candles, you could replace this line with the one above because this one will give you all the price info for the bars on the chart. But three candles is enough for me and it’s faster to calculate. In the next line we create a string variable for the signal that will be called Signal, and we need to create an array for several prices for the middle, the upper and the lower band of the Bollinger bands, because the Bollinger bands indicator uses three different lines. These arrays also need to be sorted by using array set series. Here is the Bollinger band’s definition that is created by using iBands for the current symbol and the current period. If you insert the indicator Bollinger bands here you will see that we used twenty candles, the value for the deviation is two, and the value for the shift is zero and that’s exactly what we use here, twenty candles, no shift and deviation two, and the calculation is based on the closed price. Now with Copy Buffer we use the Bollinger bands definition we have created here to fill the middle, the upper and the lower band with the price data we need. We now want to calculate the Expert Advisor for the current candle, so we create a variable my middle band value zero, my upper band value zero and my lower band value zero, and assign the value of candle zero for each of our three arrays. To calculate the Expert Advisor for the candle before, we do exactly the same for candle one. The rest is very simple if the price info for candle one for of the close is below my lower band value one and the price info for the current candle for the close price is now above my lower band value zero, that would be an entry for a buy signal. So the signal would be buy and in the other case it would be a sell signal. That is when the close of the last candle was above the upper Bollinger band and the close of the current candle is below the upper Bollinger band and now we would like to sell. And in the last step we return the signal here to the framework and that would now call the trade management with a Buy or a Sell signal. This is the result of our Golden Goose framework trading with the Bollinger bands for the Australian against the Canadian dollar from the 1st January of 2016 to the 1st January of 2017. Now let’s change the currency pair. I will enlarge this a little bit, and to speed up things for this little demonstration I will remove the visualization option here and start the test. Now you can see how it works within seconds, we should be finished in a few more seconds and here is the result.
    8 min
  • MQL5 Tutorial – Simple Chart Objects
    This time we are going to create simple objects. Each time a tick comes in, one of these objects will be painted here. Usually you will see things like arrows up and down, but actually there are a lot of more possibilities for such an arrow symbol. Everything you see here is called an arrow even if it doesn’t look like one. Now how can we create an Expert Advisor in MQL5 that is going to draw objects like these? To do that, please click on the little button here or press the F4 key on your keyboard. And that will bring up your MetaEditor window and here you want to select File, New, Expert Advisor from Template, Continue. I will call it SimpleChartObjects here, Continue, Continue and finish. And now you can delete everything above the OnTick function and the two comment lines here. And first we need an array for prices, we can create one by using MQLrates and it will have the name Price Information, now we are going to sort the array downwards from the current candle by using arraysetasseries and by using copyrates we are going to fill the price information array for the current chart and the period selected on the chart from the current candle zero for all the bars on the chart and store the values in our array. And now we are going to create a static counter, it will be an integer with the name i, and we will use that value to actually create an arrow with the name MyArrow. Please remember in MQL 5 an arrow can look like a circle or a square or anything else. So we use ObjectCreate for the current chart and our object will have the name MyArrow and we use OBJ_Arrow to create it. The next parameter would be a sub window; we will use a zero here because we are going to create the arrow here in the main window. You might have seen indicators that use a sub window below. We will use the current time and the arrow should be placed on the highest point of the current candle in our price information array we have created here. And with object set integer for the current chart, and the object, my arrow, we use OB J Prop_Arrow Code, and the value of the static counter to change how our object looks. Currently we have the value 179 and as soon as that changes to 180 the arrow code changes and so does the way our arrow looks. And for 181 our arrow would look like this; let’s select a color here, that is done by using objects set integer for the current chart for the object with the name My Arrow and we use OBJ_Prop_Color and we would like to have the color green. If you press F1 on your keyboard you will see a lot of other colors that you can use. To make our object a little bit bigger we’re using object set integer for the current chart for the object with the name MyArrow and we use the OBJProp_Width to set the size to 20. And now we move the object by using ObjectMove for the current symbol and for the object with the name MyArrow on the main window we used, for the current time and we move it to the highest prize of the current candle. I would actually like to have a chart output for the current counter value so we use comment to output the text “i has the value” followed by the current value of the static integer variable i. And in the last step we are going to increase our counter by one, that is done with I++ and now the next time a tick comes in we should see another symbol on the chart. Okay that’s it; let’s compile the code here and that worked without any errors. So please click on the little button here or press F4 on your keyboard to go back to MetaTrader. And in MetaTrader click on View, Strategy Tester or press control and R to bring up the Strategy Tester Panel here and there you want to select the file SimpleChartObjects.ex5. Let’s start the test after you have enabled the visualisation option here and for the first 20 counter values nothing changes, but around 30 you will see changing symbols on your chart and now you actually know how to print dynamic symbols on your chart and you have done it within a few minutes...
    7 min
  • MQL5 Tutorial – Simple object oriented line
    In this video we are going to talk about an object. It will be a horizontal line and this horizontal line moves to the highest candle within the last one hundred candles on the chart. This could for example be a good idea to define a trading range and you could also use it to measure the difference between the highest and the lowest candle, and maybe you will also come up with other ideas. Now how can we create an Expert Advisor that will draw our little object here and move it to the highest candle? To do that, please click on the little button here or press F4 on your keyboard and that will open the Meta Editor and here you want to click on File, New, Expert Advisor from Template. I will call it Simple Object Line, Continue, Continue and Finish, and now we want to remove everything above the OnTick function and the comment lines. First we create an integer that variable will hold the highest candle number and we need an array because we have several candles and that array will be sorted downwards from the current candle by using array set as series. We will use Copy High to fill the array with data for the last one hundred candles for the current symbol and the current period from the current candle zero for one hundred candles and this is our target array we have created here. Let’s remove the one here and our highest candle will be calculated by using Array Maximum for our array from the current candle for one hundred candles. Now we create another array for our price data, it will be called price information and we create it by using MQL rates that array also needs to be sorted by using array set as series and now we copy price data into the array by using copy rates for the current symbol and the current period. The starting position will be the current candle zero, and this expression here will give us all the price data that is currently on the chart and all the price data will go into our price information array. Now we can use Object Create for the current symbol, the object we create will have the name Line One. It’s horizontal line and that can be created by using OBJ_HLINE. This zero stands for the current chart window; you could also see it when you use the Tool Tip Function here. The next parameter would be the DateTime, this is also zero and the third parameter is the price information we need. And here we want to have the highest candle, we have calculated it here and from the highest candle we need the high. That’s because we want to draw our horizontal line above the highest candle. We use ObjectSetInteger OBJ_Prop_COLOR to set the color to red and we use ObjectSetInteger OBJ_Prop_WIDTH to set the width of the line to three, and at the end of the function we move the line that’s the same value here that we have used when we created the object. Nnormally we only would create the object once, but for this simple example it is okay to use Object Create and Object Move in the same function. Okay that’s it. Let’s compile the code and that worked without any errors so let’s click 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 control and R, select the simple objectline.ex5 file, enable the visualisation mode and click on Start. Here is our Expert Advisor at work, let’s press minus to make it visible, and now you can see the horizontal line object actually move to the highest of the last one hundred candles. Okay now you know how to create an object for a horizontal line and you have created it with a few lines of MQL5 code.
    6 min
  • MQL5 Tutorial – How to trade any entry you like
    This is the English version of the Golden Goose framework. A framework basically can help you to simplify your automated trading because it does all the trade management for you. Right now the Golden Goose framework is trading a sixty minute moving average and I would like to show you how easy you can change the entry here, all you have to do is click this little button here or press the F4 key. That will open the Meta Editor and this is the main file, it does the import for the framework components. These are all imported functions that will handle the trade management, here we include the current entry for the sixty minutes moving average and in the OnTick function we check for an entry by calling the Check Entry function. That is included in this file and afterwards we call the trade management by delivering the signal to the Check For Tick function. If I want to change the entry here, I will outcomment the current entry and I will now include Check Entry_MacD.mq5 and compile the file by clicking the little button here or pressing the F7 key that worked without errors. So now we click on the little button here or press F4 to go back to Metatrader, and in Metatrader we click on View, Strategy Tester or we press control and R, and select the exact same framework we have traded the last time. Let’s start the test here and now it’s trading the MacD. Let’s stop the test, outcomment the MacD, and this time we are going to trade Bollinger bands. Let’s stop the test and this time it is trading the Bollinger band entry. Okay let’s do one more and uncomment the Bollinger bands and go for the RSI. Compile the framework, start another test and here is the RSI. Let’s speed it up to the limit here and now you can see that it actually works and all the trade management is done by predefined functions that are contained in the Golden Goose framework. This is what we have created in a German premium course within the first fifteen to twenty weeks. Imagine how much time you can save if you can start to trade systems like this one right away. It even gets faster if you disable the visualisation note here so let’s remove the RSI and do a simple crossover entry here, recompile the framework again and start another test. This time it’s much faster and you will see results within twenty or thirty seconds. So the simple crossover entry would have made $2,405, in this case. It made 233 trades fully automated in less than a minute. 94% of the short trades and 95% of the long trades were profitable and with the Golden Goose framework it is possible to trade all the different entries here and get results like this right from the start and within a few seconds. So if you would like to trade fully automated, and if you would like to see results like this one right from the start, the Golden Goose MQL 5 trading framework might be the right choice for you and it’s easy for you to get one or to build your own version of it you just have to become a member of the premium course and you can start right away to improve your own trading results. So let’s go for it today and enjoy the benefits of automated MQL 5 trading.
    6 min
  • MQL5 Tutorial – How To calculate 3 iADX Indicator Values
    Today we are going to do a very simplified version of the Adaptive Directional Movement Index. Our version will calculate the current value of the IADX for each of the three lines the indicator will show. That is the value you see if you hover with your mouse over the blue line here, right now it is 27.09. That’s the value you see here and that’s the calculated value we also will output on our chart. Now how can we create an Expert Advisor in MQL5 that is going to calculate the IADX value for us? To do that, please click on the little button here or press the F4 key. Now you should see the MetaEditor and here you want to click on File, New, Expert Advisor from Template, Continue. I will call it Simple IADX here, Continue, Continue and Finish. Now we want to delete everything above the Ontick function and the two comment lines here are also no longer needed. The first thing we need is an array, so let’s create an array for several prices, it will be a double array and it will have the name My Price Array. And now we are going to use the IADX function to create a definition for the current symbol on the chart and the currently selected period. It will calculate IADX value for fourteen candles, because when the IADX indicator was developed in 1978 J. Welles Wilder, it was defined for fourteen days. If you click on Insert, Indicators, Trend, Average Directional Movement Index, you will also see the fourteen candles here. Now we want to sort the price array from the current candle downwards by using Array Set as Series for the price array we have created here. The function Copy Buffer will now fill our price array according to the IADX definition we have created in this line for one line, that’s the zero here, for the current candle that’s the second zero and we need the price data for three candles that’s the three here to store the result in our price array. To get the value of the current candle, we create a double variable with the name IADX value and we will use normalize double for two digits behind the dot to get the value of candle zero, that’s the current candle in our price array. And here comes the chart output: by using the comment function we will output the text “IADX Value” and the calculated value directly on our chart. Now and that everything is done please click on the compile button or press the F7 key on your keyboard. You should be able to compile your code without any errors and without any warnings. And if that did work for you, you can click on the button here or press the F4 key to go back to MetaTrader. In MetaTrader please click on View, Strategy Tester or press control and R. And now you should see the Strategy Tester Panel and here you want to select the Simple IADX.ex5 file. Now let’s start the test and here is our little Expert Advisor at work. Let’s stop it and you’ll see the first value here is 23.09 and that matches with the IADX value we have calculated here. Let’s see if we also can get the second value here. So let’s go back into Meta Editor and replace the zero here for the first line of the indicator with a one. Recompile the code and start another test. And now you will see the second value here. If you want to get the third value you simply have to replace the one with a two, recompile the code and start again. And now of the output here matches the third value of this indicator. Okay, now you know how you can calculate the ADX value for each of the three lines of the Average Directional Movement Index and you have done it with a few lines of MQL5 code.
    6 min
  • MQL5 Tutorial – Simple Money Flow Index Expert Advisor
    Today we are going to do a very simplified version of the Adaptive Directional Movement Index. Our version will calculate the current value of the IADX for each of the three lines the indicator will show. That is the value you see if you hover with your mouse over the blue line here, right now it is 27.09. That’s the value you see here and that’s the calculated value we also will output on our chart. Now how can we create an Expert Advisor in MQL5 that is going to calculate the IADX value for us? To do that, please click on the little button here or press the F4 key. Now you should see the MetaEditor and here you want to click on File, New, Expert Advisor from Template, Continue. I will call it Simple IADX here, Continue, Continue and Finish. Now we want to delete everything above the Ontick function and the two comment lines here are also no longer needed. The first thing we need is an array, so let’s create an array for several prices, it will be a double array and it will have the name My Price Array. And now we are going to use the IADX function to create a definition for the current symbol on the chart and the currently selected period. It will calculate IADX value for fourteen candles, because when the IADX indicator was developed in 1978 J. Welles Wilder, it was defined for fourteen days. If you click on Insert, Indicators, Trend, Average Directional Movement Index, you will also see the fourteen candles here. Now we want to sort the price array from the current candle downwards by using Array Set as Series for the price array we have created here. The function Copy Buffer will now fill our price array according to the IADX definition we have created in this line for one line, that’s the zero here, for the current candle that’s the second zero and we need the price data for three candles that’s the three here to store the result in our price array. To get the value of the current candle, we create a double variable with the name IADX value and we will use normalize double for two digits behind the dot to get the value of candle zero, that’s the current candle in our price array. And here comes the chart output: by using the comment function we will output the text “IADX Value” and the calculated value directly on our chart. Now and that everything is done please click on the compile button or press the F7 key on your keyboard. You should be able to compile your code without any errors and without any warnings. And if that did work for you, you can click on the button here or press the F4 key to go back to MetaTrader. In MetaTrader please click on View, Strategy Tester or press control and R. And now you should see the Strategy Tester Panel and here you want to select the Simple IADX.ex5 file. Now let’s start the test and here is our little Expert Advisor at work. Let’s stop it and you’ll see the first value here is 23.09 and that matches with the IADX value we have calculated here. Let’s see if we also can get the second value here. So let’s go back into Meta Editor and replace the zero here for the first line of the indicator with a one. Recompile the code and start another test. And now you will see the second value here. If you want to get the third value you simply have to replace the one with a two, recompile the code and start again. And now of the output here matches the third value of this indicator. Okay, now you know how you can calculate the ADX value for each of the three lines of the Average Directional Movement Index and you have done it with a few lines of MQL5 code.
    6 min