MQL5 Tutorial

MQL5 Tutorial

By Raimund BauerBusinessTechnologyInvesting
Download on the App Store

All MQL5 Tutorial episodes

  • MQL5 TUTORIAL – PLATIN SYSTEM – ENVELOPES ENTRY SIGNAL
    In this video we are going to code the Envelopes indicator for our Expert Advisor entry signal. That is the red and the blue line you see here on the candle chart. So let’s find out how to do that with MQL5.   The Envelopes indicator is drawn on the candle chart.   It has an upper band and a lower band.   To use it, we create a separate MQ5 file inside of the directory where the other files of the Platin System are located.   The name of the file is CheckEntry_Envelopes.mq5 and it contains a single function that is called CheckEntry.   We use it to calculate the entry signal for our trading system.   First we create a signal but we don’t assign a start value.   The type of the signal is either buy or sell, so we use a string variable.   Of course we also need to create an array.   That can be done with the MQLRates command.   To sort our array from the current candle downwards, we use ArraySetAsSeries.   And afterwards we can fill our array with data.   That is done by using the CopyRates command.   The first parameter is the current symbol on the chart.   The second parameter is for the period that is selected on that chart.   The third parameter is for the candle where we want to start, in our case it is the current candle 0.   The fourth parameter is for the number of candles that we want to store the price data for.   We pick 3 candles here.   And in the last parameter we can define the target array, which is our price information array.   Let’s create two more arrays.   One is for the upper band, so we call it upper band array.   The other one is for the lower band, that one is called lower band array.   Both arrays also need to be sorted downwards by using ArraySetAsSeries.   The next step is to create the definition for our Envelopes indicator. We use the builtin function iEnvelopes that comes with MQL5 and pass the following parameters.   Parameter 1 is the current chart symbol.   Parameter 2 is the period on that chart.   Parameter 3 is the number of candles for the calculation, we use 14 here. That is also the default value when you drag the envelopes indicator on the chart.   The next parameter is for a shift value. We don’t need to change that, so we use 0 for parameter 4.   Parameter 5 defines the moving average values for the calculation. MODE_SMA stands for simple moving average. That is what we want to use here.   Parameter 6 is used to define if we want to calculate the values based on the close prices which is what we want to do.   And the last parameter is a deviation value. The default is 0.100, so we use that.   Now we use copy buffer to fill our arrays.   We do that according to the definition that we have created above.   Either for buffer 0, that is for the upper band or for buffer 1, that is for the lower band.   We start with candle 0 and copy the values for 3 candles into our arrays.   Now we can calculate the values for both bands by looking at the value of candle 0 in our array.   We use NormalizeDouble and the value 6 to format the output for 6 digits behind the dot.   So let’s calculate the signal.   If the close price for candle 1 is below the lower band value, we consider that to be a buy signal, so we assign the word buy to our signal if that is true.   Otherwise, when the close price for candle 1 is above the upper Band value, that would be a sell signal. In that case we assign the word sell to our signal.   And if the close price for candle 1 is below the upper and above the lower envelopes band, we want to reset the signal and remove the buy or sell signal from before.   Finally we can use the return statement to give back the entry signal to our main module.   Please save your entry file, you don’t need to compile it as it will be compiled with your main file.    There you can use two slashes to outcomment other entry signals and use the include function to activate the new file CheckEntry_Envelopes.mq5 to use the envelopes indicator in your system.
    6 min
  • MQL5 Tutorial – Advanced Trading Range Calculation
    In this video we are going to create an Expert Advisor that can define a trading range so what is a trading range? You see the two lines here and the upper line is above the highest candle of the last one hundred candles and the lower line is below the lowest candle of the last hundred candles and here we have a very narrow range, it is calculated here and it says it’s now about 0.1659 and we could wait until the range is above one if we just want to trade a breakout. Now let’s see what happens if the price changes. I will speed it up a little bit here, now you can see our range grow, it is 0.37 right now and now it’s above one- that’s a really big candle here. And if you like to trade volatility maybe you want to learn how to calculate something like this, now how can we create an Expert Advisor that is able to calculate a trading range? To do that please click on the little button here in Meta Trader or press your F4 key and that will bring up the Meta Editor, and we need to create an mq5 file with the name Advanced Trading Range, it has only one function called Void OnTick, here we are going to create a variable for our trading range. It’s a double variable, now we create a variable for the highest and the lowest candle called highest candle and lowest candle. This is an integer variable because it’s the number of the candle. And we need to arrays, these are double arrays called high and low, and we sort both arrays downwards from the current candle by using array set as series for the array with the name high and array set as series for the array with the name low. And now we want to fill our array with data for one hundred candles; the high array will be filled by using Copy High for the current symbol and the current period from the current candles zero for one hundred candles, and we need the highest points of the candles. And with Copy Low for the current symbol on the chart and the current period from the current candles zero for one hundred candles we now need to know the lowest value for one hundred candles. Let’s actually calculate the highest candle that is done by using array maximum for the array with the name high from the current candle zero for one hundred candles. And to calculate the lowest candle we use array minimum for the Array Low from the current candles zero for one hundred candles. Let’s create another array for price information, it will be called Price Information and we create it by using mql rates. We start it from the current candle downwards by using array set as series for our array price information we have created here and with copy rates, we copy price data into our array for the current symbol and the current period from the current candle for all the bars that are visible on the chart and the result will be stored in our array called Price Information that we have created here. So let’s create the upper line first we set the object properties for the upper line, that is done by using Object Create for the current symbol, it will be called line one. We use OBJ_HLine because it’s a horizontal line and this zero stands for the window we are going to use, in this case it’s the main window, some indicators us a window below the main window here and in that case we would use another value. The last two parameters are for the date/time and for the price we also use zero for the date/time and this expression here will give us the highest candle of the price information and from that candle we want to know the highest point. These two lines set the object colour and the object width and with Object Move for the current symbol and the object with the name Line One the rest of the parameters here equal the same values we have used above. We want to actually move the line every time our trading range changes. And for the lower line we actually do the same, the only difference is that our object now has the name line two and instead of the highest point we use the lowest point for the lowest can...
    8 min
  • MQL5 TUTORIAL – PLATIN SYSTEM – CALCULATING TODAYS PROBABILITIES
    An automated trading system is similar to an automated navigation system.   Most people think that an automated system should work in any situation and for every currency pair.   But actually this is not true.   It will react to one kind of reality and that will produce one kind of result.   Think of a road trip or your everyday commute.   Probably the time it takes is not equal each day.   You might get up at the same time as yesterday, but today it is raining.   You dress up a little differently and pick up your umbrella.   So you get into your car at about one minute too late.   Because of the rain the sight is not very good, so other people might drive slowly.   That causes a traffic jam on the highway and now you are really late.   So you try to take a different route that was suggested by your navigation system.   And that is probably exactly the same alternative route that is suggested to hundreds of other drivers who use the same navigation system.   Now the traffic jam you wanted to avoid is right in front of you, because the other people who wanted to avoid it also took the same route.   In this scenario doing what you thought would be the best option to avoid a delay actually caused the situation you wanted to avoid.   And I guess every car owner knows that there are problems that can’t be avoided all the time.   On some days you might have to deal with icy roads.   On other days some roads might be closed.   And your navigation system will do its best to help you to reach your destination as fast as possible, but it can’t help you to avoid accidents.   You are still the driver, you are the one who decides at which speed you take the next turn.   You decide if you listen to the advice of your navigation system or if you take the next exit on the highway. You wouldn’t expect your navigation system to be a fortune teller.   It works by calculating the probabilities, but it can’t tell you if a garbage truck is blocking the side road around the next corner.   And a trading system is doing the same thing.    It calculates the probabilities, but that doesn’t mean it can foresee the future.
    3 min
  • MQL5 TUTORIAL – PLATIN SYSTEM – BOLLINGER BANDS ENTRY SIGNAL
    In this video we are going to create the Bollinger bands indicator for the Platin System. But you can also use this entry signal for your own system or for the robot trading system. The Bollinger Bands actually is one of my favorite indicators and it was the first one that I used to create a profitable system. So let’s find out how to do that with MQL5. The Bollinger Bands indicator is drawn on the candle chart. It has an upper band, a middle band and a lower band. To use it, we create a separate MQ5 file inside of the directory where the other files of the Platin System are located. The name of the file is CheckEntry_BollingerBands.mq5 and it contains a single function that is called CheckEntry. This function calculates the buy and sell signals for our system.     We start with MQLRates to create an array called Priceinfo. Afterwards we use ArraySetAsSeries to sort our PriceArray from the current candle downwards. And then we use CopyRates to fill our PriceInfo array with data. The first parameter is for the current symbol on the chart. The second parameter is for the currently selected period on that chart. Parameter 3 is used to define from which candle we want to start. Parameter 4 is for the number of candles that we want. And the last parameter is the target array where we want to store the prices.     Now we will create a string variable for the signal, but we don’t assign a value. The next step is to create three arrays, one for each of the Bollinger Bands. Of course, we need to sort those also from the current candle downwards by using ArraySetAsSeries. MQL5 comes with a builtin function that is called iBands and we use it to create a definition for the Bollinger Bands.     The first parameter is for the current symbol on the chart, the second one for the period on the chart. The third one is for the number of candles we want to calculate. In our case 20 candles. Parameter 4 is a shift value. We don’t need that, so we set it to 0. Parameter 5 is for the deviation. We set it to 2, because that is the default value. And in the last parameter we can define that we want to do the calculation based on the close prices.     Let’s use CopyBuffer again to fill our three arrays with data for the middle, the upper and the lower band. We do it according to the definition that we have created before for buffer 0, buffer 1 and buffer 2, starting from the current candle 0, for 3 candles. That makes it possible to calculate the values for each band by looking at the candles 0 and 1. If the close price for candle 1 was below the lower band and if the current close price is above the lower band we consider that to be a buy signal, so we assign the word buy to our signal. In the other case, if the close price for candle 1 was above the upper Bollinger Band and is now below the band we would consider that to be a sell signal, so we assign the word sell to our signal.     Finally we return the signal to the main module by using the return statement. Now, please save the file. You don’t need to compile it as it will be compiled with the main module. Okay, by now you should have a working Bollinger Bands indicator entry module for your system. I actually like this indicator very much. So thank you for listening and I will see you in the next video.
    6 min
  • MQL5 TUTORIAL – PLATIN SYSTEM – WILLIAMS PERCENT RANGE ENTRY SIGNAL
    In this video we are going to create an Expert Advisor entry for the PlatIn System. But you can use it in your own system. And there’s also a demo version available for download. This is the the Oscillator that we are going to use. It’s called the Williams Percent Range. So let’s find out how to do that with MQL5.   The Williams percent range indicator is actually an Oscillator therefore it will be shown in a separate window below the candle chart. To use it. We create a separate MQ five file inside of the directory where the other files of the platinum system are located. The name of the file is checkentry WPR MQ five and it contains a single function that is called checkentry. This function calculates the buy and sell signals for our system. We start with a string variable called signal. But we don’t assign a value right away as we are going to calculate that later on in the next step we create an array we use the data type double as this data type can also be used with floating point values. Afterwards we create a definition for WPR signal by using the function IWPR that comes with MQL five. And we want to do that for the current symbol on the chart and the currently selected period on that chart. The last parameter is the number of candles that we want the calculation to be based on. When you open a MetaTrader chart and click on insert indicators oscillators Williams percent range. This is the value that you will also see as a standard value for the period.   But let’s continue with the entry module. Here we array set as series for our WPR array to sort it from the current candle downwards. Afterwards we can fill our WPR according to the definition that we have done above. We do it for buffer zero starting from candle zero for three candles and store the values in our price array that makes it possible to calculate the current WPR value by looking at candle zero in our array with normalized double. We make sure to format the output with two digits behind the dot as this is how the value also looks like when you add the oscillator manually to your chart now let’s continue with the calculation for the signal if the WPR value is below -80 and bigger than -100 we consider that to be a buying signal so we assign the word by to our signal variable in the other case if the WPR value is above -20 and below zero we would consider that to be a cell signal so that is when we want to assign the word cell to our signal. Finally, we return the signal to our main module by using the return function now please save the file.   You don’t need to compile the entry module as it will be compiled automatically when you include it in your main file. Changing an entry signal is easy to do with the Platinum system. Actually, you can also use the entry modules you create in your own system. All you need to do is to use the Include function in your main module. Entry signals are enabled or disabled with two slashes that will outcome at the entry signals that you don’t want to use and they will appear in gray color. To include an entry signal, you can use the Include command for the MQ five entry signal file. It is not required to compile the entry files as they will be compiled with the main module you use to include them. To compile the main file of your trading system and the entry file, just enable the toolbar and click on the compile button. You can also press the f seven key on your keyboard. The compilation process should work without any errors. If you have errors, or if you don’t want to type everything yourself, please visit our website and look for the shop as most of our source code files are available there.   There you will also find the premium course and other useful resources for automated trading.   Okay, so far so good. We have changed our entry signal for the Platin System, and if you don’t know how to start a strategy test, or if all that was too much, you might want to watch one of the other videos.
    7 min
  • MQL5 TUTORIAL – PLATIN SYSTEM – ADVANCED MOVING AVERAGE ENTRY
    In this video we are going to create an entry module for this little indicator here. It is called the adaptive moving average and you can use this entry signal to get buy and sell signals for the Platin system. So let’s find out how to do that. To change the entry signal for your Platin system, please open the main file and search for this part where it says include. Here we have check entry modules and if I want to change the module for the entry signal, I just need to outcomment the old one, like this, and enable the new one which is the Check Entry Advanced Ma module.   Here is what’s inside of the Check Entry CCI module that comes with the system. Now I can say that I want to save it as… And save it as Checkentry Advanced MA.mq5 in the same folder as the Checkentry CCI module is located. I have done that before, so I don’t want to do it right now. And here is what is inside of the module. By the way, you can create your own system and use it in your system – or in the robot trading system it’s also possible to use this entry. We start by using MQL rates to create a price info array. Afterwards we use array set as series for the price array we just created to sort it from the current candle downwards. Now we want to fill our array by using copy rates for the current symbol on the chart and the currently selected period on that chart. Starting from candle zero for 30 candles. That’s probably a little bit too much.   So let’s say we do it for three candles. And I would like to use the more current notation here. The next step is to create a string variable for the signal. And we also need to create a second array for the prices. Now comes the interesting part. We create an adaptive moving average definition by using the IAMA function that comes with MQL5. For the current symbol on the chart and the currently selected period on that chart. Here we have three parameters. And if you point your mouse on the adaptive moving average signal line here, you will see the parameters 9,2 and 500.   And if you click on insert, indicators, trend, adaptive moving average, you will see that these are the standard parameters. The period is nine, the fast EMA is two. The slow EMA is 30. So let’s change that to 30 here, because when we cut the last part and hit the comma key on the keyboard, we will see that this parameter here is for the slow EMA period. And that’s actually 30. But you can use whatever you like. I prefer to go with the standard parameters.   Now let’s continue. By using array set as series we are going to sort our price array from the current candle downwards. And now we can use copy buffer for the adaptive moving average definition that we have created here to fill our array for the first buffer. That’s the indicator line. Starting from candle zero for three candles and store the result in our price array. And now we can calculate the current adaptive moving average value by using normalize double and six digits, because the value is shown with six digits behind the dot. And we want to look at the value for candle zero in our price array and assign the result to this variable here.   That makes it possible to now calculate if we have a buy or a sell signal. Because if the adaptive moving average value is bigger than the close price for candle zero in our price info array, that would mean we have a buy signal. And that’s when we assign buy to our signal. Otherwise, if the adaptive moving average value is below the close price for candle zero in our price info array, that’s a sell signal. And that’s when we assign the word sell to our signal. Finally, we want to return the signal to our main module. Now please save the module that we have created, enable it here in the main module. And now we need to recompile that.   So please click on Compile in the toolbar or press F7. That should work without any errors here. And if that is the case you can click the little button here or press F4 to go back to the Platin System.
    8 min
  • MQL5 TUTORIAL – HOW TO GET THE 1000 PLATIN SYSTEM FOR FREE
    Platin System MQL5 TUTORIAL BASICS – 57 HOW TO CREATE METAQUOTES DEMO ACCOUNTS INSIDE METATRADER In this video, I would like to talk about a way how you can get the $1,000 Platin System for free. And here are my thoughts. Currently, we are facing a situation that I have never seen before in my lifetime. We are facing high energy costs and buying groceries is about twice as expensive as last year. So there are lots of people who face financial problems right now.   And on top of all this, there might be other sorrows. Not everybody has an idea about how the future might look like. And I understand that it is hard to sell a system for $1,000 in a time like this. But like Michael Voigt, the German guy who wrote the book that is called “The Great Book of Market Technique” once said: “The markets are not going anywhere. They will still be around next year.”   So if you are not sure if automated trading is something that you would like to try, there is a way to do it without spending a single dollar. And here is how. If you look at the output on the chart here, it says MetaQuotes-Demo. This is the server for original MetqQuotes demo accounts and you can open such a demo account for free. And I will provide an unrestricted version of the Platin System.   The only exception will be that you need to trade it on a MetaQuotes demo server account. So you basically can do everything that my $1000 clients can do, but you only can do it on demo accounts. And that will help you to get a good understanding about what works and how it works. Actually, I’m not trying to sell you something, because I’m only selling the Platinum system to long term customers who have already bought the premium course and who have already proved that they have what it takes to actually achieve good results. So the Platin System currently can only be bought with an invitation link. But I still remember that when I started out with automated trading, I needed a proof that it actually works! Because once you know that something works, you will find a way to get it – if it is something that you actually want.   I did that in the past and it worked very well for a lot of people. But I need to admit that I still think that not everybody has what it takes. There are still people around who think that they can push a button and become a millionaire overnight. This is not one of these offers! If you have what it takes, it is a way to get what you want. But actually I’m not able to change the person that is sitting right in front of your screen.   And that is the part that is actually more important than anything that has to do with automated trading. But most people still don’t get that. And if you open your own account and count your losses, you will probably still find out that the vast majority of all your losses is caused by YOUR OWN stop loss. And if you want to change that and improve your results, the Platin System might be a way to do that. In the next few weeks, I will provide some information for people who are really interested.   So if this is something that sounds interesting for you, you should subscribe, get MetaQuotes demo account and I will see you in the next video.
    5 min
  • MQL5 TUTORIAL ENGLISH – HOW TO PROFIT FROM A TREND CHANGE
    This video is about the topic of trend reversal. And as you can see quite well, the direction for the Euro US Dollar has surprisingly turned. In plain language, this means that we have two moving averages here. One for 1000 candles and the other for 1100 candles. And in the last few days, the price has been consistently above these two moving averages. So it was going back towards the uptrend. Until then, on September 13, a candle emerged that looks pretty huge and it’s down from a €1.01 to pretty much one euro. My system actually closed all positions here in profit as well. Strictly speaking, it’s not that every position was profitable. But that has never been the case in the past, because the system is designed to close positions when the account is in profit. The original deposit here is 10,000. Currently we have a profit of 451. I think US dollars. And right now my system is not trading at all because the price is on the wrong side of the trend.   What does it mean in plain language? If you zoom in on the chart here with the minus button, you can see very nicely that we’ve been trading a downtrend here the whole time. And for the most part, the price was below the two moving averages. That then changed briefly here at this point. And after this monster candle here pushed the price back to the other side, nothing is happening right now. And the reason for that is: we’re waiting for there to be the next crossover here. Only then will trading continue, because that would mean that the long-term downtrend continues. And if that happens, the system would continue to sell. But if the price turns and lands above the two moving averages without a crossover, then that would be a buy signal for us. And as long as this does not happen, our system does not trade at all. Of course, we could change this now by simply changing the two moving averages, for example. But that is not the point. The entry signal is not the reason why a system is profitable, but it still requires a defined rule for entry, which should also not be violated.   After all, every game has its rules and we’re not going to show up to a soccer game with field hockey gear and a tennis racket. My rule for this system is: if my entry signal and the long term trend match and the price is on the right side of the moving averages, then trade here accordingly. And that has worked well in the past since about mid-July. And that’s why I’m sticking with my entry criteria, even though it might be a little bit boring right now. But as it looks here, we should expect to see another crossover here in the next few hours. Okay, that was a practical part. Actually, it belongs in the course for the Platinum Group. But since we have this special situation here, I wanted to show it briefly. Because if a rule has proven itself, then it makes sense to stick to it. And I’ve been testing this for various years. And in this short video, you learned how to confirm your entry signal with two simple moving averages, to only trade when your signal and the long-term trend also confirm each other.
    3 min
  • MQL5 TUTORIAL ENGLISH – 3 COMMON ERRORS CAN LEAD TO SLEEPLESS NIGHTS
    In this video, we’ll look at one of the biggest problems in trading and how to solve it. And that’s why it’s hard to know what to do when the signal changes. After all, many traders think that the right time to close all open positions and open a new one in the opposite direction is when a signal changes. There are, in fact, strategies that are based on this idea, but you don’t have to do it this way. The new Platinum System is different.   The version shown in the video is one that was made by using MQL5. And it’s based on the opposite idea, which is that an open position has only one purpose, which is to make money. So, when the signal goes the other way, we don’t close the position in this case. In a trading system, the entry is not the most important thing. Of course, you need a clear entry, and we couldn’t make clear rules without a clear entry. But the point of entry doesn’t have to always point in the right direction for a system to be profitable. The problem with this is that when there are a lot of open positions, like right now, you always have to ask yourself, “Should I close my position now?”   Should I stop or is the loss too big? In this example, we only have a $10,000 account, and the equity is now worth less than $9,900. This might get a lot more in-depth with a longer drawdown. And the longer a situation like this goes on, the less sure we traders are and the more we ask ourselves, “What should I do now?” Should I accept that I’ve lost, or should I hope that things will get better? I’ve been asked this question twice in the last week, so I’d like to share what I think about it. And that’s just to try things out until you’re sure how you want to act in a certain situation. In a soccer game, there are boundaries, referees, and goals. Most soccer games are 90 minutes long.   At the end of the period, the winner is the team that has scored the most valid goals. Such rules are just what you need to be able to tell if a result looks good or bad and if you want to keep going or not. After all, soccer players almost never leave the field after giving up three goals because, after all, the game is no longer worth playing. So, if you feel like your trading results aren’t what you expected, it’s usually because of a few simple things.   The first problem is that you haven’t set any rules. That means you show up to a soccer game with a tennis racket and field hockey gear.   Probably your account is too big, which is the second problem. If you start to worry that your account won’t make it through the next night and can’t sleep because of it, your account size is probably too big to let you sleep well in the future.   The third problem is that you depend on making money. And if you already know exactly what should happen next, it’s almost certain that the opposite will happen.   But there is also a solution for each of these problems. And sometimes the answer seems to be just to wait long enough. Since then, our system has already reached February, but not much has changed. This can look a lot worse in real life and make you feel a lot worse than it does in this strategy test. And that’s exactly why it’s important to do a lot of these strategy tests ahead of time so you know how to act when the time comes. Because this is where I am with my Platinum System right now. The direction of the Euro Dollar has changed.   We have a small drawdown, and now you have to ask yourself, “Do I still want to trade this system next week, next month, and next year?” For me, the only way to give a good answer is to do enough testing and set clear rules before I get into the situation. Because only then can I act in the situation according to my rules. Okay, I guess that’s all for today. Thanks for watching, and we’ll see you in the next video.
    4 min
  • MQL5 TUTORIAL – SIMPLE SIGNAL STACKING
    In this video I wanted to talk about something that I call: “Signal Stacking”; you see 4 lines here, each is a Moving Average for a different period. As long as all the 4 lines are going downwards without a crossover that would be a pretty stable sell trend and you could stay in your short position and be very sure that you don’t lose any money, in fact we would have made some money here, probably a descent amount. The only thing you need to wait for is: you need to wait for a crossover for one or more of these lines to get out. Let’s speed that up a little bit and here is the crossover, now you would get out and when you see a complete crossover for each of the lines like in this case that would create a reverse trend, this is a very good example and now you would open a long position and trade it until the next crossover takes place. Now we want to find out how we can create an Expert Advisor that is able to produce these 4 lines and create buy or sell signals for stable trends. 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 one: “SimpleSignalStacking”, click on “Continue”, “Continue” and “Finish” and now you can delete everything above the “OnTick” function and the two comment lines. We want to start by creating an empty string for the signal that will be also called: “signal” and we don’t assign a value here. Let’s create an array for several prices; in fact we are going to create four. We will call them my Moving Average array 1 (myMovingAverageArray1), my Moving Average array 2 (myMovingAverageArray2), my Moving Average array 3 (myMovingAverageArray3) and my Moving Average array 4 (myMovingAverageArray4). For each of the arrays we use the “iMA” function for the current symbol and the current period to create an Exponential Moving Average by using “MODE_EMA” that will be calculated on the close price and it will be calculated based on the current candle. The first Moving Average will be for the last 50 candles, the second one for the last 100 candles, the third one is for the last 150 candles and the last one calculates the last 200 candles. By using “ArraySetAsSeries” we are going to sort each of our arrays from the current candle downwards; this is array 3 and this is array 4, I simply used “copy and paste” that saves some typing work. Now we fill each of our arrays by using “CopyBuffer”. According to the Moving Average definition (movingAverageDefinition) that we have created here each of our EMA’s has only 1 buffer, that’s buffer 0 and we want to fill our array from the current candle 0 for 3 candles and store the result in our Moving Average arrays (myMovingAverageArray) and now we can calculate our Moving Average values (myMovingAverageValue) by looking into candle 0 of our Moving Average arrays (myMovingAverageArray). These are the values and when you place your mouse over each of the lines at the end of the line you will see the current value for candle 0 and to calculate the sell signal we would check if “myMovingAverageValue1” is below “myMovingAverageValue2” and if “myMovingAverageValue2” is below “myMovingAverageValue3” and if “myMovingAverageValue3” is below “myMovingAverageValue4”. So, these 3 “if” statements stack our entry signals and only if all are true we would create a sell signal. For the buy signal it’s almost exactly the same but in this case we are checking if the value for each of our Moving Averages is greater than the one on the right side. If this is the case we create a buy signal. In the last step we use the ”Comment” function to output our signal on the screen followed by each of the values that we have calculated. Okay. When you are done please click on the “Compile” button here, that should work without any errors and without any warnings and if this is the case please click on the little button here ...
    7 min