MQL5 Tutorial

MQL5 Tutorial

By Raimund BauerBusinessTechnologyInvesting
Download on the App Store

All MQL5 Tutorial episodes

  • MQL5 TUTORIAL BASICS – 93 SIMPLE HIGH GANN FAN
    In this video we are going to create such an object here, the so-called Gann Fan, and we want to find out how to do that with MQL5. To get started, please click on the little icon here, or press F4 on your keyboard. Now you should see the MetaEditor window, and here you want to click on file, new file, expert advisor from template, continue. I will call this file SimpleHighGannFan, click on continue, continue, and finish. Now you can delete everything above the OnTick function and let’s remove the two comment lines here. We are going to calculate the number of candles on the chart, and that can be done by using ChartGetInteger. The first parameter is for the chart ID zero, the second one is called chart first visible bar, and if you mark that and press F1 you will see that it returns the number of the first visible bar on the chart, the last parameters for the sub window. The one with the candles is windows zero. Now let’s create a variable for the highest candle, and I would also like to create an array for the highest prices, it is called High and it will contain all the highest prices for each candle on the chart. First, we need to use ArraySetAsSeries to sort the high array from the current candle downwards. And now we can use a function called CopyHigh, this one will give us the highest bar prices for the current symbol on the chart and the currently selected period on that chart. We want to start with the current candle zero for all the candles on the chart and copy the values into our high array. And now we can get the highest candle by using this function ArrayMaximum that will give us the largest element in our array. The array is called High, we want to start to search for the highest candle with candle zero and go through all the candles on the chart, and the result is the number of the highest candle. We also need to use MQLRates for another array called price information, because MQLRates also stores the time, and for each object we need to know the time and the value to draw it. Let’s also sort this one with ArraSetAsSeries from the current candle downwards, and now we can fill the array with data by using CopyRates for the current symbol on the chart and the currently selected period on that chart, starting from the current candle zero for all the candles on the chart we want to store the price information in our array. Before we can create a new object we want to use ObjectDelete for the current symbol on the chart and the object that is called SimpleHighGannFan, we use ObjectDelete to remove old objects before we draw a new one. This will not be the case, the very first time we call this function, but afterwards we always have an old object that needs to be removed and to draw an object we use ObjectCreate. The first parameter, zero, is for the chart ID, the second parameter is the object name. In my case it’s SimpleHighGannFan. Basically you can use any name you want, but you need to use the exact same name everywhere. Parameter three is the object type, we have used OBJ_GannFan, and if you mark that and press F1 you will see that there are different object types. We use this one, it will draw these lines on our candle chart, we want to draw it inside of the main chart with the candles, so that’s the window zero. My starting point is the time when the highest candle inside of our price information array was drawn, and I would like to have it for the highest price of the highest candle. The second point in time will be the current time when the current candle zero is drawn, and the value will be the highest price of the current candle, and that’s it for the ObjectCreate part. Of course, you can use other values here, but for this simple example it’s good enough. Now let’s change a few properties that can be done by using ObjectsetInteger for chart ID zero, I would like to change a property for the object that is called SimpleHighGannFan, the property I want to change is object property color,
    7 min
  • MQL5 TUTORIAL BASICS – 92 SIMPLE DEVIATION CHANNEL OBJECT
    In this video, we are going to create a channel object for a so-called deviation channel. Let’s find out how to do that with MQL5. To get started, please click on the little icon here, or press F4 on your keyboard. Now you should see the MetaEditor window, and here you want to click on File, New File, Expert Advisor from Template, Continue. I will call this file SimpleDevChannel. Click on Continue, Continue and Finish. Now you can delete everything above the OnTick function, and let’s also remove the two comment lines here. First, we want to calculate the number of candles on the chart. That can be done by using ChartGetInteger. For the chart id zero. We use CHART_FIRST_VISIBLE_BAR. The last parameter here is for the sub window. In our case, that is sub window zero. That’s the window with the candles. If you like oscillators, you know that those are drawn in a separate window below the candles. But, we don’t want to do that, so we use zero here. Now let’s create a variable for the lowest candle, and we also need to create an array for the low prices for each candle. I will call this one low, and as you might have guessed, we also want to create a variable for the highest candle and the array for the highest prices called high. Now we use ArraySetAsSeries for both arrays to sort them from the current candle downwards. Now let’s fill the low array by using CopyLow for the current symbol on the chart and the currently selected period on that chart. We will start with candle zero for all the candles on the chart and copy the lowest prices into the low array. Of course, we need to repeat that for the highest prices. Therefore, we use CopyHigh. That will give us all the highest bar prices for the current symbol on the chart and the currently selected period, starting from candle zero for all the candles on the chart and the values will be stored in the high array. To get the lowest candle on the chart, we use ArrayMinimum. That will give us the lowest element in the array, and we are looking for it in the low array, starting from candle zero for all the candles on the chart, and store the lowest candle number in this variable. That’s the number of the candle, not the value. You might have expected that we also need to do that for the highest candle. This time we use ArrayMaximum, and we want to search inside of the high array, starting from candle zero for all the candles on the chart and store the result in the variable highest candle. Let’s continue and use MqlRates to get all the price information that we need. It will create an array called price information, and we use ArraySetAsSeries to also sort this one from the current candle downwards. Afterwards, we use CopyRates for the current symbol on the chart and the currently selected period, starting from candle zero, that’s the current candle, for all the candles on the chart and store the result in our price information array. Let’s use ObjectDelete to delete any former objects for the current symbol on the chart. It will delete objects called simple channel object, and we will not have such an object on the very first time we code the function. But afterwards, we want to make sure that we delete the old channel before we draw a new one. That is done by using ObjectCreate. Let’s go through all the parameters we need. The first one, _Symbol, is for the current currency pair. The second one is the name of the object. I have called it Simple Channel Object. The third parameter is the type of the object. In this case, we are using OBG_STANDARD DEVIATION CHANNEL. If you mark that and press F1, you will see that it is just one of the possible object types. It will draw a standard deviation channel object, right on the chart. In the next parameter, we need to define that we want to have the object on the candle chart. That’s window number zero. I would like the object to be drawn for all the candles on the chart. I have to subtract one candle here because this is always a point i...
    9 min
  • MQL5 TUTORIAL BASICS – 91 SIMPLE CHANNEL OBJECT
    In this video, we are going to create a channel object for the highest and the lowest candle on the chart, so let’s find out how to do that with mql5.   To get started please click on the little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple channel object, click on continue, continue and finish. Now you can remove everything above the ontick function and let’s also remove the two comment lines here. We want to start by calculating the candles on the chart that is done by using chart get integer for the chart id zero and we use chart first visible bar, the last parameter here is for the sub-window, the one with the candles is window zero, if you would like to insert oscillators like the MACD you would see that those are drawn in a separate window below but we want our channel object to be drawn in the main window. Let’s create a variable for the lowest candle and we also need an array that is called low and it will hold the lowest candle prices for all the candles on the chart. We repeat that and create a variable for the highest candle and an array for the highest candle prices on the chart. And now we use array set as series for both arrays to sort them from the current candle downwards, so we can fill them with data that is done by using copy low, if you mark that and press F1 you will see that we will get the historical data and the minimal prices for each candle for the current symbol on the chart and the currently selected period on that chart starting from the current candle zero for all the candles on the chart and the results will be stored in the low array that is for the lowest prices. And as you might have guessed there is another function called copy high that will give us the highest bar prices for the history data for the current symbol on the chart and the currently selected period starting from candle zero for all the candles on the chart. And that’s how we store those price values into our high array but now we want to find the extreme prices. For the lowest candle that can be done by using the function array minimum that will search for the lowest value in the whole array, in our case in the array called low starting from candle zero for all the candles on the chart and the price for the lowest candle will be stored in this variable. For the highest candle we use array maximum that will give us the largest element or the highest price in our array and this is the high array starting from candle zero for all the candles on the chart so now we have the number for the lowest and for the highest candle but we need more data, so we use mql rates to create a price information array, if you mark mql rates and press F1 you will see that it stores information about prices, volumes and spread and also the time and that’s what we need, so let’s use array set as series to sort the price information array from the current candle downwards and with copy rates we fill the array for the current symbol on the chart and the currently selected period on that chart starting from candle zero for all the candles on the chart and store the values in our price information array. Before we can draw the object we want to use object delete for the current symbol on the chart to delete any formal objects called simple channel object. We will not have such an object the very first time we call the code but afterwards, we want to make sure that we remove the old values before we draw a new object and to draw that object we use object create, if you mark that and press F1 you will learn that it can take up to thirty coordinates, we need to pass a few parameters, so let’s go through the values one by one. The first parameter is for the current symbol on the chart, the second one is for the name of the object, I have called it simple channel object,
    10 min
  • MQL5 TUTORIAL BASICS – 90 SIMPLE LOW PRICE TREND LINE
    In this video we are going to create a line object that is drawn from the lowest low of the lowest candle on the chart to the current low, so let’s find out how to do that with mql5. To get started please click on a little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file, simple low price line, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. First, we want to get the numbers of candles on the chart and that can be done by using chart get integer. We want to do that for the current chart id zero and we want to get chart underscore first underscore visible underscore bar. The last parameter is for the sub-window, zero is the sub-window with the candles and now that we have the number of candles on the chart let’s find out what is the lowest candle so we create a variable called lowest candle and we also need to create an array called low that will hold the lowest candle prices for all the candles. Now let’s use array set as series for the array to sort the current array from the current candle downwards. To fill the array with data we can use copy low that will give us the minimal bar prices for the current symbol on the chart and the currently selected period on that chart, starting from the current candle zero for all the candles on the chart and it will store the values in the low array. And now we can calculate the number for the lowest candle by using array minimum that will search for the lowest element in the array, in this case, it will search in our array low starting from candle zero for all the candles on the chart and give us the lowest candle number. We continue by using mql rates to get the price information on the chart. Once again we use array set as series to sort this array from the current candle downwards and now we use copy rates for the current symbol on the chart and the currently selected period on that chart to copy the price information for all the candles from the current candle zero and for all the candles on the chart into our price information array, so now we have the price data and we have the number of the lowest candle. And in the next step, we use object delete for the current symbol on the chart and we want to delete all the objects that have this name, simple low line trend that will not exist the first time we run the code but afterwards we want to remove the old values each time and draw a new line. And that is done by using object create for the current symbol on the chart, the second parameter is the name of the object, we have called it simple low line trend. Parameter three is for the type of the object, we use obj underscore trend, there are lots of other object types that we could choose but for this object type, we need to tell Metatrader to draw it in the main window that is window zero. This is the time for the lowest candle on the chart because this is the time line. The next parameter is for the price level of the lowest candle because this is the price value line and here is the starting point. And the next two parameters will tell Metatrader to draw the line for the current candle zero and especially for the lowest price of that candle, so now we have two points that define how the line will be drawn but we want to add a few changes to the line properties that can be done by using object set integer for the chart id zero and the object that is called simple low line trend, we want to change the object property color, in my case, I would like to have a red color. Now let’s repeat that this time for object property style, I’m using a solid style here, we could also decide to use a dotted line, in this case, you would use style underscore dot, here comes another one, this time we are going to change the object property width, I use a value for a thin line.
    8 min
  • MQL5 TUTORIAL BASICS – 89 SIMPLE HIGH PRICE TREND LINE
    In this video we are going to create an expert advisor that is able to draw a line object from the highest price on the chart to the current high of the current candle to get the current price trend, so let’s find out how to do that with mql5. To get started please click on this little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file, simple high price line, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. As we only want to draw a line for the highest candle on the chart we just need to get the number of candles that are visible. And to do that we use chart get integer for the current main chart and the property we need to get is called chart first visible bar – all in capital letters –, the last parameter here is for the sub-window, window zero means we use the window with the candles. If you like oscillators like the MACD you will see another window below the main window that would be window one but in our case, we will draw the line in the main chart where the candles are.  Now let’s create a variable for the highest candle, we also want to create an array that is called high to hold all the high prices for each candle on the chart. Let’s use array set as series to sort the array downwards from the current candle and now we can use a function that is called copy high, it contains the data of highest bar prices and we need to use a few parameters. The first one is for the current symbol or the current currency pair on the chart, the second one is for the period that we are using on that chart, these two values are able to automatically detect that. This is the starting index that’s candle zero or the current candle and we want to check all the candles on the chart that we have calculated here and store the values for the highest prices in our high array. And that makes it possible to get the highest candle by using array maximum. Array maximum searches for the largest element in our array that is the array that we called high, it starts to search from the current candle zero and it will go through the values for all the candles on the chart and store the highest value in this variable called highest candle. Now let’s use mql rates to get the price information for all the candles on the chart, not only the highest prices but all the prices. Mql rates stores information about prices, volumes and spread. We call the array price information, let’s also use array set as series to sort this one from the current candle downwards and now we want to use copy rates to copy the price data for the current symbol on the chart and the currently selected period starting from candle zero for all the candles on the chart and store the results in the price information array. And before we create an object we use object delete because if we already have drawn lines on the chart we are going to delete all the lines that are called simple high line trend for the current symbol on the chart, that will remove the old lines. And now we can use object create to create a new one that will require a few parameters, so let’s go through the values one by one. The first parameter is for the current symbol on the chart, the second parameter is for the object name, in this case, it’s called simple high line trend, you could use any name but you need to use the same name everywhere, parameter three is called obj trend and when you mark that and press F1 you will see that this will draw a trend line, we could create lots of other object types, here is a list. Parameter number four is for the window where we want to create the object, as I said I would like to have the line in the main window and it should start at the highest candle in our price information array and this is a point in time because we all know this is a time based and th...
    10 min
  • MQL5 TUTORIAL BASICS – 88 SIMPLE ALLIGATOR INDICATOR
    In this video, we are going to calculate the values for the alligator jaw, the alligator teeth and the alligator lips. This is an indicator that was created by Bill Williams, so let’s find out how to do that with mql5. To get started please click on a little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple alligator, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. To calculate the alligator we need to have three different arrays, one is for the so-called jaw, one is for the teeth and one is for the lips. To be honest I’m not a big fan of the alligator indicator but this was a suggestion from one of the premium course members and if you are already a premium course member and have an idea for a video like this one please let me know but let’s continue! We now need to define the alligator expert advisor, I do it in a different way because I would like to actually check the current values. The original version is using shift values but I would like to check if the calculation for the current value is correct, so let’s get started. And to do that we use the included function called ialligator, if you mark that and press F1 you will see that it needs a lot of parameters. The first parameter is for the current symbol on the chart, in our case, it’s a currency pair, the second parameter is for the period on that chart, for example, a one-minute chart or thirty-minute chart. Underscore period is going to calculate the current one, the next parameter is a so-called jaw period if you right-click on the indicator and click properties of alligator you will see the jaws period is thirteen candles, teeth period is eight candles and the lips period is five candles. In the original version they also use shift values but I have set those to zero to make it easier to check the current values here, so we use zero for the jaw shift value, the teeth period is eight, the shift value for the teeth also is zero, the lips period is five, the shift value for the lips is also zero, the mode in my case is mode underscore sma, you could also use ema for exponential moving average or smma that’s the original one that they use for the original alligator. I would like to calculate the values based on the close price, here you can use whatever you want, the original alligator is using the median price and that’s it for the alligator definition. Now we need to calculate the jaw, the teeth, and the lips. We start by using array set as series for the jaw array to sort it from the current candle downwards and as you might have guessed we repeat that for the teeth array and for the lips array and now we use copy buffer to fill the jaw array according to the alligator definition that we have created here. For the jaw, we are using buffer zero and we want to copy the values from the current candle zero for three candles and store them in the jaw array. For the teeth array it’s basically the same but this time we are going to use buffer one because in the reference we learn that buffer zero is the jaw, buffer one is the teeth and buffer two is the lips value. So let’s repeat that! And this time we are using buffer two for the lips array and now we can calculate our values by simply looking into candle zero of the jaw array, I use normalize double and five to create an output with five digits behind the dot because this is what we see when we point the mouse on one of the three indicator lines. We repeat it and do it for the alligator teeth value, everything is similar except for the fact that we are now looking at candle zero in the teeth array and as you might have guessed it’s the same for the lips array. Finally, we want to add a comment statement to output the values, we are not going to actually trade this indicator but we want to see t...
    9 min
  • MQL5 TUTORIAL BASICS – 87 SIMPLE SELL BUTTON OBJECT
    In this video we are going to create another object, this is a sell button and when I click the sell button I see that we have a new sell position here, so let’s find out how to code that with mql5. To do that please click on a little button here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple sell button, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. We start with an include statement to include the file trade dot mqh, this one is part of mql5 and it will provide some simplified trading functions. Afterwards, we are going to create an instance of the class ctrade this one is called trade and we also want to declare two global variables for the ask price and the bid price. Inside of the ontick function we start with calculations for the ask price and the bid price that can be done by using symbol info double for the current symbol on the chart, we use symbol underscore ask or symbol underscore bid and with normalize double and underscore digits we make sure to automatically calculate the right number of digits behind the dot. Now let’s continue and create the button object that is done by using object create, if you mark that and press F1 you will see that it will create one of these objects. There are a lot of different object types and depending on the type of the object you need to do different things, we are going to create the object button here that can be placed on the chart. The first parameter is the current symbol or the currency pair on the chart, the second parameter is for the name of the object, we will call it sell button, parameter three is for the object type and this is obj underscore button, this parameter is for the window, we will create the object in the main window – that’s where the candles are – if you use oscillators you could also create objects in the window below the candles but we are not going to do that and the last two parameters are for a time and a price. Depending on the object you want to create you might want to move it to a certain date-time or a certain price point. For example, we have used that to move a line to the highest and to the lowest candle on the chart but we don’t use these values for the button because the button will stay where it is, so that’s how you create the object but so far it will not do anything and we want to change a few properties. The first one is for the distance from the border, we use object set integer for the current symbol on the chart for the object called sell button and we want to modify the property object property x distance and set it to two hundred pixels. Let’s also set the width of the button! Once again object set integer for the current symbol on the chart, the object name is sell button and now the property is object property x size, let’s also set this one to two hundred. Let’s continue and set the property y distance! This time we are going to use two hundred fifty pixels. I have messed up the comments here, so let’s change that. And we use object set integer for the next property object property y size that is the height of the button, we will set it to fifty pixels, the next property is the corner, I have used corner two, you can pick one of the four corners on the chart and we change that by modifying the property object property underscore corner in my case I use corner two. And finally, let’s set the text on the button that is done by modifying object property underscore text and let’s set that to sell, and that’s it for the button creation and the button properties but we need still to implement the event handling. Mql5 comes with a function that is called on chart event, it has four parameters, the first one is for the object id and the other parameters will pass some values, in our case,
    10 min
  • MQL5 TUTORIAL BASICS – 86 SIMPLE BUY BUTTON OBJECT
    In this video we are going to create a buy button, this is a chart object and when we click on the button we can see that we have a new open position, so let’s find out how to do that with mql5. To get started please click on a little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file, simple buy button, click on continue, continue and finish. Now you can delete everything above the ontick function and let’s remove the two comment lines here. We start with an include statement to include the file trade dot mqh, it contains the class ctrade and we are going to create an instance that is called trade, afterwards, we create two variables for the ask price and the bid price because the event handling for the button will be implemented in a separate function. Inside of the ontick function, we start by calculating the ask price and the bid price that is done by using symbol info double for the current symbol on the chart, we use either symbol underscore ask or symbol underscore bid and with normalize double and underscore digits we make sure to automatically calculate the right number of digits behind the dot. Now we want to create a chart object that is done by using object create for the current symbol on the chart, the object name will be buy button, the object type is obj underscore button and if you mark that and press F1 you will see that there are lots of object types that we can draw on the chart. This is the one that we are going to use, you can place a button in front of any chart. Inside of the documentation, you will find lots of examples for dozens of properties and events but we are going to make it very simple. The next parameter is the window, we want the button to appear in the main window where the candles are and the last two parameters here for date time and price point are not required, so we set those values to zero. Let’s define a few properties, we use object set integer for the current symbol on the chart and the object with the name buy button, the property we want to change is the x distance from the border, let’s set the distance to two hundred pixels, I would like to set another property, everything is equal except for the parameter here that’s object property x size and that will change the width of our button. We also want to set the distance from the upper or from the lower border that is done by using object property underscore y distance. Now let’s set the height of the button to fifty pixels and this time it’s obj prop underscore y size, we can pick one of four borders for our object that is done by using obj prop underscore corner so if you change this number your object will appear in a different corner and finally, I would like to change the text on the button – that’s what we do when we use obj prop underscore text – and I would like to have the text buy and that’s it for the button. You could compile the code now but the button wouldn’t do anything so what’s missing is the event handling and we are going to create that now. So let’s create a separate function here, this function is called on chart event, we have four parameters here, the first one is for the chart id and these three parameters here are used to pass some values. Inside of the function, we first want to check if the first parameter here, id, equals chart event object click, so that would be a mouse click on an object. And in the next step we want to check the value for the sparam that is a string value and we will call that clicked object name and now we can check if the sparam equals buy button – that’s the name of the button – and if that is true we want to create a comment statement and output the sparam value to show which button was pressed, in our case we only have one button and if it is the buy button we use trade dot buy to buy ten micro lot.
    9 min
  • MQL5 TUTORIAL – THE ONE THING YOU NEED FOR PROFITS
    Hello in this video, I would like to do a live recording. I would like to talk about something that seems to be a common question from time to time. People ask me the same question again and again, and I would like to use this kind of live recording videos to answer those questions in the future. So the question today is, is it possible to recognize the entry X or Y with MQL four or MQL five? So basically it’s about, can I automate what I see on the screen? Yes. Most of the time this is possible. It is not very hard to do that, but you need to define it in numbers. So if you see something with your eyes, You need a way to translate that into numbers. That can be calculated. So let me explain what I mean. You probably have some kind of trend and you as a human, have no problem to identify it, but to automate it, you need to define what needs to happen and when it needs to happen. So for example, for a trend, you would need to define when the trend will start and when it will end, something like I see it on the chart will not work for an automated trading system. Here is how it would work. You would need to define borders and rules. Something like a crossover of two moving averages is a good idea, because it can be calculated and Metatrader would be able to define if the ball is inside or outside of the playing field. So without clear rules, you cannot automate anything, that would be like playing soccer, using tennis rackets and the basketball. This is not the kind of game you want to play. You can do whatever you want, but you cannot do everything. You’ll need to pick something and stick to it. And that will make your system profitable. Thank you for watching.
    3 min
  • MQL5 TUTORIAL BASICS – 85 SIMPLE TAKE PROFIT POINT TEST
    In this video, we want to test how to find the optimal value for the take profit points, so let’s find out how to do that with mql5. To get started please click on a little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file, simple profit point test, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. First, we want to include the file trade dot mqh, it contains the class ctrade and we are going to create an instance called trade. I also would like to create a user-defined variable for the profit value. Inside of the ontick function, we start by calculating the ask price and the bid price that is done by using symbol info double for the currently selected symbol on the chart, we use either symbol ask or symbol underscore bid and with normalize double and underscore digits we automatically calculate the right number of digits behind the dot. Now let’s use mql rates to get some price information because mql rates stores the information about prices, volumes and spread. Afterwards, we use array set as series for our price info array to sort the array from the current candle downwards and with copy rates we are going to fill our array for the current symbol on the chart and the currently selected period but I would like to use it with an underscore, basically, it’s the same. This one and this one are exchangeable and with copy rates, we can fill our price info array for the current symbol on the chart and the currently selected period on that chart. We start with candle zero and we copy the values for three candles and store them in the price info array. Let’s create another array, called sma fifty array because we are going to use a simple moving average. Here comes the definition. I would like to use the integrated ima function for the current symbol on the chart and the currently selected period on that chart. I would like to calculate the value for fifty candles, don’t use a shift value here, this parameter is called mode underscore sma that stands for simple moving average and I would like to have the values calculated based on the close price. Now let’s use array set as series to sort this one from the current candle downwards and now we can use copy buffer according to the sma fifty definition that we have created here to copy values for buffer zero, from the current candle zero for ten candles and store the values in the sma fifty array. And to get the current sma value we just need to have a look into candle zero of our sma fifty array and now that we have the current value for the simple moving average we check if the simple moving average value is above the ask price, in that case, we want to buy, so we assign the word buy to our signal. Otherwise, if the current sma value is below the bid price that’s when we want to sell and then we assign the word sell to our signal and if we have a sell signal and positions total is below one that would mean we don’t have any open positions but we want to sell, so now we use trade dot sell to sell ten micro lot. And here is our user profit point value that we have defined, the basic value is three hundred but as it is an input value you can change that later on while the expert advisor running without any new compilation process. Now let’s repeat that for the buy signal. If the signal equals buy and we have no open positions we use trade dot buy and but ten micro lot and this time we take the current ask price and add the user profit point value multiplied by the point value and that value depends on the current symbol you have on the chart. Finally, we want to use the comment statement to output the current signal on the chart followed by the user profit point value that we are going to test and that’s about it. Well, if this was too fast for you or if you have no idea...
    9 min