MQL4TUTORIAL.COM

MQL4TUTORIAL.COM

By MQL4TUTORIAL.COMBusinessInvesting
Download on the App Store

MQL4TUTORIAL.COM episodes

  • LEARN MQL4 TUTORIAL BASICS – LEVEL 1C BUILD YOUR OWN ALGO TRADING SYSTEM FARM
    Our new documentation series on setting up your own Algo Trading System Farm is now available for viewing. We use automated voices and technology to assist you in improving your outcomes more quickly and with less work than ever before. MX Linux is covered in detail in this section, which will cover the basics of the installation. First and foremost, you must learn how to modify the starting settings on your computer in order for the installation to be successful later in the process. This varies based on the kind of computer, but in most cases, hitting a certain key, such as Escape or F1, will allow you to access the setup menu. There is an option to start the computer from a USB stick that may be configured. But first and foremost, we must make this USB stick.   There are a variety of applications available for this, and the functionality varies based on the operating system. The vast majority of people who watch these videos will most likely be using the Windows operating system, and there is a very simple and straightforward method of creating a USB stick from our obtained ISO file. We said in the last section that we wanted to obtain the 64-bit version of Fluxbox. However, a 32-bit version of MX Linux is available for download on the company’s website. As a result, even computers that are 15 years old may be utilized with the newest software. We will take a device from the year 2010 as an example. As a matter of fact, I have a few netbooks that are only compatible with 32-bit operating systems. They are able to run MX Linux smoothly even when just one GB of RAM is available. These devices, on the other hand, are not particularly well suited for use in the construction of an algo trading server farm.   Instead, we make use of a Tecra A11 laptop that was manufactured in 2010. However, while this device is no longer a high-performance computer, the RAM may be increased to 8GB. Previously, this would have been prohibitively costly, but in the meanwhile, technology has advanced to the point that RAM for such old systems is now quite affordable. Now, in order to build our bootable USB stick, we’ll need to download and run the proper application. Consequently, we begin by downloading the portable version of the program Rufus for our Windows-based computer. Rufus is a piece of software that may be used to generate a bootable memory stick in a matter of minutes, even if it has not been installed on your Windows computer. The portable version may be launched with a single mouse click when the download has been completed, and from here we will be able to obtain the appropriate ISO image of the version we downloaded for MX Linux. We’ll also need a USB stick that’s capable of serving as a bootable storage media for our software.   The majority of modern USB sticks should be able to do this without any issues. We have a 32 gigabyte USB stick here, but if you have an old USB stick laying around with 8 GB or more, that would do. Be cautious to double-check that you have chosen the right configuration for the destination disk before attempting to copy the ISO file to the USB stick. Should there be any uncertainty, please unplug any external USB devices, such as hard drives or SD cards in the case of laptop computers. This will assist in avoiding any misunderstandings. After you have completed all of the necessary adjustments, click on the relevant button to begin the process of creating the USB stick. This should take no more than five to ten minutes to complete. Following the successful completion of this step, we will enter our freshly manufactured USB stick into our target machine in order for MX Linux to begin functioning properly. Don’t be concerned, nothing will be installed till later. MX Linux will initially run in test mode on the target computer prior to beginning the installation procedure on that machine. This provides you with the chance to test everything before overwriting your previous operating system with the new one....
    5 min
  • LEARN MQL4 TUTORIAL BASICS – LEVEL 1B BUILD YOUR OWN ALGO TRADING SYSTEM FARM
    Our new documentation series on setting up your own Algo Trading System Farm is now available for viewing.   We leverage automated voices and technology to assist you in improving your outcomes more quickly and with less work than ever before.   Let’s get this project started!   As of today, we will begin putting up our infrastructure, with the goal of having a fully functional automated trading system farm by the completion of this course.   It will take some time until then since I will not be able to offer knowledge on this issue on a daily basis until then.   There are a variety of factors contributing to this.   The first reason is the present pretty difficult political environment in my neighborhood, which is the first of two reasons.   The second difficulty is that we are dealing with certain health difficulties at the moment.   For example, we are now dealing with a scenario in which my father has had a stroke and hemiplegia and has been placed in an institution.   The third issue is one that has to do with economics.   In order for the bottom line to cover net demands and expenses, we must, as an economically focused organization, complete certain tasks in a certain sequence.   In simpler terms, this indicates that the project will be finished incrementally, but we are unable to predict how quickly or slowly the improvement will go at this time because of the identified factors and situations.   The vast majority of viewers will most likely already have an operating system that they want to keep using.   In our situation, however, we will be utilizing a netbook that is ten years old and installing the software that we now believe to be the ideal alternative for individuals who have not yet decided on an operating system as their only choice for computing.   MX Linux is a Linux distribution based on Debian that is used to run this software.   Within the past few months, MX Linux has risen to the top of the list of the most popular Linux distributions, surpassing Red Hat Enterprise Linux.   Because, to put it simply, this software allows you to do numerous tasks that would otherwise be impossible to accomplish with other Linux distributions, which is a significant advantage.   Numerous features are operational immediately after the first installation, and the hardware is recognized really well, even if the devices are more than ten years old.   Furthermore, MX Linux is capable of running a highly contemporary and up-to-date version of Linux on a small number of resources, without the need to deal with any command line commands throughout the day.   In simpler words, this implies that anybody who wants to use MX Linux will be able to take benefit of the best of both worlds while still being able to utilize a high-performance and simple-to-use operating system without having to pay licensing costs.   We have experimented with various different Linux variants for our own firm over the past several years, and the majority of the time you reach a point where you are unable to continue.   In this scenario, it is pretty simple to put into action, and you do not need any specialized understanding.   Furthermore, there are so many useful articles available on the internet for MX Linux that even complete novices should be able to manage it better than they would with Windows.   The interface and look may be totally customized to meet your specific needs, so that even if you are using a MacBook, you will get the impression that you are using a cutting-edge Apple system.   However, for us, this isn’t really significant.   We value support for hardware that has been released within the previous 10 years considerably more than anything else, and this includes the now 12-year-old netbook that we use for this purpose.   You should be able to follow along with each and every step with ease.   This documentation series may seem to be a little lengthy for some persons who are already acquainted with the Linux operating system.
    5 min
  • LEARN MQL4 TUTORIAL BASICS – LEVEL 1A BUILD YOUR OWN ALGO TRADING SYSTEM FARM
    Welcome to the first part of our new series on how to set up your own Algo Trading System farm. We combine voice and automated technologies to assist you in improving your outcomes more quickly and with less effort than ever before. A new project has been on my mind for some time, and over the last few weeks, I’ve been asked on a number of occasions whether anything new from me on the topic of Algo Trading would be published, and if so, what shape it will take and under what conditions it will be provided.   I actually worked on another automated customer acquisition project for many months, and that project came to a conclusion just last week. So I sat down and thought about what I wanted to accomplish next, and I came up with the idea of using the Algo Trading System Farm concept as a starting point. Each day, with just a few minutes of work, the authors of this paper want to construct infrastructure. Through the use of this solution, you will be able to operate several Algorithmic Metatrader trading systems on any operating system, allowing you to trade independently around the clock on up to 22 completely automated charts at the same time. It makes no difference if you wish to do the task on a Windows PC, a Linux machine, or a MacBook.   And it makes no difference if you like to trade using MetaTrader 4 or MetaTrader 5. All of these solutions are likely to work on your machine as well, assuming that they are applicable. We will choose a variation that uses extremely little resources and can be run on a netbook that is more than ten years old. This implies that you can now go underground and resurrect your old PC from ten years ago, which you can then use to run your own automated trading system using Metatrader.   We’ll do it step by step and make use of the opportunities provided by today’s cutting-edge technological advances. This includes my use of the technology described in this section for this material, which enable me to dub movies generated in several languages in a totally automated way. When it comes to MQL4 channels in English, I will utilize my own voice, but when it comes to other languages and MQL4 channels, I will rely on automatic solutions.   That’s all there is to it for today. You may reach out to me through email if you have any concerns or recommendations concerning the content of this video. I personally reply to every email, and I aim to answer within 24 hours in most cases. Subscribe to our YouTube channel if you simply want to boost your trading outcomes with the use of automated trading. If you want results that are quicker and more consistent, check out our premium course on our website. Now I’d want to express my gratitude for your attention, so I’ll see you in the next video!
    3 min
  • MQL4 TUTORIAL – SIMPLE MOUSE CLICK EXPERT ADVISOR
    This time we are going to talk about chart events; a chart event will happen when you interact with your chart. For example in this simple Expert Advisor that is called: Simple Mouse Click . You can click anywhere in the chart and you will see the text: ”You pressed the mouse at the following coordinates:” and the x and y coordinates here. That will happen whenever you click on the chart. For example if you click on the left border here you will see that the x value is very low and the y value is high and if you click on the upper border here it’s the other way around; now the x value is high and y value is low. You will get the highest values here in the lower right corner and now we want to find out how we can create an Expert Advisor that is able to take the mouse coordinates and create the output on the chart. To do that please click on the little button here or press F4 in your Metatrader and now you should see the Metaeditor window here and here you want to click on “File/ New/ Expert Advisor (template)” from template, “Continue” – I will call this one: “SimpleMouseClick”, click on “Continue”, “Continue” and “Finish”. Let’s remove everything that is above the “OnTick” function and the two command lines here. Usually the “OnTick” function would be triggered whenever the price changes on your chart, but in our case we want to look for mouse clicks, so let’s change “OnTick” to “OnChartEvent”. Let’s mark that expression here and press F1 and you will see that the “OnChartEvent” is the handler of a group of chart event elements. For example if you press a key, move your mouse, create an object or change an object and whenever something like this happens it will create an event. In our case the event will be “CHARTEVENT_CLICK” this is the event handling function and it will take a few parameters here; the first parameter is the “ID”, that’s the event ID – in our case that will be “CHARTEVENT_CLICK” –, the second parameter is of the long type, so it’s called: “lparam” for long parameter, the third parameter is a double parameter, so it’s called: “dparam”, and the last parameter is called: “sparam” for string because it’s of the string type. Now we want to find out if the mouse button was clicked and that is the case whenever the id equals the chart event “CHARTEVENT_CLICK” and when that is true we want to use the “Comment” function to output the text: ”You pressed the mouse at the following coordinates:” followed by the x coordinate that is the value of the “lparam” and the y coordinate that is stored in the “dparam”, and that is pretty much it, so when you’re done you can click on the “Compile” button here and that did work without any errors and without any warnings and this code is exactly the same in MQL5 so if you ever wanted to switch from Metatrader 4 to Metatrader 5 the event handling is exactly the same in this case. Now you can click on the little button here or press F4 on your keyboard to go back to Metatrader. In Metatrader usually we would click on “View/ Strategy Tester” or press CTRL + R and you could select the “SimpleMouseClick.ex4” file here and start a new test but wherever you click you won’t get anything, so let’s stop the test here, remove the “Strategy Tester”. Now simply select the Simple Mouse Click Expert Advisor (SimpleMouseClick) here and drag and drop it on your chart. I will confirm that, click on “OK” and here it is! When I click on the chart I get the output: “You pressed the mouse at the following coordinates:”, x is: 97 and y is: 113 and when I click anywhere else the values will change because every time I click the chart event is triggered and now you know how to create an Expert Advisor that can get the coordinates of each and every mouse click on your chart and you have created it with a few lines of MQL4 code.
    6 min
  • MQL4 TUTORIAL BASICS – 125 SIMPLE ATR SELL TRAILING STOP
    In this video we are going to create an Expert Advisor that is able to use the Average True Range indicator for a sell trailing stop. So let’s find out how to do that with MQL4. To get started please click on a little button here or Press F4 on your keyboard. Now you should see the Meta Editor window and here you want to click on File, new File, Expert Advisor from Template, continue. I will call this file Simple Average True Range Sell Stop. Click on continue, continue and finish.   Now you can delete everything above the on tick function. And let’s also remove the two comment lines here. We want to have a basic stop point value for 100 points. So let’s define that first. And for the trailing stop we need a calculated stop point value. These are global variables so they will be available in all the functions. Inside of the Ontick function, we first want to create a string variable for the signal, but we don’t assign a value here because we are going to calculate that now.   Let’s start with the included IATR function that comes with MQL4   . To calculate the average true range value it uses a few parameters. The first one is for the current symbol on the chart, the second one is for the currently selected period on the chart. We want to calculate the result based on 14 candles.   This last parameter here would be a shift value. We don’t need that, so we set it to zero. Let’s create a static double variable for the old value. Because we want to be able to find out if the current average true range value is below the old value or if the old value is zero. That would be the case the very first time we run this expert advisor. And if one of the conditions is true, we want to set our signal to sell. And if we have a sell signal and the return value for orders total is zero, that would mean we have no open orders and that’s when we use order send to open a sell order for ten microlot.   We would do this on a demo account, because we need to have an open position to check if the trailing stop is working. Because now we can calculate the stop point value by calling a user defined function with the name Check ATR Sell trailing stop. We will pass the average true range value. And this function doesn’t exist so far, so we need to create it in a few seconds. But before we do that, we want to use the comment function to create an output on the chart for the current signal, the average true range value, and the calculated stop point value. Afterwards we want to assign the current average true range value to the old value. And that’s it for the main function. Now we need to create this one. Our user defined function is called Check ATR Sell Trailing Stop. We pass the average true range value here.   Our calculated stop point value will be the basic stop point value and we will add the result of this little calculation here. Now we can calculate the stop loss price and that will be the bid price. And we will add the calculated stop point value times the point value. Now we use a for loop to go through all the open orders. We use Order select for the current counter value and select the position for the trade. Afterwards we want to check if the current order symbol and the symbol on the chart are the same.   And of course we want to know if the current order type is a sell order. That would be the case when it is equal to Op_Sell. And if the order stop loss for the current order is higher than the calculated stop loss price, that’s when we want to use Order modify for the current order ticket and the current order open price to set the stop loss to the calculated stop loss price. The order take profit, the expiration and the color will remain unchanged. Now we need to close the loops.   This here is an if loop. You can see that the brackets are highlighted. So let’s end the if loop, the for loop, return the calculated stop loss value to the main function . And this is the end of our user defined function.
    8 min
  • MQL4 TUTORIAL BASICS – 124 SIMPLE ORDER CLOSE TIME
    In this video we are going to create an Expert Advisor that is able to get the Order close time from the Order history. So let’s find out how to do that with MQL4. To get started please click on the little button here or Press F Four 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 Order Close Time.   Click on Continue, continue and finish. Now you can delete everything above the Ontick function and let’s remove the two comment lines. This is about the order history, so we need something in the history. And when Orders total equals zero, we need to open a few test positions. You wouldn’t do that on a real account, but on a demo account we can use Order Send to open a buy and a sell position, just to have something to test. And once we have done that, we use this user defined function called Check Closetime.   It doesn’t exist so far, so we need to create it now. The name of our user defined function is Check Close Time. We use Void here because we don’t have any return type. Now we use a for loop to go through all the open orders. And to get data for closed orders we actually use Order Select. But this time we use Mode underscore History, because Mode history will make it possible to select an order from the history pool for closed and canceled orders.   Now let’s continue and get the current time. We use Time Local to get a Date time object that is called My Time. We want to use MQL Date Time to create a time struct. Now we want to convert the local time called My Time that we have created here to the structure that we have created there because this will make it possible to get parts of that struct. For example, the current hour can be calculated by looking into the struct and extracting the hour.   We can also convert the time for our output that is done by using Time to string. We use Time Local, time Date and Time seconds. When you use Order Open time, you will get the opening time. To get the closing time you can use Order Close Time. Let’s create two more structs, one for the open and one for the close time.   And once again we use Time to Struct to convert it. Let’s once again use Time to String to create a string for the opening time with seconds and for the closing time with seconds. And finally, we want to create an output by using the print statement. That will output the order ticket, the open time, the Close time, the Order profit, and the local time. And we will see the output for each order in the history in our Journal tab. Finally, please close the for loop and the function and that’s about it.   Well if you have no idea what all the code here does or if this was too fast for you, you may want to consider to become a premium member of the premium course. You can find that one on our website and this actually was once again a suggestion of a premium course member. And if you are already a premium course member and have an idea for a video like this one please let me know. For now please click on the compile button or Press F seven on your keyboard.   You shouldn’t see any errors here and if that is the case you can click on a little button here or Press F four to go back to MetaTrader. And in MetaTrader you want to click on View, Strategy Tester or press CTRL and R. Please pick the new file simple Order Closetime Ex four. Mark the option for the visible mode here and start your test. Now the expert advisor is running. Let’s click on the Journal tab. Currently we don’t have any closing time, because so far our first two orders have not been closed. So let’s speed that up a little bit. That’s enough. Now click on the Journal tab and now you can see the opening time and the closing time for our test orders. So our little expert advisor actually works as designed and in this little video you have learned how to calculate and output the opening and the closing time for closed orders and ...
    6 min
  • MQL4 TUTORIAL BASICS – 123 HOW TO FIND ERRORS IN BIG JOURNAL FILES
    In this video we are going to look for errors. This should be a sell trailing stop but as you can see there is nothing trailing. So we have an error. We can’t see the cause. It doesn’t appear on the chart. We have some results. Nothing on the graph tab, nothing inside of the reports. But the journal tab shows a lot of errors here. I did that by purpose to show you how to find errors in big journal files. So let’s stop the test here. You can see we have hundreds and hundreds of entries here. In this case it wouldn’t be hard to find out that we have errors, but if these errors only occur every two or three days, it would be hard to find. So we need to have a way to do that. Please right click and select open. Now you should see an explorer window for the log file. This is the log file from today and when you put the mouse over the file name, you will see that this is a single file and it is 640 megabytes. So it’s a very big file. If I right click it and select open, Windows would try to open it in Notepad. And it would probably crash because Notepad is not a good choice to deal with big files. Therefore, I’m going to use this application here. It is called Notepad Plus Plus. This is a free editor that is able to deal with huge files. You can download it on websites like Chip for free. So this is myLog file and when I scroll down you will see that we have a few hundred thousand lines here, exactly 5.2 million. Now you could go through the whole file manually but it would take hours and hours to do that. And the good thing is that this editor has a good search function. Let me modify the language here. So this should be better for you. Now we click on search, find. I would like to look for the term error and now I click on find all in current document. This might take a little while. Now here is my search result and I can now click on any of the entries and it will take me to the line where the error is located. As I said before, I intentionally have caused these errors because I have used a totally wrong value for the stop loss. If your file gets too big you can right click into the Journal and Select Clear all journals that will also delete the file in the directory. Let’s speed that test up a little bit and you will get a new journal file. This time I have a different expert advisor and it says order modify Error 130. If you go to Google and look for that error, one of the first entries should be from bookmql4.com. This is the error codes appendix and here you can find all the errors and some additional explanations. This might be helpful because not every error code is easy to understand. That’s it for now. Because in this little video you have learned how to find errors even for big journal files and you have done it yourself within a few minutes.
    5 min
  • MQL4 TUTORIAL BASICS – 122 SIMPLE AVERAGE TRUE RANGE BUY STOP
    In this video we are going to use the Average true range indicator to create buy trailing stops for buy trades. So let’s find out how to do that with MQL 4. To get started please click on on a little icon here or Press F Four on your keyboard. Now you should see the Meta Editor window and here you want to click on File, new File, Expert Advisor from Template. Continue. I will call this file Simple Average True Range Buy Stop.   Click on Continue, continue and finish. Now you can delete everything above the on tick function and we want to remove the two comment lines here. We start by creating two global variables. The first one is for the basic stop point value. We will start with 100 points.   The second one is the calculated Stop point value. This is the one we are going to use for the trailing stop. Inside the on tick function we need to create a string variable for the signal. We don’t assign a value here because we are going to calculate that now. To do that, we use the included IATR function that comes with MQL 4.   It needs a few parameters. The first parameter is for the current symbol on the chart. The second one is for the currently selected period on that chart. We want to calculate the value for 14 candles. We don’t use a shift value, so we set the last parameter to zero.   The next variable is a static variable. Static is a modifier that will keep the variable available for as long as the program is running. The name of this variable is old value and we are going to compare it with the current one, because if the average true range value is above the old value, that would be a buy signal and that is when we assign the word buy to our signal. So if our signal equals buy and orders total equals zero, that would mean we have no open orders and a buy signal. And that’s when we are going to use order send to open a buy trade for ten microlot.   This of course is just a demo account and a test position. You wouldn’t do that on a real account, but now we are going to call this function Check ATR Buytrailing stop and to check stop loss we need a position. That function doesn’t exist so far, so we need to create it now. We will pass the average true range value as a parameter. And the return value will be assigned to this variable Calculated Stop Point value. But before we need to code it, we want to create a comment statement on the chart to output the current signal, the average true range value, and the calculated stop point value.   And at the end of the main function we assign the current average true range value to the variable called old value, so we can use it the next time we call the function and that’s it for the main function. So let’s create this one. Our user defined function will be called Check ATR Buy trailing stop and we will pass a parameter. This is a double variable called Average True Range value. The calculated stop point value will be the basic stop point value. And we use the average true range value and multiply it with 100,000 to add it to the basic value.   Now we have the calculated points. So let’s get the actual calculated stop loss price and to calculate this one we use the ask price and subtract the calculated stop point value times the point value. Now we can use a for loop to go through all the open positions. We use Order Select to select each trade that we have. Then we want to know if the current order symbol equals the symbol on the chart.   If that is true, we need to know if the current order type equals Op Buy. So it is a buy trade and if the current value for the order stop loss is below the calculated stoploss price. That is when we use order modify for the current order ticket and the current order open price, we want to change the stop loss value to the calculated stoploss price. The order take profit, the expiration and the color will remain unchanged. Finally, we need to close the loops and return the calculated stop point value to the main module and that’s about it.
    9 min
  • MQL4 TUTORIAL BASICS – 121 SIMPLE RSI SELL STOP LOSS
    In this video we are going to create an expert advisor that is able to open a sell position when the RSI value is above 70 and to close the position when it is below 30. That should happen in a few seconds. So let’s find out how to create that with MQL Four. To get started, please click on a little button here or Press F four on your keyboard. Now you should see the Meta Editor window and here you want to click on File, new File, Expert Advisor from Template, continue.   I will call this file simple rsi sell stop.   Click on continue, continue and finish. Now you can delete everything above the on tick function and let’s also remove the two comment lines here. We will start by creating a string variable for the signal, but we don’t assign a value here. Let’s continue and calculate the RSI value. That is done by using Irsi for the current symbol on the chart and the currently selected period on the chart. We want to calculate the value for 14 candles and it should be based on the close price.   The shift value is zero because we don’t need it. Now let’s check if we have any open orders. That can be done by checking the return value for orders total, and if that returns zero, we don’t have any open orders, and when the RSI value is above 70, we want to use order send to open a test order for ten microlot. It should be a sell position. Afterwards we want to check the RSI Sell stop and pass the RSI value that we have calculated here as a parameter, but this function doesn’t exist, so we need to create it in a few seconds.   Before we do that, please add a comment statement that will output the RSI value directly on the chart.   Now let’s create this function. The name of the function will be Check RSI Sell stop. We pass a variable called RSI value and the return type is void because we don’t need to return anything. Now let’s use a for loop to go through all the open orders. We select each trade by using Order Select.   Now we check if the order symbol is equal to the current symbol on the chart and we want to know if the order type for the current order equals Op sell. If that is true, it’s a sell position. Let’s add another condition. We only want to close the open position if the RSI value is below 30. If that is the case, we use Order close for the current order ticket and the current order lot size.   This expression here will give us the current ask price. This is our slippage and the color will be red. Finally, please close the for loop and the function and that’s about it. Well, if this was too fast for you or if you have no idea what all the code here does, you maybe want to watch one of the other basic videos, or maybe even the premium course might be interesting for you. You can find that one on our website. For now please click the compile button here or Press F seven on your keyboard. You shouldn’t get any errors here, and if that is the case, please click the little button here or Press F four to go back to Meta Trader. And in Meta Trader, please open an empty chart. Select Insert, Indicators, Oscillators, Relative Strength Index. We want to go with the default values here. That is for 14 candles.   Apply to the close price. Now let’s click on OK. Here is the RSI. Now let’s right click into the chart. Select Template, Save template and save it as tester TPL because that is what you are going to see in the next strategy test.   Now please click on View, Strategy Tester or Press Control and R. Please pick the new file simple RSI Sell Stopp Exfour. Mark the option for the visible mode here and start your test. Here we are. The RSI is above 70, so here is our sell trade.   Now let’s wait until it is below 30. That’s when it should close the current position. I will speed that up a little bit. It should be closed in a few seconds. And yes, the expert advisor works as expected.   And in this little video you have learned how to create an expert advisor that is able to open a sell position when the RSI value is above 7...
    6 min
  • MQL4 TUTORIAL BASICS – 120 SIMPLE RSI BUY STOP
    In this video we are going to create an expert advisor that is able to open and close positions based on the values of the RSI indicator. So let’s find out how to do that with MQL4. To get started, please click on a little icon here or Press F four 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 RSI buy stop. Click on continue, continue and finish. Now you can delete everything above the on tick function and let’s remove the two comment lines here to calculate the RSI value. We can use the included function Irsi. It comes with MQL4 and we need to pass a few parameters.   The first parameter is for the current symbol on the chart. The second one is for the selected period on the chart. We want to calculate the RSI indicator for 14 candles. The result should be based on the close price and this last value here is a shift value. We don’t need that, so we use zero.   First we want to check if we have no open position. That would be the case when the return value for orders total is zero, the entry condition for a buy trade would be when the RSI value is below 30. That is when the blue line here is below the lower dotted line. And if these conditions are true, we are going to use order send for the current symbol on the chart to open a buy trade for ten micro lot. Afterwards we want to call a function that is called Check RSI buy stop and pass the current RSI value as a parameter. And to see what’s going on, we will use a comment output to output the text RSI value and the calculated value on our chart.   So far, so good – with the main module, but this function doesn’t exist so far, so we need to create it now. Our user defined function will use the return type void because we don’t need to return anything. The name is Check RSI buy stop and we need to pass the RSI value as a parameter. Now we use a for loop to go through all the open orders with order select, we can select a position and now we want to know if the order symbol for that position is equal to the symbol on our chart.   If that is the case, it’s the same currency pair.   We want to know if the order type equals Op buy, then it would be a buy order and another condition. We only want to close if the RSI is above 70. If all those conditions are true, we use order close for the current order ticket and the current order lot size to close the order for the bid price. The next parameter here is the so called slippage, and the last one is for the color. Afterwards we want to close the for loop and the function and that’s about it.   If this was too fast for you or if you have no idea what all the code here does, maybe you want to watch one of the other basic videos first, or maybe even the premium course on our website might be interesting for you.   This was a suggestion from another Premium course member, and if you are a Premium course member and have an idea for a video like this one, please let me know. For now, please click on the compile button or Press F seven on your keyboard. You shouldn’t get any errors, and if that is the case, you can click on a little button here or Press F four to go back to MetaTrader and in MetaTrader you want to pick an empty chart, please click on Insert, Indicators, Oscillators, Relative Strength Index.   We will go with the default values for a 14 candle period. The result should be calculated based on the close price, so please click on OK. Now you should see the RSI oscillator below the candle chart now, right click into the chart.   Select Template, Save template and save it as Tester TPL. You can override it the current one because Tester TPL is what we will see in the next strategy test. Now please click on View Strategy Tester or press CTRL and R. Please pick the new file simple RSI buystop E X four, mark the option for the visual mode here and start your test.   Here we are.
    7 min

About MQL4TUTORIAL.COM

From the publisher's feed

MQL4 Tutorial for Metatrader 4 or MT4 about automated trading, trading robots, MQL 4 and MQL programming