Here is something that sounds almost too good to be true. Making money in the markets is entirely possible – and the path there is surprisingly straightforward. So straightforward, in fact, that it’s hard to understand why more people aren’t doing it.
The catch: you have to act consistently against your own instincts. Every single time. Your mind tells you to buy – so you sell. Your gut tells you to hold – so you close. Experience tells you to wait – so you act immediately.
And if that doesn’t work out? Your broker is more than happy to step in. Reliably, persistently, and with genuine appreciation for your loyalty.
Brokers do particularly well with beginners – not because they set out to, but because trading generates emotions like almost nothing else. And when emotions take over, most people are just trying to feel good. That, however, is precisely the opposite of what actually works.
Let me put it another way. Have you ever considered attempting a backflip? Everything you need, you already have: two legs, a body, a head. The difficulty isn’t physical – it’s that you have to send that head backwards over yourself.
The moment you leave the ground, there is no changing your mind. Anyone who reconsiders halfway through lands exactly where you’d expect – on that head.
Trading follows the same logic exactly. The moment you start questioning an open position and hesitate, you’ve already secured the worst possible result.
The real issue isn’t trading. It’s that most people hit the ground head-first on their first attempt – and then spend a surprisingly long time trying to figure out how they ended up there.
The post MQL5 Tutorial English – AI Trading Backflip – How Your Instincts Work Against You appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
Okay, today is December 30th. So Christmas is over and we are now at a profit of about twelve euros. This means that trading picked up again a bit after Christmas. We have a few more positions here and if you are wondering why the different sums are appearing here, it is because I have selected the one-hour chart here and I have also set up my system so that it only checks once an hour to see if we have an entry or exit signal. This can sometimes lead to such irregularly high profits. The reason for this is that if I were to run my system on a minute-by-minute or price-change basis, it would require significantly more computing power. In principle, this is justifiable.
However, I have not noticed any improvement. That’s why I’m leaving it at the hour. You can see here, when you move the mouse over it, that a position was opened and a position was closed at a profit of €3.90. This is the last position. If we zoom in a little closer, we can see that there is a second position and that the two are connected by this dashed line. This means that both positions were opened at different times but closed at the same time. One of the main problems is that beginners now do the math and say, “Man, I made a profit of €12 in x days. Then I extrapolate that one-to-one and that means I earn so-and-so much.” Unfortunately, this is not realistic in practice, because there are always phases where we experience drawdowns and these can last for days, weeks or even months.
And that is why most traders lose their nerve after a while, because they see their account melting away in their mind’s eye and have the very strong feeling that the risk is much higher than the profit expectation and that the trading risk cannot be justified. And it is to be expected that a lot will change in the United States at the beginning of January and here in Germany in February. And such changes can usually be seen quite quickly on the chart. The question is whether they will work for or against us, but we’ll see. In one of the next videos, I also have to set up advanced statistics for this system so that you can track online what, when, and how it happened. For now, I’m satisfied with the result, the system is running, and I’ll see you in the next video.
The post MQL5 TUTORIAL – Christmas Edition Part 13 appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
So, Christmas is over and we have opened the first few positions. You can see here in the account history that we have currently made a profit of €2.69 and you might wonder why it says €2.71 here at the front. Let’s click here in the column, look at orders and deals. Then it is €2.71.
As soon as we switch it to trades, it is €2.69. Let’s try it with the calculator. 1.08 plus 0.76 plus 1.04 is 2.88. Now we subtract 19 cents in losses and that leaves us with 2.69 euros. You can see the direction quite well here. So, In means we have opened a position. Out means we have closed a position. There are currently no open positions. That doesn’t surprise me, though, because there isn’t much change here between Christmas and New Year. I expect it to pick up significantly at the beginning of January.
However, we can already see quite clearly here that our system works fundamentally. Let’s take a look at the journal. The times can also be seen there and so far we have no fundamental errors in communication. So I would say that our system has passed the first real-time test and we will then take a look in the next few days to see how things progress.
The post MQL5 TUTORIAL – Christmas Edition Part 12 appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
We have already seen the first results and the task now is to find out what we can do to make our system 100 percent safe. And the easiest way to test that is simply to take a much too small account. I’ll take a deposit of €10 here, start my test and within a second the test is finished. We can now see in the backtest that we have used €10 and lost it immediately. It went down almost immediately. Let’s change the deposit and go up to €50 and start our test. Then we should now see in the process that our account is initially developing quite well. We are now at €62, and are now exceeding €70. Now we are at 85, 90, 95. So that’s clearly not going any longer.
Now we’ve passed 100, but that’s as far as it goes. We got to €129 and then our account crashed. Again, it lasted much longer, but in the end it was over. Let’s just go to the other extreme and say we have €100,000 available. And if I start the test here now, I’ll see if I can make it a little more visible, then we can simultaneously observe the development here above and the equity and balance curve here below. That looks much less threatening. I’ll let this run through to the end of the test period. That was it so far. We have a positive result. Here is the drawdown. But at no time was our entire account at risk. The disadvantage, of course, is that the profit in relation is not that high either, so it doesn’t matter.
But what we have learned is that with a €10 account, we can be pretty sure that we will ruin it within a very short time. And that was the first task. So, if the account is too small, there is usually a very high risk that we will reduce the account balance to zero quite quickly.
The post MQL5 TUTORIAL – Christmas Edition Part 10 appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
Okay, let’s take a look at how the system works here. We have an equity, which is the net balance. This is always reduced when we open a position, because every position is initially in the red. We also have the balance, which is the gross balance. And the gross balance always increases when we make a profit and there are currently no open positions. For example, right now our gross balance has increased by €10 and we have no open position because our oscillator is between these two lines.
Now it is below the lower line, which is a buy signal, and if we are in an uptrend, a position will then be opened. Whether we have an upward or downward trend can be seen quite well with the help of these moving averages here. And now let’s speed up the whole thing and let it run for a while. Then we see how many positions our system automatically opens and closes. Here in the strategy test, there is the so-called history. There you can see the opening and closing of the position for each individual position. The “Operations” tab works in a similar way and the journal is always interesting, because this is where we would also see if errors occur. For example, a calculated value may not work because the broker has defined that the stop loss must not be so close to the purchase price, or there could be requotes or problems with the margin.
We would see all these errors here. Our system is trading peacefully all the time and we have now reached €9,636.00. What the strategy tester does not show is the historical curve. We can see that here in MetaTrader 5 itself. You can display the chart and it shows us how our Expert Advisor behaves over the course of our set trading period. All in all, we have a positive result here and now, of course, the question arises: can I improve this result? And if so, how would I do it? To answer that, let’s change a few things and we’ll do it the other way around. We’ll try to find out what measures can be taken to ruin a system immediately.
The post MQL5 TUTORIAL – Christmas Edition Part 9 appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
We have now set up a demo account and a cent account. The MetaTrader is basically set up and now, of course, we want to trade with it. To do that, we first need a version that automates it for us. So let’s download the Christmas Edition here, I’ll copy it and put it in my personal folder in the.MT5 folder, which is hidden but can be shown by selecting “Show hidden files”. There is a drive C in it. There are several subfolders in it. Below Program files, we find MetaTrader5 and there we have to go to the MQL5 – Experts folder. Here we can insert the file and also unzip it directly. This then gives us this folder and everything is in here. The main components are these two green files.
One is the system library, which is compiled and where a large part of the settings for the Expert Advisor are made under the hood. The other file here can be edited by yourself using the corresponding MQ5 version and here, for example, you can select the entry. As I said, I prefer the Williams Percent Range Oscillator as an entry signal. If we now click on Experts on the right and select Update, we should already find our demo version. Here you can change the settings. For example, you can increase or decrease the trading risk here. Let’s do a first test. To do that, we click on View, “Strategy Tester” or press Control and R. We want to do a single test with the system just mentioned.
I’m doing euro-US dollar because that’s the most popular currency pair in trading. I’m looking for a period from 2024 to the end of 2024. Let’s make it a bit bigger, then we can see here that we can set a delay. I would like to have every tick. My deposit would now be €9,500. My leverage is 1,500. I’ll leave out the visual mode for now, because that would take quite a while. And when I click on Start Test, the historical data for the year should now be downloaded. You can also see that here in the journal. And our system is already starting to trade. Let’s just let it run. So, and that was it. The display here may look a bit distorted. This was a hefty drawdown.
Let’s check one of these free robots here. Start a test and the results will look like this. Let’s try this one. It makes these beautiful sawtooth lines. But all in all, we now have our system set up to work for automated trading. In the next video, we want to take a look at how such settings work and how you can test and optimize a system like this.
The post MQL5 TUTORIAL – Christmas Edition Part 8 appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
I have already mentioned that I like to use CENT accounts and therefore I want to set up a CENT account right now. I am here on my broker’s website and now I can choose what I want. I would like to use the MetaTrader 5. The account model is MT5 Pro Cent. It is very important that we select a hedging system. As a currency, I can choose euros or US dollars here and I personally find the leverage of 1:000 a bit high. You can even go up to 2000. I usually use 1:500. This makes it easier for me to compare with other systems that I have already traded. Now you can assign a password here and if I click on confirm, my account should be created. That’s happened now. Now, of course, we still have to deposit money. Alternatively, I can make a transfer from my credit here. Let’s do that now. I’m selecting €100 here.
The status is pending. So that may take a bit. Let’s copy our account number already. Of course, an update is offered again now. This typically always happens when you are about to do something else. Unfortunately, MetaQuotes has recently acquired a bad habit. And that is the fact that certain systems report after a certain time that they have to be recompiled because the version is too old. I think that this is to force people to always install the latest version of MetaTrader 5, similar to what is already done with Windows. I now right-click here on Accounts and open an account. My broker is called RoboForex. I click on Next.
Now I can connect to a current account here. The username is my account number. Now I enter my password and click on Done. And as you can see, my account is connected. Due to the current euro-US dollar exchange rate, 10,000 dollars have now become 9,541 euros. Converted, this means that for every 100 euros deposited, I now have 95.41 euros available on my cent account, which are traded as if they were 9,541 euros. And when it comes to payment, it is then recalculated accordingly using the factor of 100. In any case, I have now connected my demo account and my cent account and in the next video we will continue with automatic trading.
The post MQL5 TUTORIAL – Christmas Edition Part 7 appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
When we install the MetaTrader for the first time, we are shown four such charts. These are preset and show different indicators or oscillators. Basically, you have to get away from the idea that what is displayed is also what is actually traded. This is because I can display an indicator on my chart that has no function but only serves to make something visually more visible. That’s why we want to change the charts a bit now. The first thing that is displayed up here is this quick trading function. This should lead to people manually opening or closing a position on the chart. For automated trading, we can deactivate this here via this small button. These indicators that are displayed can also be marked and we can either display the properties here. For example, we could change the number of candles or we can right click and delete the indicator.
Also, right-click on properties. Here we can define whether we want to see bars, candles or lines for the price movements. But we I can also do that in the bar at the top. I can determine whether my chart should scroll automatically. This means that I always see the current state here on the right-hand side, and I can also move it a little to the left by activating chart shift. This would be very useful, for example, if you wanted to project indicators into the future. Under the second tab, I can show or hide the ticker, which is the text at the top. Completely remove the quick trading buttons, and I am also not a fan of having this grid displayed. The trading levels and the trading history are not yet visible here. This would show us where we have already opened and closed positions. That’s why I’ll leave it as it is and you can change the colors again using this tab if you like.
For now, I’ll leave it as it is and click on okay. And so that I don’t have to do this every time, I can save it as a template. To do this, I right click with the mouse, select Templates, Save Template, and there are two names that are reserved. One is default. This would now always be displayed when we do live trading. That means in real time, which does not happen at the moment because there are no price changes at the weekend. I can also save the template under the name tester. This is then the template that is always loaded in the strategy tests. If I want, I can also save further templates here at any time or reload templates. This is quite useful if you want to make visual decisions on the chart. For automated trading, however, this setting is actually okay. I will import my robot trading system here and a lot of additional information will be displayed.
For now, we have defined and saved our template. We can now also load it for the other charts if we wish. I will first deactivate all other currency pairs and save this as the default profile under profiles. If I now close and reopen the MetaTrader, my standard view in the standard profile with my standard template should be reloaded as I left time, and that worked. We will continue in the next part with the import of an automated trading system.
The post MQL5 TUTORIAL – Christmas Edition Part 6 appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
Okay, our MetaTrader is now up and running. Even after changing the energy-saving settings, our server no longer wants to constantly go into sleep mode. And we still have to set two or three things before we can use it. Today is the weekend, so there will be no price changes. Let’s go to Extras – Options. The server settings are okay so far. I don’t need messages, so I can deactivate them. I used to reduce the maximum number here in the charts because the computing power of older computers was still quite modest. On the trading tab, I always set a default size that is as small as possible. This prevents you from accidentally clicking on the chart and opening a large position when you don’t actually want to.
The important tab for us here is this expert tab. Here we have to allow algorithmic trading. As a security feature, you can disable the option to continue trading after an account or profile change. I don’t need that here. The import of DLLs is useful if we want to use an external statistics service, such as FXBlue or MyFxBook. And one of the first things I always turn off are these annoying event sounds. With a virtual server, I don’t really care, but I always turn them off anyway. And if we click on OK now, we should have the basic settings done. Algorithmic trading is now allowed up here. The tabs below are also becoming more and more from year to year.
The tab for trading is important for us. Here we see the account balance and we would see positions. And you can display columns in the positions, for example the swap costs. These can be quite significant and are not displayed at all by default. In addition, you can display the comment here, provided that you use a system that works with comments. And there is one more subtlety: even if algorithmic trading is allowed up here, it is still possible that a different setting has been selected on the chart. In the next video, we will set up the chart differently and also save a template for automated trading.
The post MQL5 TUTORIAL – Christmas Edition Part 5 appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts: Okay, in the last video we had already installed the MetaTrader. Now I have to restart my server again because it keeps switching to energy-saving mode. If we turn everything off, it might be better. Somehow you can’t find anything here now. So where is our MetaTrader installation? Normally you can find this script in the home directory. There’s another one here. This refers to the installation, just like this one. If we go to the settings at the top, we can say that we would like to show hidden files. This also works with Control+H. And if you do that, you can see that these slightly hidden folders appear here. Actually, a desktop file should also be created. Why mine was missing is a mystery to me. In any case, it worked during the second installation. And after we have started the MetaTrader, we can now set up an account here. Let’s choose “Metaquotes” for a demo account. Now we have to fill out this form. This would correspond to a deposit of 500 Euros on a cent account. The leverage of 1 to 500 is relatively difficult to get in Germany and Europe. I use it all the time with my broker RoboForex. I agree to the terms and conditions for opening the account, click on Next and here I get my access data for the demo account. Now another package is being installed. But that’s pretty quick. And here is our demo account ready for trading. The setup was successful so far. Then our account should be connected and available immediately and we are ready to make the settings in the next video to proceed with automated trading.
The post MQL5 TUTORIAL – Christmas Edition Part 4 appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
Now that we have set up our Debian server for €3.29 so that we can get started with it, we would of course also like to install the MetaTrader. To do this, we first go back to the console, switch on the graphical mode here and we see the message: Display Output is not active. So let’s turn off the server and restart it. This may take a few seconds. Now we can see something again. And when our interface is loading, we open Firefox, go to the website Metatrader 5 dot com and click on Download for Linux. Then there is this command, which we copy out, open the console, that is, the Linux terminal, and paste it in here. Now I have to enter the password and realize that I am not authorized at all. So I log in again as root, because I still have to enter a file that allows me to make changes to the system. This is done with this line here.
That’s my username and these are the rights I give myself. The file is called sudoers. These are all the people who are allowed to access sudo on the system, which means execute as root, that means with full rights. Let’s try that again. Then our script should actually start and perform the installation of MetaTrader 5. Various package lists are now being downloaded here. Yes, I want to continue. The MetaTrader and some Linux files are now being installed in the background. These include Wine, among other things. Wine is a Windows emulator. The logo is this red wine glass and you can install it directly from the sources of the Linux distribution. The advantage is that Wine is able to run Windows programs on a Linux system. Meanwhile, we have already reached version 10, so it has been around for a few years and you can now get graphically demanding games to run with it. Our MetaTrader doesn’t need that much graphics power. Nevertheless, quite a bit is installed. The nice thing is that it’s all automated now. In the past, you had to do some tricks.
Here is the MT5 Setup EXE. Now there is a Wine-Mono package for the Dotnet environment. And when that’s done, we should be done pretty quickly. And now it’s time. We can start the MetaTrader 5. In the past, there was always a problem here, where you had to change one or two settings, because otherwise you couldn’t load any installation data. This works much better now and the installation is already complete. Our MetaTrader 5 is installed and started. The next video will continue with the setup.
The post MQL5 TUTORIAL – Christmas Edition Part 3B appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
First of all, let’s create a new server that we can then use to operate our system later. I already have two servers here that are for AI solutions that I create for companies, but we will now add a server for trading. This is relatively easy to do at Hetzner, is GDPR-compliant and also relatively inexpensive. We can opt for different operating systems here. I’ll take Debian here, I’d like a shared CPU for Intel AMD compatible systems and the cheapest version with 4 GB RAM and 40 GB memory for €3.29 a month is enough for me here.
We click on Order now and here is already our third system. This is now being created. We can click on the three dots here to open the console and then we are already in the login area. The access data comes here by email. We copy the password, log in with it here on the server. The password must now be changed. In other words, we do that. That worked too. A short update so that the system files are updated. Now we’ll do an upgrade. This should actually be pretty fast. And as you can see, the performance isn’t bad at all. Considering that we booked a very affordable system, it’s running pretty quickly. We should be ready in a few seconds. OK, let’s try the graphical installation, because we had one or two problems with the ISO image. For example, the keyboard layout was wrong. That’s why I’m selecting German here.
I’m in Germany, I speak German. Now it’s loading a bit. All in all, it’s pretty fast here. Now a few network components are being configured and I can assign a name. Let’s use MQL5 Tutorial. We’ll leave the domain as it is. Assign a password for the root user. Then I create my own account. I also have to assign a password for that. The partitioning is loaded. Everything on one partition. Continue. Yes, please format. And now the base system is installed. This may take a while. The server is running here in Nuremberg, in other words, it is GDPR-compliant in Germany. It will probably take a little while. I’ll get a drink then. The installation continues. We can still choose a server from which we will get the updates. We don’t need a proxy. Now software is being installed. No, I don’t want to send statistical data. And here we can now choose which graphical user interface we like. I’ll try KDE Plasma. Click on Next. Now we just have to wait for a while. We should be ready right now. Now the boot loader is being installed.
Yes, please. One more short update. Final installation. The installation is complete and ready. Now we just eject our ISO image and restart our server. And if we’re lucky, we should see a graphical interface immediately. To do that, you have to turn on this GUI mode down here. Let’s see if our login works. KDE is loading here and here is our graphical desktop interface. All in German. For example, we can add our terminal to the bar down here and this time our umlauts work and the keyboard layout is completely in German. Firefox is already there too. In other words, we can open the metatrader5. com website. That works too. And this is where we can download Linux, which is what we will be doing in the next video.
The post MQL5 TUTORIAL – Christmas Edition Part 3 appeared first on MQL5 Tutorial.
Trade the system yourself with Metaquotes demo accounts:
If you have watched the last video and like the results, you might ask yourself at this point: What does this system actually do? To answer that, let’s go to the settings and turn on the visual mode. 14 years would be a bit much now. Let’s take 2024. I prefer the euro/US dollar because it is the most traded currency in the Forex sector. And I trade on the 1-hour chart because I believe that this is a period that most people take into account. And trading is partly about psychology, even though there are now a great many automated systems on the market.
I have set a random delay here, I want to trade every single tick, in other words every price change, and my default value here is 10,000 US dollars. You can also switch this to euros. Now I’ll just click on Start Test and I also want to use visual mode. And what we see here is the so-called strategy tester. In the upper area, we see the individual candles. Each of them represents an hour. We have two moving averages here. These are calculated in such a way that there is a larger and a smaller long-term average, and these two averages can be used to determine the long-term trend direction. Here in the lower window, we see the Williams Percent Range oscillator. This has recently become my favorite oscillator for entries and, in my opinion, works very, very well. And up here in the area, we see all the text output. You can see here that buy and sell signals are generated and what is happening now is exactly what I said earlier. We see a myriad of positions being traded and for a human being it would be hard to bear at this point, because the account could potentially suffer quite a lot of damage here. But as we can see, it has been resolved and in the end result we should now see this drawdown appearing on the chart.
Our system has recovered here and is now trading again. By the way, this is a problem with the Linux version. The display above is not really stable, because normally we would have to see a few more sliders and the display for the market data is also gone. However, we should be finished with our test in a moment, because it only takes about 3:30 minutes and we have already arrived in November. And at this point, most people would get scared and close their accounts. Unfortunately, such drawdowns cannot be avoided. There are always major or minor slumps in equity. Here my controller has now reappeared and I’m trying to speed it up. Of course, I now have 20 other programs running on my computer in addition to the recording software and the MetaTrader, and that puts a lot of strain on this Windows emulation.
But we don’t have to go through with this now. The main thing is to explain how it works. It says up here that my license is about to expire. This has to do with the fact that the Robot Trading System is a system for end customers and each of them gets a separate license for an account. I’ll extend it for myself right away and the next video will be about the basics of making trading decisions here. That’s it for this video, and I’ll see you again in the next video.
The post MQL5 TUTORIAL – Christmas Edition Part 2 appeared first on MQL5 Tutorial.
In one of our other videos we have created a simple buy trade system and this is the result of a whole year.
It made seventy three trades, fifty four were short trades and nineteen were long trades.
You see under the input tab we have absolutely no values here so we cannot set anything that is not hardcoded in our source code.
Now we want the user to be able to adjust the Lot Size of a trade here, to do that we simply click on Simple Buy Trade and click Modify.
This is how our short E.A. looks like and this is the Lot Size.
To create a dynamic value that can be changed by the user you have to make it an input variable and will be a double variable, and we will call it MyLotSize.
Let’s assign ten Micro Lot here, copy the name and exchange the fixed ten Micro Lot Size here with our new variable.
I will save it as Simple Buy Trade with input. Let’s compile the code and hit F4 to bring up the Meta Trader.
I will select the system here, check the visualization option and start the test. This is our first trade and its ten Micro Lot.
Let’s stop the test, go to inputs and change it to 0.2, now it is 20 Micro Lot.
If you make something adjustable by the user, you can do it by making it an input.
Afterwards the value can be simply changed without recompiling the code.
Download “MQL5 Simple Buy Trade with User Input EA from MQL5 Tutorial”SimpleBuyTradeWithInput.txt– Downloaded 453 times– 381.00 BThe post MQL5 Tutorial – How to simply adjust user input with MQL5 appeared first on MQL5 Tutorial.
With MQL5 for Metatrader5 we can use the ICCI function that is built in to create an Expert Advisor that will use the Commodity Channel Index Indicator to create entry signals on our Forex Trading Chart…This video is about the commodity channel index.
The commodity channel index is an oscillator and it will tell you if something is overbought or oversold.
This is one of the oscillators I like because it is very easy to understand.
It has one hundred plus and a one hundred minus line here and whenever the value rises above the upper line, it’s overbought.
In the other case if the indicator falls below the lower line, it’s oversold.
The commodity channel index can be created with the MQL 5 function ICCI that is built-in into MQL 5.
And now we want to create a little Expert Advisor that will tell us when the market is overbought or oversold.
To do that please click the little button here or hit the F4 key on your keyboard. That will bring up the Meta Editor, and here we want to select File, New, Expert Advisor from template, continue.
And we will call the Expert Advisor Simple Commodity Channel Index. Now click on Continue, Continue, Finish, everything above the Ontick function can be removed and we will also delete the two comment lines here and we will start by creating a little array for our prices.
It’s a double array and we will call it my price array. And for the definition of our commodity channel index, we will use the ICCI function of MQL 5.
For the current symbol on the chart and the selected period, this might be Euro/U.S. dollar and this might be the minute chart or the hourly chart, and the calculation is done for fourteen candles, because this is the default value of the commodity channel index when you drag it on your chart by using Insert, Indicators, Oscillators, commodity channel index.
And it is calculated based on the close prices.
In the next step we need to sort the price array from the current candle downwards by using the function arraysetasseries for the price we have created here.
And now we use copy buffer for the CCI definition from line here.
This is for the first line, it is line zero. And for the current candle that’s candle zero, and we need the values for three candles, that’s the three here, and we want to store the results in my price array.
We want to get the CCI value of the current candle in our price array.
Okay now we need the chart output depending on the value so if our value is above the upper line we want to put the text “Overbought” on our chart by using the comment function.
And if it’s below the lower line we want to output the text “Oversold.”
And when it’s between the lines we just use an empty output because we have no signal.
Okay that’s it. If you’re ready, please click on the little compile button here or hit the F7 key on your keyboard.
That should compile your Expert Advisor without any error or warnings. And in that case we want to bring up the MetaTrader by pressing the F4 key or hitting the little button over here.
In Metatrader please click on View, Strategy Tester or hit control and R. That should show you the strategy tester panel, and here we want to select the simple commodity channel index.ex5 file.
Please make sure to mark the visualisation option here and click on start. And here is our Expert Advisor at work.
Now it’s below the lower line and then it says oversold and when it’s above the upper line it says overbought.
Okay, now you know how you can use the Commodity Channel Index Indicator to create entry signals in your own Expert Advisor. And you have done it yourself with a few lines of MQL 5 code.
Download “MQL5 Simple Commodity Channel Index Expert Advisor from MQL5 Tutorial”SimpleCommodityChannelIndex.txt– Downloaded 344 times– 928.00 BThe post MQL5 Tutorial – Simple Commodity Channel Index appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor. Let’s see how we can do that. We start by opening Metaeditor, which can be done by clicking a little icon or pressing F4. The code begins by including the Trade module, which provides functions for trading operations. We then create an instance of the CTrade class, which will allow us to execute buy and sell trades. An input variable named MassTest is defined with a default value of 1, which can be used for mass testing purposes. The OnTick function is where the main logic of the Expert Advisor is executed. First, we calculate the Ask price for the current symbol and normalize it to the number of digits specified by the _Digits variable. Similarly, we calculate and normalize the Ask prices for the GBPUSD and USDCAD currency pairs.
Next, we calculate the Bid price for the current symbol and normalize it, followed by the Bid prices for GBPUSD and USDCAD. A string variable named signal is created to store the trading signal. We initialize the random number generator using the current tick count and generate a random number between 0 and 1. If the random number is 0, we set the signal to “buy,” and if it is 1, we set the signal to “sell.” If the signal is “sell” and the total number of open positions is less than 10, we execute a sell trade for 0.10 lots, which is equivalent to 10 Micro Lots. The trade is executed at the Bid price with a take profit set 250 points below the Bid price. This process is repeated for the GBPUSD and USDCAD currency pairs. If the signal is “buy” and the total number of open positions is less than 10, we execute a buy trade for 0.10 lots at the Ask price with a take profit set 250 points above the Ask price. This is also repeated for the GBPUSD and USDCAD pairs.
Once the code is complete, we press F7 to compile it. If this was too fast for you or if you don’t understand what all the code is doing, you might want to check out the Premium course on our website or watch one of the basic videos first. After compiling, we go back to MetaTrader by pressing F4 or clicking on the icon. In MetaTrader, we press Control and R to start the strategy tester, select the Expert Advisor we just created, enable the visual mode, and start a strategy test. We should then see the Expert Advisor on the chart. If you are already a Premium course member and have an idea for a video like this one, feel free to send us an email. In this video, we have learned how to create an Expert Advisor that uses random signals to execute buy and sell trades with a few lines of MQL code. Thanks for watching, and I will see you in the next video.
The post MQL5 TUTORIAL – Multi Currency Trading explained (in 4 min) appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor that places an arrow object on the chart at the medium price between the current Ask and Bid prices. Let’s see how we can do that. We start Metaeditor by clicking the little icon or pressing F4. First, we get the current Ask price using the SymbolInfoDouble function with the SYMBOL_ASK parameter. The NormalizeDouble function is used to format the Ask price to the number of digits specified by _Digits. Next, we get the current Bid price in a similar manner, using the SymbolInfoDouble function with the SYMBOL_BID parameter, and again formatting it with NormalizeDouble. We then calculate the medium price by averaging the Ask and Bid prices. This is done by adding the Ask and Bid prices together and dividing by two. To generate a random number, we initialize the random generator with MathSrand using the current tick count from GetTickCount. We then calculate a random number between 0 and 99 using MathRand and the modulo operator. We create an arrow object named MyObject on the chart using ObjectCreate.
The parameters include the symbol, object name, object type (OBJ_ARROW), and the time and price where the object will be placed, which are TimeCurrent and the medium price, respectively. The arrow code for the object is set using ObjectSetInteger with the OBJPROP_ARROWCODE property and the random number generated earlier. We set the size of the arrow object using ObjectSetInteger with the OBJPROP_WIDTH property and a value of 20. The object is moved to the current candle high using ObjectMove, with parameters including the symbol, object name, time, and medium price. Finally, we display a comment on the chart showing the Ask price, Bid price, and medium price using the Comment function. After writing the code, we press F7 to compile it. If this was too fast for you or if you don’t understand what all the code is doing, you may want to check out the Premium course on our website or watch one of the basic videos first.
If the compilation works, we go back to MetaTrader by pressing F4 or clicking on the icon. Back in MetaTrader, we press Control and R to start the strategy tester, pick the Expert Advisor that we have just created, enable the visual mode, and start a strategy test. We should see the Expert Advisor on the chart. If you are already a Premium course member and have an idea for a video like this one, you can send us an email. In this video, we have learned how to create an Expert Advisor that places an arrow object on the chart at the medium price between the current Ask and Bid prices with a few lines of MQL code. Thanks for watching, and I will see you in the next video.
The post MQL5 TUTORIAL – How to draw arrow symbols on the Chart (explained in 3 min) appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor that trades based on the spread and the price movement of the last few candles. Let’s see how we can do that. First, we start Metaeditor by clicking the little icon or pressing F4. We include the Trade.mqh library, which provides trading functions. We create an instance of the CTrade class called trade. We also define a user input parameter MaxSpreadAllowed, which sets the maximum spread value allowed for trading. In the OnTick function, we begin by calculating the Ask price using the SymbolInfoDouble function and normalizing it to the number of digits for the current symbol. Similarly, we calculate the Bid price. We then create a string variable named signal to store our trading signal. Next, we create an array of MqlRates structures called PriceArray to store price data. We set the array to be sorted from the current candle downwards using ArraySetAsSeries. We fill the array with price data for the last three candles using the CopyRates function. We calculate the current spread using the SymbolInfoInteger function and store it in the variable CurrentSpread.
We create an empty string called SpreadFilter to store the spread filter status. We then check if the current spread is above or below the allowed spread. If the current spread is greater than or equal to MaxSpreadAllowed, we set SpreadFilter to indicate that trading is not allowed. If the current spread is less than or equal to MaxSpreadAllowed, we set SpreadFilter to indicate that trading is allowed. We analyze the price movement by comparing the closing prices of the last two candles. If the closing price of the previous candle is higher than the one before it, we set the signal to “buy”. If the closing price of the previous candle is lower, we set the signal to “sell”. If trading is allowed based on the spread filter, we proceed with the trading logic. If the signal is “sell” and there are no open positions, we execute a sell order for 0.10 lots (10 micro lots) at the Bid price with a stop loss set 150 points below the Bid price.
If the signal is “buy” and there are no open positions, we execute a buy order for 0.10 lots (10 micro lots) at the Ask price with a stop loss set 150 points above the Ask price. Finally, we create a chart output using the Comment function to display the current spread, the allowed spread, and the trading status based on the spread filter. We press F7 to compile the code. If this was too fast for you or if you don’t understand what all the code is doing, you may want to check out the Premium course on our website, or watch one of the basic videos first. If the compilation works, we go back to MetaTrader by pressing F4 or clicking on the icon. Back in MetaTrader, we press Control and R to start the strategy tester, pick the Expert Advisor that we have just created, enable the visual mode, and start a strategy test. We should see the Expert Advisor on the chart. If you are already a Premium course member and have an idea for a video like this one, you can send us an email. In this video, we have learned how to create an Expert Advisor that trades based on the spread and the price movement of the last few candles with just a few lines of MQL code. Thanks for watching, and I will see you in the next video.
The post MQL5 TUTORIAL – Spread Filter explained (in 4 min) appeared first on MQL5 Tutorial.
As a trader, wouldn’t you like to make a bigger relative return than Warren Buffett does with his investments? And would you also like to know why most people would find that very boring? In this video, you will learn everything about the strategy that I use. This is something I wanted to show you because we have correlations, which means we have entries and exits, and we have this oscillator here. This is the Commodity channel Index, and you can see we have entries in blue and we have exits in red. And the idea is whenever we get below the lower line, we want to buy. And when we get into the profit, we want to sell. In this case, we have a blue arrow here, which means we have taken a trade. And once the profit goal was reached, it was closed here. And this is the chart that people like to show you because it all makes sense every time I have a spike below the lower line, we can open a trade and it runs into a profit. And that’s what people want to see. But from time to time, it can also go the other way.
Like in this case, we had this entry signal. And it opened a trade here. That wasn’t a profit right away because the market went down. And the happy end is here when it was able to close the two open positions in a profit. So if we move the chart a little bit into the past, we can see these fan-like trading results. Here was the entry signal. We opened a buy trade, but the market went against us. And that is when we need to wait until it comes back. So how do we know if it comes back? Let’s zoom out and see what our two moving averages are doing. And here we can see on the long term With 1,000 candles for the green moving average and 1,100 candles for the red moving average, we have a long term uptrend. And that makes it likely that the uptrend is going to continue. Therefore, we expected the price to come back into the long-term trend because this would be a correction. And in most of the times, this will work. So let’s zoom out even more. And you see all the time, starting from the beginning of August until today, which is September the 27th, we had a long-term uptrend and we made a lot of trades, and that led to a lot of small profits.
In this case, we are about 6.8% profitable. Actually, let’s have a look at the FX Blue stats for the system. It says 6.6%. This is in German because my operating system is in German, but you could Check out all the stats in the language that you prefer. And when we click on the risk tab here, we see we have about 1.7% each month. The current probability of a total loss is zero. And we have also seen bad days and bad weeks. And you could analyze each and every trade here. By the way, you don’t have to log in. But let’s say it is 6.6% for 116 days, and more than half of it was just the adjustment time to get the system up and running and change a few parameters until we started off in August. So let’s say this is a third of a year. We have 6.6%, so three times this value would be roughly 20%, which is also my yearly goal. And guess what the the S&P average return is? According to Investopedia, the average return currently is about 10.26% since 1957! And now that we know that, what do you think is the average return for Warren Buffett, the greatest investor in the world, as some people call him?
Well, according to Google, it’s about 10 %. And as we all know, Google knows everything. But if you look at his company, which is Berkshire Hathaway, this is about three times the return value. And if we go a little bit down, we see that Berkshire Hathaway has consistently outperformed the S&P 500 since 1965. So some people might find about 18 to 20% gain per year totally boring. But I’m risk averse and I consider trading to be one thing that I do. My goal is not to live from this little account. It’s more about a combination of things that I use, and trading is just one part of that combination. And I like simple and consistent, like in this case. But what I could do is I could increase the trading risk here to a much higher value. But there is a reason for my values here. And we can see the reason here. This is a backtest result. This is the COVID-19 time, and this is today. I started in 2015, traded up until the current day, which isn’t October the 15th because we are in late September. This is actually five minutes. That’s a time frame that a lot of people would consider to be pure noise.
Actually, I prefer to trade the one hour time frame. But I like consistent and slow growth with as little risk as possible, because most of the time it looks like this. And this is easy to watch without the urge to manipulate the system. This COVID spike here was very hard in a lot of ways for all of us. And by the way, in this case, I used a $10,000 account and it did 3,411 trades. So that is what I consider to be a good result. And that’s how I like my systems to behave. So if 6.8% is not enough for you and you want to double or triple your money every month, I would suggest to stop trading, because once you see a big drawdown, most likely you will want to close everything and get rid of the account. And that’s how most people lose all their trading capital within the first six months. Okay, I hope that was helpful for you and you understand how I do it. You can do it too if you want. You can also check out the stats. Just look for the FX Blue link that I will publish with the video.
For now, I say thank you for watching and I will see you in the next video.
The post MQL5 TUTORIAL – Simple Scales Fancy Fails ( Simple Robot Trading Strategy Revealed) appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor that uses Envelopes to generate trading signals. Let’s see how we can do that. We start by opening MetaEditor, which can be done by clicking the little icon or pressing F4. First, we define the OnTick function, which is called every time a new tick is received for the symbol. Inside this function, we create an array named Price Information to store price data. We then sort this array from the current candle to the oldest candle using the Array Set As Series function. Next, we copy the price data into the Price Information array using the Copy Rates function. The parameters for this function are the symbol, the period, the starting position (0 for the current candle), the number of bars to copy, and the array to store the data. We then create two arrays, Upper Band Array and Lower Band Array, to store the values of the upper and lower bands of the Envelopes indicator. These arrays are also sorted from the current candle downwards using the Array Set As Series function. We define the Envelopes indicator using the iEnvelopes function. The parameters for this function are the symbol, the period, the number of periods for the moving average (14), the shift value (0), the type of moving average (MODE_SMA), the applied price (PRICE_CLOSE), and the deviation (0.100).
We then copy the upper and lower band values into the respective arrays using the Copy Buffer function. The parameters for this function are the handle of the indicator, the buffer number (0 for the upper band and 1 for the lower band), the starting position (0 for the current candle), the number of values to copy (3), and the array to store the data. Next, we calculate the values of the upper and lower bands for the current candle using the Normalize Double function, which rounds the values to six decimal places. We then generate trading signals based on the closing price of the previous candle. If the closing price is above the upper band, we display an “UPPER SIGNAL” comment on the chart. If the closing price is below the lower band, we display a “LOWER SIGNAL” comment on the chart. If the closing price is between the upper and lower bands, we display the values of the upper and lower bands.
Finally, we compile the code by pressing F7. If this was too fast for you or if you don’t understand what all the code is doing, you may want to check out the Premium course on our website, or watch one of the basic videos first. If the compilation is successful, we go back to MetaTrader by pressing F4 or clicking on the icon. Back in MetaTrader, we press Control and R to start the strategy tester, pick the Expert Advisor that we have just created, enable the visual mode, and start a strategy test. We should then see the Expert Advisor on the chart. If you are already a Premium course member and have an idea for a video like this one, you can send us an email. In this video, we have learned how to create an Expert Advisor that uses Envelopes to generate trading signals with a few lines of MQL code. Thanks for watching, and I will see you in the next video.
The post MQL5 TUTORIAL – Envelopes Indicator explained (in 4 min) appeared first on MQL5 Tutorial.
If I were to tell you that you can improve your trading results by just clicking a few hundred times on your mouse button, would you do it? You might say yes, but still, most people don’t do this, and I don’t get it. So in this video, we are going to talk about what I think is the most important thing that you need to do to improve your trading results. In this video, I would like to talk about something that people don’t because they think that they can save time or they think they would waste time if they would actually do it. You see this line here? This is a current backtest. It’s running for 32 minutes. It’s one of hundreds of back tests I do, and I’ve been doing this since 2014. So you can imagine this is a lot of time, and I have done a lot of back tests. And people usually think that trading doesn’t work because of their own results. And they might do five back tests or 21 back tests or 37 backtests. And at some point in time, they see that it doesn’t work because they have a big drawdown, like this one, but in much bigger.
And that’s when they convince themselves that it doesn’t work. And that’s when they stop. Well, in this case, I’ve been doing this backtest since 2014 until 2024. It’s still running, and it was never dangerous because we have never seen a big drawdown. And now the same people will say, yes, but you only have 30% profit. This should be much better. And that’s exactly the problem. So this backtest has been done with $10,000, and we are around the $3,300 profit mark. So let’s see if I can reach my other client that is running locally. It doesn’t work right now, so I have to copy and paste the screenshot from my other computer. So let’s resize this and you will see this is September the 12th, 2024. It’s about 10 minutes past 7:00. And this spec test made $4,083 with a $1,000 account. And let’s show the date on the current one here. This is also the same time, and it is the same day, first day, September the 12th. And we have made, let me see, 3,120 dollars. I’m using these settings here. This is the Robot Trading System, the last iteration from September the ninth.
And I have several of these just from this year. So I’m doing exactly this all the time to make it better. And I’m only doing Euro, US, Dollar. And if you look at the data here, the profit factor is over two. In this case, the total drawdown was $422, and the profit was about eight and a half times that value. And if you like to see results like this one or this one with a much smaller account, you just need to repeat the backtesting process and let your computer do this over and over and over again. And after a few hundred backtests, you have an idea to change something. And then you click on the Modify menu item here and just change one thing. And then you come back to your system and do a few hundred more back tests. The account number here is 37132419. So let’s Let’s try this URL here. Here are the trading results. This is how the current system looks like, in my case, in German, because I’m from Germany. But you could see everything and analyze everything in your language. You can pick one of the reports here, analyze each and every trade, just do a few hundred back tests.
And guess what? The more often you do this, the your system gets. But nobody is willing to do that. And this is one of the most common problems. And most people who have this problem and don’t do hundreds of back tests also think that a send account or a demo account would be a waste of time. And they also think that their own stop loss is actually going to save them money. So if you believe in these things, just Just do a few hundred back tests for at least one year, or in my case, this is for 10 years. And once you have something in place that looks like this, there is always enough time to improve it. So that’s it for this video. Thank you for watching, and I will see you in the next one. Okay, I hope I have convinced you to do back tests, a lot of back tests. Over and over and over again until you don’t like to see anything like that anymore, because that is the most important lever that you have to improve your own trading results. That’s it for this video. If this was too fast for you or if you have no idea how to do all this, maybe the premium course on our website might be interesting for you.
For now, I say thank you for watching, and I will see you in the next video.
The post MQL5 TUTORIAL – One simple thing to improve trading results (I don’t get why people don’t do this!) appeared first on MQL5 Tutorial.
Today we wanted to record a video to show that some things are not just fantasies, but actually work. However, there are a few things to think about when you see the results here. First of all, it is safe to say that we would have failed right at the beginning if we had started with only 500 dollars in this system instead of 1000. This means that basic capitalization plays a major role. The second point is that we see an outcome that is only one of many possible outcomes that could have occurred. If you don’t optimize a system and just rely on the fact that it worked yesterday and last week, you can get nasty surprises. The only way to get better results in the long run is to run many hundreds of tests, which can sometimes take a long time. Even this test here is not done in a minute or two, even though the PC it is running on is extensively equipped with hardware and graphics card. Such tests are very resource-hungry and can take a long time. We now have a situation that we want to take a closer look at: What if we could put this result into practice? This would mean that we would not only have doubled or tripled our capital within ten years, but multiplied it by a maximum. That would be one way of being able to trade profitably in the long term, provided you get the system stable enough. This means that the many hours spent on these tests are well invested. At the same time, it means that you have to take the time to test for years. In my case, we have been testing this for ten years now and will probably continue to do so for the next ten years. It’s about long-term testing and achieving long-term results with as little risk as possible. But what looks like a small weakness in the system here and there can lead to people reacting strongly emotionally in practice. These dips may not look particularly impressive, but when you see a system suddenly drop from 30,000 to 20,000, it has a different effect than when you see it on the chart in a few seconds. Real money is always a problem, no matter how much you have. You want to keep as much of it as possible and lose as little as possible. The main problem with us humans is that every dollar we lose is twice as bad emotionally as every dollar we gain would be positive. Consequently, we will always try to avoid losses and react more strongly to losses than we do to profits. This is exactly what plays into the broker’s pocket, because he makes the most money from the negative emotions of traders. Not only does he make money on every position, whether we lose or win, but he also makes money by making us so scared at one or more points that we close our account. In this system, there is a drop from 34,000 to about 20,000 dollars. The biggest problem, however, is that we keep going until the system stops working or we have driven our account into the wall. To avoid this, it makes sense to use an equity stop that is as close as possible to the current gross balance. This is easy to program and in practice results in fewer losses. Many people want even better results when they are doing well and become careless and greedy as a result. As soon as this happens and you no longer adhere to your own rules, you no longer have a system because you manipulate it and the results get worse as a result. It’s a bit like making a fire: There are people who poke around in the coals until the barbecue goes out completely. To avoid such results and ensure positive experiences and profits for the future, you have to take the time to carry out many tests until you have a stable system. In fact, we are taking a risk here that is far higher than what we would take in normal operations. Such results can only be achieved with an unreasonably high level of risk. However, as this has now worked for over ten years and you don’t take a risk that could threaten the existence of an account with a few hundred euros, it makes sense to test such a high-risk system in real operation with these settings. We will therefore deviate from our usual approach and see whether we can achieve similar success with the settings used. Our system should now be slowly coming to an end. We have now arrived in 2023 and it is currently the month of June in 2024. You can often see in the last few meters that the biggest equity slump is still to come. In this case, you can see that we still have a lot of time left at the end of our test series, even though our equity curve is not moving at all. This indicates that we have to expect a massive slump. In the backtest, this can only last a few seconds, but in real trading it can take weeks or months for the profits made to disappear again. This is so emotionally stressful for many people that they tend to act irrationally and don’t wait until the end to see the result. This is also difficult for us, as we are used to listening to our own feelings. A computer doesn’t have this problem; it can follow whatever rules we give it.
The post MQL5 TUTORIAL – 8900 PERCENT PROFIT ? (Don’t do this at home!!!) appeared first on MQL5 Tutorial.
In this video, we are going to use artificial intelligence in Metaeditor to build a simple Candle Counter Expert Advisor. So let’s see how we can do that with MQL5. To do that, please open MetaTrader and click on the little button here or press F4 on your keyboard. That should open the Meta Editor window. And if you don’t see the Toolbar, please click on View, Toolbar. Now we want to click on File, New File, ExpertAdvisor from Template, Continue. I will call this file, Simple CandleCounter. Click on continue, continue, and Finish. Here we are. Now we can delete everything above the OnTick function, and I also delete the two comment lines here. So this is how we have done it so far, manually. But this time I would like to use this little icon here. This will send some text to a solution that is called Copilot. Basically, Copilot is a coding AI that also can be used for other programming languages like Python.
And to use it, we first need to activate it. So you need to get an OpenAI API key. You can click on this link and you will be brought to the OpenAI website where you can create as many keys as you like. I I have already created my key. They also show you the monthly usage, and so far, the most expensive day was about $1. I’m using this API for AI programming with Python because I do AI coding for companies to create AI servers that will help them in their daily business. So if you have a business, that might be interesting for you. And once you get your key, you can paste it here. For this simple example, we are going to use GPT 3.5 turbo. You could also use a GPT 4 model. Those are better, but also a lot more expensive. The maximum tokens amount here is basically a restriction on about how much you are going to allow to spend. A thousand tokens is about 750 words. And this variability slider here is set to 20% because I don’t want my solution to be very creative. If you would like to have something about fairy tales and unicorns, you could increase this value here. Now, basically, what this thing does is it sends whatever you say to the artificial intelligence. And this one is trying to make suggestions. So let’s see if it works in our case. Create a function that calculates and returns the number of candles on the chart. I can now mark this line of text, click on the button here, and it should be sended to Copilot, which actually worked this time. In the German video, we had several timeouts, and I had to restart MetaTrader all over again. In case you click on the button and nothing happens, you can click on View, Toolbox, and check out the journal here. Here is the error that we had, and this time we spend a few cents for 74 tokens. So now we have our function. Let’s try to create an output. I say: use the comment function to output the result for the get number of candles function. Let’s mark that and send it over to copilot. And here is the result. And you might notice that we said we want to use the comment function, but it returned the print function. So let’s try on the screen, remove the output, and mark this and try it again. And still, it uses the print function instead of the comment function. So for now, I’m going to change that manually. These are all comment lines, so let’s click on Edit, Advanced, and you can uncomment a few lines by clicking on this menu item or by pressing Control and the plus. Let’s change that to comment. And remove the empty lines. Once you’re done, you can click on the Compile button. So what’s happening now? Okay, this should be a comment line that is correct. And this time, the compilation was successful. Actually, in the German version, it forgot that we have to pass two parameters here because when you click on the ibas function and press F1, you will see that we have to pass the symbol and the time frame, which would be period in my case. So let’s recompile the code. And if you don’t get any errors, you can click on the little button here or press F4 to go back to MetaTrader. This It was a very simple example. And if you have no idea what all the code here does, maybe the premium course on our website might be interesting for you. For now, let’s go back to MetaTrader. Click on View, Strategy Tester, or press Control and R. Pick the simple candle counter that we have created. Mark the visual mode here and start your test. And yes, indeed, we get the number of candles. It is counting, and we see it on the life chart in the strategy tester. So our little expert advisor works. This was a very simple example, and you might notice that from time to time, you get code that is not working right away, like we have seen with the comment statement and the print function. So for now, I consider AI to be helpful but not perfect. But that might change in the near future when we get better models.
The post MQL5 TUTORIAL – COPILOT AI PROGRAMMING (WITH SOME ISSUES) appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor that places a Buy Limit order when there are no open orders or positions.Let’s see how we can do that. We start Metaeditor by clicking the little icon or pressing F4. We include the Trade mqh library by using the directive #include Trade\Trade.mqh, which provides trading functions. We create an instance of the CTrade class named trade. The On Tick function is called every time a new tick is received for the symbol. We get the ask price using Symbol Info Double with the SYMBOL ASK parameter and normalize it to the number of digits for the symbol using Normalize Double. We check if there are no open orders and no open positions by using Orders Total and Positions Total functions. If there are no open orders and no open positions, we place a Buy Limit order using the trade Buy Limit function.
The parameters for trade Buy Limit are: 0.10 for the lot size, Ask minus 200 points for the price of the Buy Limit order, Symbol to get the symbol, 0 for the Stop Loss, Ask plus 200 points for the Take Profit, ORDER TIME GTC for the expiration date, 0 for the expiration time, NULL for the comment.
We press F7 to compile the code.If this was too fast for you or if you don’t understand what all the code is doing, you may want to check out the Premium course on our website, or watch one of the basic videos first. If the compilation works, we go back to MetaTrader by pressing F4 or clicking on the icon. Back in MetaTrader, we press Control and R to start the strategy tester, pick the Expert Advisor that we have just created, enable the visual mode, and start a strategy test. We should see the Expert Advisor on the chart. If you are already a Premium course member and have an idea for a video like this one, you can send us an email. We have learned how to create an Expert Advisor that places a Buy Limit order with a few lines of MQL code. Thanks for watching and I will see you in the next video.
The post MQL5 TUTORIAL – SIMPLE BUY LIMIT EXPLAINED (in 3 minutes) appeared first on MQL5 Tutorial.
In this video, we are going to create a simple ExpertAdvisor that is going to open a sell trade whenever the last candle was bearish and when we have no open positions.Let’s see how we can do that with MetaTrader5. With MQL5 for MetaTrader 5, we can create an Expert Advisor that will execute trades based on certain market conditions. In this video, we want to create an Expert Advisor that will sell when the last complete Candle is bearish and there are no open positions. Let’s see how we can do that. Opening Meta Editor and Creating a New File. Please click on the little button here or press F4 in Meta Trader. Now you should see the meta editor window. Here, we need to include the necessary MQL5 header file for trading operations, trade.mqh, and create an instance of the Ctrade class, which will allow us to execute trades. Defining the market data. In the onTick function, which is called every time the market data is updated, we first get the current bid price for the symbol using the symbol info double function and normalize it to the correct number of decimal places using normalized double.
Next, we create an array called price info to store the price data for the last three candles.We then use the the array set as series function to sort the array in reverse order so that the most recent candle is at index zero. We fill the price info array with the actual price data using the copy rates function. We start from the current candle zero and copy the data for the last three candles. Checking the market condition. Now we check if the last complete candle, candle one, is a bearish candle, meaning the closing price is lower than the opening price. Executing the trade. If we don’t have any open positions, as indicated by the positions total function returning zero, we will place a sell order using the trade.sell function. This function takes several parameters. 0.10. This is the volume or lot size for the trade, in this case, 0.10 lots. Null. This is the symbol which is set to the current symbol by default. Bid. This is the current bid price, which is the price we will use to enter the short position. Bid plus 300 to a point. This is the stop loss price, which is 300 points pips above the current bid price. Bid 150 a point. This is the take profit price, which is 150 points pips below the current bid price. Null. This is an optional comment for the trade. Compiling the code. Now we can press F7 to compile the code in Meta Editor, testing the Expert Advisor. If this was too fast for you or if you don’t understand what all the code is doing, you may want to check out the premium course on our website or watch one of the basic videos first.
Otherwise, let’s go back to Meta Trader by pressing F4 or clicking the icon.Then press CTRL+R to start the strategy tester. Select the ExpertAdvisor we just created, enable the visual mode, and start the test. You should now see the ExpertAdvisor on the chart. If you’re already a premium member and have an idea for a video like this, feel free to send us an email. We’ve just created a simple ExpertAdvisor that will sell when the last complete candle is bearish and there are no open positions, using a few lines of MQL code. Thanks for watching and I’ll see you in the next video. Okay, by now you should see the ExpertAdvisor doing its work on your chart. If everything went well, that is fine. If you have no idea what all the code does, maybe the premium course might be interesting for you. You can check it out on our website. For now, I say thank you for watching, and I will see you in the next video.
The post MQL5 TUTORIAL – SIMPLE SELL TRADE EXPLAINED (in 5 minutes) appeared first on MQL5 Tutorial.
In this video, we are going to create a simple ExpertAdvisor that is able to create a buy trade whenever the last candle was bullish! Let’s find out how we can do that with MQL5. With MQL5 for MetaTrader5, we can create an expert advisor that will execute trades based on certain market conditions. In this video, we want to create an expert advisor that will buy when the last complete candle is bullish and there are no open positions. Let’s see how we can do that. Opening Meta Editor and Creating a New File. Please click on the little button here or press F4 in Meta Trader. Now you should see the Meta Editor window. Here, we need to include the necessary MQL5 header file for trading operations, Trade\Trade. Mqh, and create an instance of the C Trade class which will allow us to execute trades. Defining the market data. In the onTick function, which is called every time the market data is updated, we first get the current ask price for the symbol using the symbol info double function and normalize it to the correct number of decimal places using normalized double.
Next, we create an array called price info to store the price data for the last three candles. We then use the array set at as series function to sort the array in reverse order so that the most recent candle is at index zero. We fill the price info array with the actual price data using the copy rates function. We start from the current candle zero and copy the data for the last three candles, checking the market condition. Now we check if the last complete candle, candle one, is a bullish candle, meaning the closing price is higher than the opening price. Executing the trade. If we don’t have any open positions as indicated by the position’s total function returning zero, we will place a buy order using the Trade Buy function. This function takes several parameters, 0.10. This is the volume or lot size for the trade. In this case, 0.10 lots. Null, this is the symbol which is set to the current symbol by default. Ask, this is the current ask price, which is the price we will use to enter the long position. Ask – 300 _POINT. This is the stop loss price, which is 300 pips below the current ask price. Ask plus 150 _POINT, This is the take profit price, which is 150 point pips above the current ask price. Null. This is an optional comment for the trade.
Compiling the code! Now we can press F7 to compile the code Meta Editor, testing the Expert Advisor. If this was too fast for you or if you don’t understand what all the code is doing, you may want to check out the premium course on our website or watch one of the basic videos first. Otherwise, let’s go back to Meta Trader by pressing F4 or clicking the icon. Then press CTRL+R to start the strategy tester. Select the Expert Advisor we just created, enable the visual mode, and start the test. You should now see the Expert Advisor on the chart. If you’re already a premium member and have an idea for a video like this, feel free to send us an email. We’ve just created a simple Expert Advisor that will buy when the last complete candle is bullish and there are no open positions, using a few lines of MQL code.
Thanks for watching, and I’ll see you in the next video. Okay, by now you should see the ExpertAdvisor running on your chart, if everything went well. I would like to say thank you for watching. And if you have an idea for a video like this one, and if you are already a premium customer, just drop me a line, otherwise maybe the premium course might be interesting for you. You can find that one on our website. Thank you for watching, and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
This red line here is a simple moving average!And in this video, we are going to create a simple expert advisor that is able to calculate the value for this moving average and show it on the chart. Let’s see how we can do that with MQL5. Introduction to calculating a simple moving average in MQL5. In this video, we want to calculate the value for a simple moving average and output the value on the chart. So let’s find out how to do that with MQL5. Opening Meta Editor and Creating a New File. Please click on the little button here or press F4 in Meta Trader. Now you should see the Meta Editor window, and here you want to click on File, New Expert Advisor, Template from Template, Continue. I will call this file, Simple Moving Average. Click on Continue, Continue and Finish.
Setting up the code structure!Now you can delete everything above the onTick function and the two comment lines that remain. Defining the moving average with IMA function. Let’s continue with the definition of the moving average. We use the integrated MQL5 function Ima, if you highlight it and press F1, you will see that it needs a few parameters. The first parameter is used to automatically find out what symbol is used on the chart. In my case, it’s the currency pair, Australian dollar against Yen. The second parameter contains the value of the time frame that is used on the current chart. I’m using the M1 chart for one minute candles right now. The third parameter is the number of candles that we are going to use to calculate the moving average. In our case, we use 20 candles, configuring Parameters for Moving Average Calculation. When you put your mouse over the moving average, you will see behind the moving average that stands for 20 candles. This parameter here is the starting point. We will start the calculation based on the current candle zero. We use Mode Underscore SMA to calculate a simple moving average, and we use price close in the last parameter because we want to calculate the moving average values based on the closing as price. Filling the moving average array with data.
Now we use copy buffer, fill our moving average array with data based on the moving average definition that we have created here. We start from Candle 0. We do it for Buffer 0. That’s the red line here, the only indicator line that we have for a moving average. The Bollinger Bands indicator, for example, would have three lines, so that would be Buffer 0, 1 or 2. We start with the current Candle 0, and we copy the price data for three candles and store it in our array. Calculating the moving average for a specific candle. To calculate the moving average for candle one, that’s the last complete candle that appears on the chart, we can use the value for candle one in our moving average array and store it in a variable called my Moving Average 20, outputting the moving average value on the chart. Finally, we want to use the comment function to create an output on the chart saying, My Moving Average 20, followed by the value that we have calculated.
Compiling the code and testing in MetaTrader!Now we can press F7 to compile the code in Metaeditor, and then we can test the ExpertAdvisor in MetaTrader using the strategy tester. Observing the moving average and output on the chart. If you have any trouble understanding the code or need more basic information, you can check out our premium course on our website or watch some of our beginner videos first. Otherwise, Let’s go back to MetaTrader by pressing F4 or clicking the icon, then press CTRL+R to start the strategy tester. Select the ExpertAdvisor we just created, enable the visual mode, and start the test. You should now see the ExpertAdvisor and the calculated simple moving average on the chart. If you’re already a premium member and have an idea for a video like this, feel free to send us an email. We’ve just created a simple moving average expert advisor using a few lines of MQL code. Thanks for watching, and I’ll see you in the next video. Okay, if everything went well, you should see the expert advisor on your chart now. If you have any trouble understanding all that stuff, maybe the premium course on our website might be interesting for you. For now, I say thank you for watching, and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
In this video, we are going to use artificial intelligence in Metaeditor to build a simple Candle Counter Expert Advisor!So let’s see how we can do that with MQL5. To do that, please open MetaTrader and click on the little button here or press F4 on your keyboard. That should open the Meta Editor window. And if you don’t see the Toolbar, please click on View, Toolbar. Now we want to click on File, New File, ExpertAdvisor from Template, Continue. I will call this file, Simple CandleCounter. Click on continue, continue, and Finish. Here we are. Now we can delete everything above the OnTick function, and I also delete the two comment lines here. So this is how we have done it so far, manually. But this time I would like to use this little icon here. This will send some text to a solution that is called Copilot. Basically, Copilot is a coding AI that also can be used for other programming languages like Python. And to use it, we first need to activate it.
So you need to get an OpenAI API key!You can click on this link and you will be brought to the OpenAI website where you can create as many keys as you like. I I have already created my key. They also show you the monthly usage, and so far, the most expensive day was about $1. I’m using this API for AI programming with Python because I do AI coding for companies to create AI servers that will help them in their daily business. So if you have a business, that might be interesting for you. And once you get your key, you can paste it here. For this simple example, we are going to use GPT 3.5 turbo. You could also use a GPT 4 model. Those are better, but also a lot more expensive. The maximum tokens amount here is basically a restriction on about how much you are going to allow to spend. A thousand tokens is about 750 words. And this variability slider here is set to 20% because I don’t want my solution to be very creative. If you would like to have something about fairy tales and unicorns, you could increase this value here. Now, basically, what this thing does is it sends whatever you say to the artificial intelligence. And this one is trying to make suggestions. So let’s see if it works in our case. Create a function that calculates and returns the number of candles on the chart. I can now mark this line of text, click on the button here, and it should be sended to Copilot, which actually worked this time. In the German video, we had several timeouts, and I had to restart MetaTrader all over again. In case you click on the button and nothing happens, you can click on View, Toolbox, and check out the journal here. Here is the error that we had, and this time we spend a few cents for 74 tokens.
So now we have our function. Let’s try to create an output!I say: use the comment function to output the result for the get number of candles function. Let’s mark that and send it over to copilot. And here is the result. And you might notice that we said we want to use the comment function, but it returned the print function. So let’s try on the screen, remove the output, and mark this and try it again. And still, it uses the print function instead of the comment function. So for now, I’m going to change that manually. These are all comment lines, so let’s click on Edit, Advanced, and you can uncomment a few lines by clicking on this menu item or by pressing Control and the plus. Let’s change that to comment. And remove the empty lines. Once you’re done, you can click on the Compile button. So what’s happening now? Okay, this should be a comment line that is correct. And this time, the compilation was successful. Actually, in the German version, it forgot that we have to pass two parameters here because when you click on the ibas function and press F1, you will see that we have to pass the symbol and the time frame, which would be period in my case. So let’s recompile the code. And if you don’t get any errors, you can click on the little button here or press F4 to go back to MetaTrader. This It was a very simple example. And if you have no idea what all the code here does, maybe the premium course on our website might be interesting for you.
For now, let’s go back to MetaTrader!Click on View, Strategy Tester, or press Control and R. Pick the simple candle counter that we have created. Mark the visual mode here and start your test. And yes, indeed, we get the number of candles. It is counting, and we see it on the life chart in the strategy tester. So our little expert advisor works. This was a very simple example, and you might notice that from time to time, you get code that is not working right away, like we have seen with the comment statement and the print function. So for now, I consider AI to be helpful but not perfect. But that might change in the near future when we get better models.
Not sure what to do? Click on the automated trading assistant below
In this video, we are going to create an Expert Advisor that uses the Average True Range Indicator.First, we’ll need to click on the little button here, which should bring up the MetaEditor. In the MetaEditor, we’ll want to select File, New, Expert Advisor from template, Continue, and we’ll call it Simple Average True Range.
Now, click Continue, Continue, finish, and we can remove everything above the OnTick function here, and I’ll also delete the two comment lines.
Let’s start by including the Trade.mqh file and creating an instance of the CTrade class.
In the OnTick function, we first create a variable called signal to hold our buy or sell signal.
Next, we calculate the current Ask and Bid prices using the SymbolInfoDouble function and the NormalizeDouble function to get the correct number of decimal places.
We then create an array called PriceArray to hold our price data, and define the Average True Range indicator using the iATR function.
We sort the PriceArray from the current candle downwards using the ArraySetAsSeries function, and then copy the buffer values from the indicator into the array using the CopyBuffer function.
Now we can calculate the current value of the Average True Range and store it in the AverageTrueRangeValue variable, using the NormalizeDouble function again to get 5 decimal places.
We also keep track of the previous value in the OldValue variable, and use that to determine our buy and sell signals. If the current value is greater than the old value, we set the signal to “buy”. If the current value is less than the old value, we set the signal to “sell”.
Finally, we check the PositionsTotal function to see if we have any open positions. If the signal is “sell” and we have no open positions, we use the Sell function of the CTrade class to sell 10 microlots. If the signal is “buy” and we have no open positions, we use the Buy function to buy 10 microlots.
We output the signal, old value, and current value to the chart using the Comment function.
Lastly, we update the OldValue variable with the current AverageTrueRangeValue.
Okay, that’s it.
Now, please click the Compile button, and you should get no errors and no warnings here.Now, you can click the button or hit the F4 key to go back to MetaTrader.
In MetaTrader, you want to click on View, Strategy Tester, and in the Strategy Test panel, you want to select the Simple_Average_True_Range.ex5 file. Select any currency pair you like, and please make sure to enable the check mark for the visualization option before you start your test.
And here we go! If you move your mouse to the current value here, you’ll see the calculated Average True Range value.
If this was too fast for you or if you don’t understand what all the code is doing, you may want to check out the Premium course on our website, or watch one of the basic videos first.
Okay, now you can create an Expert Advisor that uses the Average True Range Indicator to find out if you want to buy or if you want to sell, and you’ve created it in less than five minutes with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
Introduction to AMA Standalone Expert Advisor
In this tutorial, we are going to create an Expert Advisor in MQL5 that utilizes the Adaptive Moving Average (AMA) for generating trading signals. The AMA is particularly useful for capturing trends in the market due to its sensitivity to price movements. We’ll explore how to implement this indicator to determine buy and sell signals based on its interaction with the price.
Setting Up in MetaEditor
To begin, launch MetaEditor by clicking the little icon or pressing F4 on your keyboard. Once opened, navigate to: “File/New/Expert Advisor (template)” and name your file “SimpleAMAStandaloneEA”. Click “Continue” until you can finish and create the file. Initially, clear any pre-existing code above the OnTick function and remove the comment lines to prepare our workspace.
Including Essential Files and Initializing Variables
Start by including the Trade.mqh file, which provides functionalities necessary for trade operations. Create an instance of the CTrade class named trade, which we will use later for executing trades.
Copy Code
```
``` Calculating Ask and Bid Prices
Within the OnTick function, calculate the current Ask and Bid prices using SymbolInfoDouble. Normalize these prices using NormalizeDouble and _Digits to ensure they adhere to the precision required by the trading server.
Copy Code
double ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits); double bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits);
Setting Up Price Data Arrays
Define a price array using MqlRates and sort it with ArraySetAsSeries. Populate this array with price data using CopyRates.
Copy Code
MqlRates PriceArray[]; ArraySetAsSeries(PriceArray, true); CopyRates(_Symbol, _Period, 0, 3, PriceArray);
Implementing the AMA Indicator
Utilize the iAMA function to define the AMA based on its parameters. Fill an array with the AMA data using CopyBuffer.
Copy Code
int amaDefinition = iAMA(_Symbol, _Period, 10, 2, 0, PRICE_CLOSE); double EAArray[]; ArraySetAsSeries(EAArray, true); CopyBuffer(amaDefinition, 0, 0, 3, EAArray);
Calculating and Assigning Signals
Determine the current AMA value and compare it with the close price of the last candle to assign buy or sell signals.
Copy Code
double currentAMA = EAArray[0]; string signal = ""; if(currentAMA > PriceArray[1].close) { signal = "sell"; } else if(currentAMA < PriceArray[1].close) { signal = "buy"; }
Executing Trades Based on Signals
Execute trades based on the calculated signals, ensuring no existing positions conflict with the new signal.
Copy Code
if(signal == "sell" && PositionsTotal() == 0) { trade.Sell(0.1, _Symbol, bid, 0, 0, "AMA Sell"); } else if(signal == "buy" && PositionsTotal() == 0) { trade.Buy(0.1, _Symbol, ask, 0, 0, "AMA Buy"); }
Displaying Signal on Chart and Testing
Use the Comment function to display the current trading signal on the chart. Compile the code by pressing F7 and test the Expert Advisor in MetaTrader by pressing CTRL+R and selecting the “SimpleAMAStandaloneEA”.
Conclusion
By following this tutorial, you have created an Expert Advisor that trades based on the Adaptive Moving Average. This EA can help you understand how to implement and test trading strategies in MQL5. If you found the pace fast or need more detailed explanations, consider exploring our Premium course or reviewing basic videos first.
Thank you for following along, and I look forward to seeing you in the next tutorial where we continue exploring the capabilities of MQL5 for automated trading.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – Simple AMA STANDALONE WALKTRHOUGH appeared first on MQL5 Tutorial.
Today we want to talk about a system that is called OCO that is the short term for Order Cancels Order.
If you look on our chart we have a sell stop here and we have a buy stop there and here is where the price is and if the price moves to the sell stop that would trigger a short position.
And if the price rises and hits the buy stop we would have a long position. Now what’s the difference between an order and a position?
You use an order if you want to open a position so you can place your orders in the market and if the price moves and hits your pending order it will become a position.
You see that we have cancelled the other order now. It’s no longer here, so let’s find out how to create an Expert Advisor that can cancel pending orders.
To do that please click on the little button here or press the F4 key and once you have done that piece click on File, New, Expert Advisor from Template, Continue.
I will call it Simple Cancel Order, Continue, continue and finish and now you want to remove everything above the OnTick function and the two comment lines here.
And to have anything to close we first need to import the file trade mqh by using the include function.
We want to create an instance of the Class Ctrade and that will have the name trade.
In the first step we need to get the account balance that is done by using account info double, Account_Balance.
Now we need to get the equity by using account info double, Account_Equity and we also need the ask prize here we use symbol info Double_Symbol for the current chart and the constant Symbol_Ask.
We also use normalized Double_Digits because we have currency pairs with five digits and other currency pairs with three digits and now we do exactly the same to get the bid price, but this time we use Symbol_Bid.
Now if we have no open position and no order, so if positions total equals zero and if orders total also equals zero, we need to open a pending order for a buy stop and another one for the sell stop, the position size is ten micro lot.
In both cases the buy stop order will be placed one hundred points above the ask price and the sell stop order will be placed one hundred points below the bid price.
For the current symbol we have not defined a stop loss, the take profit is three hundred points above the ask price and two hundred, no let’s also use three hundred points below the bid price.
We use other time GTC that means the order will stay until we cancel it, so we have no expiration time here.
If we would use an expiration time we would use this parameter to define it and the last parameter here is for a comment but we don’t need that.
If we are trading right now – that would mean that the balance has different value than our equity.
We want to cancel the open orders so let’s create a function called cancel order.
It’s a void type because it doesn’t need to return any kind of value and here we use For Loop.
It starts by using orders total minus one and until the value for the counter is zero that means as long as we have open orders it will go through all the open orders.
We use order get ticket for the current order to find out the ticket number and it now will delete the pending orders by using Trade.OrderDelete for the order ticket that we have calculated here.
And the last thing we need to do is to close the For Loop and the cancel order function.
Now let’s compile the code by clicking the little button here or pressing the F7 and that did actually work without any errors.
So now please click here or press F4 to go back into Meta Trader. And in MetaTrader you want to click on View, Strategy Tester or press control and R, and here you want to select the Simple Cancel Order.ex5 file, select any currency pair and enable the visualisation mode.
After you have done that please start your test. And here you see two pending orders; one is a buy stop and another one is a sell stop so let’s zoom in and see how it works.
That’s a little bit slow so let’s speed it up here.
Now you can see the pending order is gone, we have an open position and every time the open position is closed, two new pending orders will be opened here and as soon as the first order is triggered the other one will be cancelled.
Okay now you know how you can create a very simplified version of the order cancel order Expert Advisor and you have coded it yourself with a few lines of MQL 5 code.
Download “MQL5 - Simple Order Cancel Order EA from MQL5 Tutorial”
SimpleCancelOrder.txt – Downloaded 441 times – 1.55 KBNot sure what to do? Click on the automated trading assistant below
The post MQL5 Tutorial – Simple Order Cancel Order EA appeared first on MQL5 Tutorial.
What you see here is an Expert Advisor that is opening buy stops and we have a calculated profit on the chart and it uses two self defined functions that we have compiled in a so called library.
You can think of a library as a file that contains self defined functions that you can use again and again.
Now how can we create such a library in MQL5?
To do that please click on the little button here in your Meta Trader and now you should see the MetaEditor and this is our main module and we use these import statements here to import the file MyLibrary.ex5 and in that file we have a function called GetProfitCurrencyPair and another function called OpenBuyStop.
And in the OnTick function we check if we have no open orders and if that is the case we want to OpenBuyStop so we call the self defined function OpeBuyStop from our library.
And to calculate the profit we use the function GetProfitCurrencyPair and that’s also self defined in our library.
And to create your own library please click on File, New, Library, Continue, this one is called myLibrary and now you can click on Finish.
And the first thing we need is property library, without that you cannot compile the file and to be able to open the buy stops we need to import the trade functions from the built in trade.mqh file.
And to get the profit of the current currency pair we need to create our self defined function and this extension 2export” is used because only a function with such a modifier is accessible for our MQL 5 programs.
And in the function we declare a variable called ProfitThisCurrencyPair; it contains no value here and now we go through all the positions using this For Loop and we use PositionGetSymbol for the current counter and if the symbol on the chart equals the symbol of the currency pair from our position, we use PositionGetDouble, position_profit to calculate the position profit and position get double, position_swap to calculate the swap.
Just add the two values up to get the profit of the currency pair.
Let’s end the For Loop and we use normalize double and two digits to calculate the profit for the currency pair and format it for two digits behind the dot, and afterwards we use return to return the profit for the currency pair back to the main module.
Let’s add another function for the buy stop, it’s called OpenBuyStop and it also has the export extension and to open the buy stop we want to know the ask price, the balance and the equity.
You can get the ask price by using SymbolInfoDouble for the current symbol and you use symbol_ask and with NormalizeDouble and _Digits we make sure that we have three digits for this currency pair or five digits for other currency pairs and to get the balance of the equity we use AccountInfoDouble, Account_Balance or AccountInfoDouble, Account_Equity.
And if equity and balance are equal, we want to open a buy stop by using trade.buystop for 10 micro lots.
The buy stop will be one hundred points above the ask price of the current symbol.
We haven’t defined a stop loss, the take profit will be three hundred points above the ask price and we use Order_Time GTC because that is good until the order is cancelled so it will not expire and because of that we use a zero for the date/time and the last parameter would be for the comment, we don’t need that so we also use zero here.
Let’s add the last bracket to close the function and press this little button or F7 on your keyboard to compile your library.
I made a mistake here, of course I need to create an instance of Ctrade now that’s done and I recompile and this time it worked without any errors.
So let’s click on the button here our press F4 to go back to MetaTrader.
And in MetaTrader you want to click on View, Strategy Tester or press control and R, and in the Strategy Tester please select the file simpleLibraryMainModule.ex5 and please remember that you also have to compile the main module each time you create a library or you change a library.
Now let’s click on start and here we go.
I will speed up the process a little bit and now you know how to create an Expert Advisor that is able to import your self-written library and you have created it with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 Tutorial – Advanced Library Expert Advisor appeared first on MQL5 Tutorial.
In this video, we will be creating an Expert Advisor that calculates the elapsed time since the start of the Expert Advisor in hours, minutes, and seconds, and displays it on the chart. To begin, please click on the small button at the top in MetaTrader 5 or press the F4 key to open the MetaEditor. Code Description: At the start of the code, we declare several date and time variables: CurrentTime: This variable stores the current time. StartTime: This variable stores the start time when the Expert Advisor was initiated. PassedTime: This variable will store the elapsed time. Within the OnTick function, which gets called on every market tick: We check if the StartTime variable has not been assigned a value. If it hasn’t: We assign it the current local time using TimeLocal(). The TimeLocal() function returns the current time of the computer where the client terminal is running. We then calculate the current time and the elapsed time by subtracting the start time from the current time. A structure variable of type MqlDateTime named DateTimeStructure is declared. This structure stores information about date and time. We use the TimeToStruct function to convert the elapsed time (PassedTime) into the MqlDateTime structure. This structure will allow us to extract hours, minutes, and seconds. From this structure, we extract: PassedTimeInHours: The hours since the Expert Advisor started. PassedTimeInMinutes: The minutes since the start. PassedTimeInSeconds: The seconds since the start. Finally, we use the Comment function to display various time-related information on the chart: The start time. The current time. The elapsed time in hours, minutes, and seconds. Code Execution: Upon running the Expert Advisor, it will display the elapsed time since the start of the Expert Advisor on the chart in real-time. You’ll observe the seconds, minutes, and potentially hours ticking up. In conclusion, in this video, you’ve learned how to calculate the elapsed time since the start of an Expert Advisor using just a few lines of MQL5 code. Thank you for watching, and see you in the next video!
Not sure what to do? Click on the automated trading assistant below
The post MQL5 Tutorial – Calculating Time Difference in Hours, Minutes, and Seconds appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor that uses the Parabolic SAR and Stochastic Oscillator indicators to generate buy and sell signals in MetaTrader. Let’s see how we can do that. First, start the MetaEditor. You can do this by clicking on its icon or simply pressing the F4 key. We begin with the #include directive to import the Trade.mqh library. This library provides us with essential trading functions. Following this, we create an instance of the CTrade class named trade. This instance will be our primary tool for executing buy and sell orders. Next, we calculate the current asking price using the Symbol Info Double function with the parameters Symbol and SYMBOL ASK. This gives us the price at which we can buy. To ensure precision, we use the Normalize Double function, inputting the price and Digits to adjust the number of decimal places. Similarly, we determine the bid price using the Symbol Info Double function with the parameters Symbol and SYMBOL BID. This is the price at which we can sell. This price is also normalized using the Normalize Double function. We then set up an array named Price Info of type Mql Rates. This array will store our price data for specific time periods on the chart. Within the On Tick function, we sort our Price Info array using the Array Set As Series function to prioritize the latest data. We then fill this array with price data for the current symbol and time frame using the Copy Rates function. Here, we’re copying data for three candles, giving us a snapshot of recent price movements. The closing price of the most recent candle is then determined using the Price Info[0].close reference. We then call the Check Entry function. Inside this function, we use the Parabolic SAR indicator to check the current and previous values to determine if there’s a buy or sell signal. If the current SAR value is below the current price and the previous SAR value was above the previous price, it suggests a buy signal. Conversely, if the current SAR value is above the current price and the previous SAR value was below the previous price, it suggests a sell signal. Additionally, the Check Entry Stochastic function is used to refine our signals. This function checks the Stochastic Oscillator values. If the K line crosses the D line from below in an oversold area, it suggests a buy signal. If the K line crosses the D line from above in an overbought area, it suggests a sell signal. With these signals in hand, the code decides whether to execute a buy or sell trade. If both the trading signal and the filter signal return a buy and there are no open positions, the trade.Buy function is used to buy 0.10, equivalent to 10 Micro Lot. If both signals return a sell, the trade.Sell function is used to sell 0.10 Microlot. Once you’ve input all the code, press F7 to compile it. If this was too fast for you or if you don’t understand what all the code is doing, you might want to check out the Premium course on our website or watch one of the basic videos first. After a successful compilation, return to MetaTrader by pressing the F4 key or clicking on its icon. Once in MetaTrader, press Control and R to start the strategy tester. Select the Expert Advisor you’ve just created, enable the visual mode, and start a strategy test. You should then see the Expert Advisor in action on the chart. If you’re already a Premium course member and have an idea for a video like this one, please send us an email. By the end, you’ll have a deeper understanding of what you’ve learned and the Expert Advisor you’ve coded yourself with just a few lines of MQL code. Thanks for watching, and I’ll see you in the next video!
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE SAR STOCHASTIC STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video we are going to create an Expert Advisor to calculate this Indicator; it’s the Variable Index Dynamic Average, whenever the red line is above the price that would be a sell signal and in the other case when the red line is below the candles – like here – that would be a buy signal. Now how can we create an Expert Advisor that is going to actually trade our signal and output our buy and sell signals directly on the chart? To do that please click on the little button here or press F4 on your keyboard and now you should see the Metaeditor window and here you want to click on: “File/ New/ Expert Advisor (template)” from template, I will call this file: “SimpleIVIDYAStandaloneEA”, click on “Continue”, “Continue” and “Finish”. Now we can remove everything that is above the “OnTick” function and let’s also delete the two comment lines here. We start by including the file: “Trade.mqh”. Sometimes people ask me where the file is? Well, it’s included in MQL5 and we can create an instance of the class: “CTrade” that will be called: “trade” and we are going to use it later on to open positions. Inside of the “OnTick” function we are going to calculate the Ask price and the Bid price. We get the prices by using “SymbolInfoDouble”, we use “SYMBOL_ASK” to calculate the Ask price and “SYMBOL_BID” to calculate the Bid price. With “NormalizeDouble” and “_Digits” we calculate the number of digits behind the dot. Let’s create a string variable that will be called: “signal” and we are going to calculate the signal value later on so we don’t assign a value right now. We also need to create a price array (PriceArray) that is done by using “MqlRates”, lets sort the array from the current candle downwards by using “ArraySetAsSeries” and with “CopyRates” we fill our array (PriceArray) with price data for the current symbol on the chart and the currently selected period, we are going to start from the current candle 0 (zero) and we need the price for 3 candles – that’s for the prices. Now we need to create an array for the Expert Advisor data that will be called: “EAArray”, let’s also sort that one by using “ArraySetAsSeries”. Now we actually can define the Expert Advisor by using the integrated “iVIDyA” function. If you mark that one and hit F1 you will see all the parameters for the Variable Index Dynamic Average Indicator, it has only one buffer and the parameters are: the current symbol on the chart, the currently selected period on the chart, here we have a 9, a 12 and a 0 (zero) – so let’s click on: “Insert/ Indicators/ Trend/ Variable Index Dynamic Average” and you will see that we have a “Period CMO:” that is 9, the “Period EMA:” that is 12 and the “Shift:” value of 0 (zero) and that’s exactly what we use here and the value will be calculated based on the close price (PRICE_CLOSE). So let’s use “CopyBuffer” to fill our array (EAArray) with data according to the IVIDYA definition (iVIDyADefinition) we have created here, it’s for only one buffer – the first buffer is buffer 0 (zero) – the current candle is also candle 0 (zero), we need data for 3 candles so we use a 3 here and save it in our “EAArray”. So far so good; to get the current value we just look into our “EAArray” and we need the value for the current candle – that’s candle 0 (zero) – now we can actually calculate the signal. Whenever the current iVIDyA value (iVIDyAVALUE) is bigger than the close price of the last candle in our price array (PriceArray) that would be a sell signal and that’s when we want to assign the word: “sell” to our signal. In the other case if the iVIDyA value (iVIDyAVALUE) is smaller than the price array 1 close price for candle 1 (PriceArray[1].close) that would be a buy signal and now we assign the word: ”buy” to our signal. Whenever our signal equals sell and “PositionsTotal” is less than 1 – with other words we don’t have any open position – we use “trade.Sell” to sell 10 micro lot. In the other case if the signal equals buy and we have no open positions we would use “trade.Buy” to buy 10 micro lot. In the last step we also create a chart output by using the “Comment” function, it would output the words: “The current signal is:” followed by the signal that we have calculated. Please don’t forget the closing bracket here and when you are done you can click on the “Compile” button here or press F7. That worked without any errors here so now we can click here or press F4 to go back to Metatrader. In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, here we select our new file: “SimpleIVIDYAStandaloneEA.ex5”, let’s enlarge this here, mark the visualization option and start a test. …and here is our first trade, our Expert Advisor is working, the signal line is below the candles here so we have a buy signal, it actually opened our first position and now you know how to create a standalone version for the Variable Index Dynamic Average Indicator that actually is going to trade automated and you have created it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE IVIDYA STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
The video begins with the creation of a Bollinger Bands standalone Expert Advisor that will trade the Bollinger Band signals. A sell trade has already been made, and the tutorial aims to explain how this can be done in MQL5 (0:00). The Metaeditor window is opened, and a new Expert Advisor is created from the template. This new Expert Advisor is named “SimpleBollingerBandsStandalone” (8:00). The tutorial then proceeds to delete everything above the “OnTick” function and removes the two command lines. The Trade.mqh file is included to create a “CTrade” instance called “trade”, which will be used later to open a position (14:00). An empty string called “entry” is created, and the Ask price and the Bid price are obtained using “SymbolInfoDouble” for the current symbol. The “NormalizeDouble” function in combination with “_Digits” is used to get the number of digits for the current symbol of the current chart (22:00). An array for the prices called “PriceInfo” is created in the “MqlRates” format. The price array is sorted from the current candidate downwards using “ArraySetAsSeries” (28:00). The “CopyRates” function is used to fill the “PriceInfo” array with price data for the current symbol and the currently selected period on the chart from the current candle 0 for 3 candles (35:00). Arrays for several prices for the upper and lower band of the Bollinger Bands are created. When the price breaks out and re-enters into the Bollinger Bands, it would be a signal. A buy signal occurs when it does it from below, and a sell signal occurs when it does it from above (39:00). The Bollinger Bands are defined by using the built-in “iBands” definition for the current symbol on the chart and the currently selected period. The period of 20 candles, a shift value of 0, and the deviation value of 2 are used, and the calculation is based on the close price (47:00). The “CopyBuffer” function is used to copy the “PriceInfo” into the Bollinger Bands definition array. Buffer 1 and buffer 2 are used to calculate the upper and the lower band from the current candle 0 for 3 candles (55:00). The Expert Advisor for the current candle is calculated, and the values for the upper and lower band are obtained. To calculate a crossover, the Expert Advisor for the candle before (candle 1) is also calculated (60:00). A check is made to see if there is a re-entry from below. This would be true if the close price for candle 0 is above the lower band value and if the close price for the candle before was below the last lower band value. In this case, a buy entry is made (66:00). A check is also made to see if there is a re-entry from above. This would happen if the current price is below the upper band value and if the price for candle 1 was above the last upper band value. In this case, a sell entry is made (72:00). If the entry equals sell and there are no open positions, a sell of 10 micro lot is made. If the entry equals buy and there are no open positions, a buy of 10 micro lot is made (77:00). The “Comment” function is used to output the words “Entry Signal” followed by the calculated entry directly on the chart (85:00). The tutorial ends with the compilation of the code and the return to Metatrader. The “SimpleBollingerBandsStandalone.ex5” file is selected in the Strategy Tester, and the visualization option is marked. The test is then started, and the Expert Advisor is shown at work (94:00). The video concludes with the explanation of how to automate the Bollinger Bands signal with MQL5 and create a simple standalone Expert Advisor that is actually going to trade with a few lines of MQL5 code (103:00).
Not sure what to do? Click on the automated trading assistant below
The post How to create a Bollinger Bands Expert Advisor appeared first on MQL5 Tutorial.
In the dynamic and exciting realm of trading, the MQL5 platform is akin to a high-speed train, bridging the gap between you and your financial goals. But it’s not just the speed and power of this trading platform that captivates traders. It’s the tools it provides to master the market and navigate through it like a seasoned captain, with the moving average serving as your reliable compass. The Magical Wand of the Moving Average The moving average is a widely recognized element in the toolbox of any trader. Considered to be the Swiss Army knife of trading, the moving average is a multitasking tool that can navigate through the ever-changing tides of the market. It’s like a gardener’s spade, able to dig deep into market data, analyze it, and plant the seeds of potential profits. Let’s understand the magic that this tool sprinkles on your trading strategies. A Simplicity That Stands Tall In a world buzzing with complex technical indicators, the simple moving average (SMA) on the MQL5 platform is a beacon of simplicity. It’s like a wise old grandpa, observing market prices over a specific time frame, and doling out wisdom through average values MQL5 TUTORIAL – Simple Moving Average – Do I need an SMA for my trading strategy?. Get Your Calculations Right with MQL5 Just as the conductor’s baton orchestrates the symphony, MQL5 smoothly calculates and displays the SMA value on the trading chart MQL5 TUTORIAL BASICS – 11 HOW TO CALCULATE A SIMPLE MOVING AVERAGE – MQL5 Tutorial. As seamless as a maestro composing a melody, MQL5 brings the moving averages into play, creating an enriching trading experience. Mastering the Market with Moving Averages Remember playing with Lego blocks as a kid? Building and reassembling them into different structures was part of the fun. This sense of adaptability and creativity also resides in the heart of MQL5’s moving averages. Adapting to the Rhythm of the Market Much like an accomplished jazz musician, MQL5’s Adaptive Moving Average (AMA) improvises and adapts to the rhythm of the market, generating fewer false signals than the simple moving average MQL5 TUTORIAL – ADVANCED ADAPTIVE MOVING AVERAGE – MQL5 Tutorial. Riding the Market Roller Coaster The Bollinger Bands indicator, with the Simple Moving Average at its core, makes navigating the markets an exhilarating ride, precise and full of excitement MQL5 TUTORIAL – Mastering the Bollinger Bands Indicator for Automated Forex Trading with MQL5 – MQL5 Tutorial. Spotting Trends with the Shifted EMA Using shifted exponential moving averages in MQL5 feels like adjusting the focus on a pair of binoculars to spot distant trends. Precise calculations enable it to spot buy or sell signals MQL5 TUTORIAL BASICS – 66 SIMPLE SHIFTED EMA – MQL5 Tutorial. Automated Trading: Powered by MQL5 In a world where automation is the new norm, MQL5 steps in to revolutionize trading, just like driverless cars are changing transportation. MQL5 Signals: The Automated Bees of Trading Imagine having a swarm of bees diligently working for you, collecting the nectar of profits. The MQL5 Signal for automated trading is just that – an efficient, precise, and tireless worker that simplifies trading Harness the Power of an MQL5 Signal for Automated Trading – MQL5 Tutorial. Expert Advisors: Navigators of Trading If the MQL5 Signal is the diligent worker, the Free Expert Advisor is the skilled navigator, guiding your trades through turbulent market conditions towards consistent profits Automated Trading with a Free Expert Advisor? – MQL5 Tutorial. A Toolbox of Robots at Your Service In the MQL5 world, the trading robots are your loyal knights, always ready to charge into the battlefield of the markets on your command. Riding Trends with the SMA Robot Using the SMA Robot in MQL5 feels like riding the waves of the market, identifying upward and downward trends to stay ahead of the game MQL5 Tutorial Classics – Simple Moving Average Robot with MQL5 – MQL5 Tutorial. AMA Robot: The Accurate Archer The Adaptive Moving Average (AMA) Robot is like an archer, taking aim with precision and releasing fewer false signals, for accurate and effective trading MQL5 Tutorial – Simple Adaptive Moving Average Robot – MQL5 Tutorial. The SMA Crossover Robot: A Confluence of Signals As an expert sailor navigates the confluence of two rivers, the SMA Crossover Robot proficiently handles the crossing of two exponential moving averages, creating profitable trading signals MQL5 Tutorial – Simple Moving Average Crossover Robot with MQL5 – MQL5 Tutorial. MQL5, with its powerful moving averages and automation tools, is a beacon of simplicity, adaptability, and accuracy. It’s a world where trading feels like a leisurely, effective ride towards your financial goals.
Not sure what to do? Click on the automated trading assistant below
The post The Empowering MQL5 Moving Average appeared first on MQL5 Tutorial.
https://elopage.com/s/crowdcompany/platinum-demo-system CLICK AND USE COUPON CODE “PLATINSYSTEMDEMO” FOR A DEMO COURSE & DEMO VERSION This video is about system testing. This is the new and improved system for the Platinum Group. We now have two signals here and also some other things have been changed. And in this video we’re going to take a look at how to test a system like this. To do that, first of all, we need to select the right expert advisor in MetaTrader. I have now selected here in the strategy tester the version from July the 14th. And that is already the first criterion. You should, when you create a new system, always create a new version for every change, even if it means a little more work. But then you always have the possibility to go back to the last working version if you ever made a mistake. This is today’s date, July the 20th, 2023. So I want to test for a full year. And here on the Inputs tab, I first set everything to the default values. If I now start the test here, then I see the strategy tester with the information on the chart. But we want to save some time. That’s why I’ll pause this here and we’ll do the test without the visual mode. This should be relatively quick in the optimized version. Here, you can already see how the progress is developing. The total test time is given here with about two minutes. And I will fast forward the video to the end of the test in a moment to show what the result is. So as you can see, the system survived. But of course we didn’t make a profit here. The reason is: The default settings are meant to make a system profitable in the long run over a long period of ten or more years. But that can be wrong for some years. And of course you can optimize such values, now. We start here by changing the values for the curve and for the position size and start the test again. Okay, the second strategy test is done. This already looks quite good. However, this could be much more profitable here. So in the next step, I go a little higher with these two values and start the test again. This also worked, but it is not yet profitable. Let’s set the position size to four times because the drawdowns here were not really high. And let’s see if we can optimize this. So this test is also done and this time we are at about 11.3% profit with a moderate risk. That’s about what I see as a realistic profit expectation. Of course, you can go much, much higher here now with these values, but that wouldn’t work for every year. In 2003, I started my testing. I could change this accordingly and that would then work with the default settings for 20 years. But I’m pretty sure these settings here would be too aggressive at some point in this long term test. So we can just test by doubling the values here again and see what happens. Okay, this strategy test is also over. And this time we would have made 45,000 profit. That would be 45% for a $100,000 account. And of course, on this chart here, it all looks totally easy and smooth. But the people who really take profit in trading are the people who can take drawdowns like this here without manipulating their own system. And that always works best when you don’t need the money. And I believe that the percentage of Platinum members who have the nerve to endure such drawdowns, and who also have the money to go through such developments here is above average. And if you are already a Platinum member, then you can use the new version from the Platinum system as an optional update in the next few weeks. I myself don’t like forced updates. That’s why there is always the possibility to continue using the previously approved version. I will use the next few days to do some more extensive testing to make sure that the system does not ship with serious bugs. Nevertheless, it’s safe to say that this is still a version in beta status. If you click on the chart above, you can see how many tests I do every day. And the basic idea is to make such a system more and more stable. And there’s really nothing better for that than a large number of realistic tests. I think that’s it for this video. This test should also be finished in a few seconds. I’m quite happy with the result, because this time we would have made $55,000 profit with a $100,000 account. That was it so far. I say thanks for watching – and see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – HOW TO OPTIMIZE YOUR RESULTS appeared first on MQL5 Tutorial.
This time we are talking about the ITEMA Indicator. This is for the Triple Exponential Moving Average Indicator. You see this red line here. If we pass the strategy test and hover over the red line you will see that it is called the Triple Exponential Moving Average and its calculated based on 14 candles. In this video we are going to find out how to create an Expert Advisor to calculate a Triple Exponential Moving Average Indicator and how to improve the frequency of the signals that are created. To do that please click the little button here in your Metatrader or press F4 on your keyboard and now you should see the Metaeditor window and here you want to click on “File -New -Expert Advisor” from template (template), Continue (Next). I will call this one: “Simple ITEMA” (SimpleITEMA). Click on continue, continue and finish. Now everything above the “OnTick” function can be removed, let’s also delete the two comment lines. First we need to create an array for the prices, that’s done by using “MqlRates” and the array will be called: “PriceArray”. We use the MQL5 built-in function “ArraySetAsSeries” to sort the price array from the current candle downwards and with “CopyRates” we fill the array for 3 candles. That’s enough to calculate the current candle and calculate crossovers. “CopyRates” takes a few parameters, first one is the symbol parameter – that’s for the current currency pair on the chart – the second one is for the currently selected period on the chart. We start with candle zero; that’s the current candle, copy the data for 3 candles and store it in the price array. In the next step we to create another array for the Expert Advisor data, that will be called “EAArray” and the Expert Advisor array also need to be sorted by using “ArraySetAsSeries”. Now it’s time to actually define the ITEMA Expert Advisor. That is done by using the built-in function: “iTEMA”, it takes a few parameters: the first one once again is the currency pair on the chart, the second one is once again the selected period on the chart, these are 14 candles because if you click on “Insert -Indicators -Trend -Triple Exponential Moving Average” you will see that the default value for the built-in indicator also is 14 candles. We use a shift value of 0 here and it applies to the close price, so that’s what we are using here: shift value 0 and “PRICE_CLOSE “. Now that we have created the definition we use “CopyBuffer” for the ITEMA definition (iTEMADefinition) we have created here. The 0 is for the first buffer, this 0 stands for the current candle, the 3 is to copy 3 candles and we want to save it in the array called: “EAArray”. Now that we have done that we calculate the ITEMA value (ITEMAVALUE) for the current candle 0 in our array. I use float, usually it’s a double and if you press F1 you will see that a double variable is 8 bytes in size, a float variable only takes half of the size and it’s better to read for us humans. So, let’s create a chart output depending on the direction. If the ITEMA value is bigger than the close price of the first candle in the price array – remember the first candle is always this one, this is candle zero, candle one, candle two and so on – so, if this expression is true we use the “Comment” function to output the text: “iTEMA IS SHORT”, followed by the calculated ITEMA value. In the other case if the close price for candle one in our price array is above the ITEMA value we will output: “iTEMA IS LONG”, also followed by the value. Okay, that’s it. When you are done you can click on the compile button here, we get a warning that says that we have a possible loss of data due to type conversion, that’s because I used a float variable here but for this little Expert Advisor that is okay. So, if the compilation works without any errors you can click the little button here or press F4 to go back to Metatrader. In Metatrader please click on “View -Strategy Tester” or press CTRL and R and now you should select the file: SimpleITEMA.ex5, mark the visualization option here and start a test. This is how our Expert Advisor looks like, you see it saying: “iTEMA IS SHORT “or “iTEMA IS LONG”. The frequency of the signals is much too high, so let’s fix that! We go back into the Metaeditor and change the shift value for the candles to 100 candles. Let’s recompile the code, press F4, stop the current test and start a new one! This is how it looks like, just press the minus key a few times and now you see that the indicator is calculated 100 candles before the price and whenever the price is crossing here we will get another signal. Let’s speed that up a little bit, now we are getting much fewer signals but the signal quality is better! Okay. That’s it! Now you know how to create an Expert Advisor for a Simple Triple Exponential Moving Average Indicator and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE ITEMA EXPERT ADVISOR appeared first on MQL5 Tutorial.
This week I’ve gotten a few requests: how we can use external signals to create buy or sell signals in Metatrader. Right now, our buy signal is “Don’t Buy It Now”, and we have no open positions. And this is a simple text file. It is located in the user’s path in Windows. So that path here might be a little bit different, depending on your name and your operating system, but it should be below MetaQuotes, terminal, common files. Right now, it contains the sentence, “Don’t buy it now”. So let’s see what happens if I remove the Don’t and save the file. Immediately, a new Buy trade appears. So now we have opened a new position by using an external text file. And in this little video, we are going to find out how to do that. In your MetaTrader, please click on the little button here or press the F4 key. And in Metatrader, you want to click on File, New, Expert Advisor from Template, Continue. I will call it simple external signal and finish. And now you can remove everything above the on tick function and the two comment lines here. And to open a trade, the first thing we need is to import the trade.MQH file by using the include function. And now we want to create an instance that will have the name trade. And inside the ontick function, the first thing we do is to get the ask price by using symbol info double for the current symbol. We use the constant symbol underline ask because we need the ask price. And with normalize double and underline digits, we make sure that we have the right number of digits behind the dot, because there are some currency pairs that have only three digits and others have five. Let’s tell MQL5 actually which file we are going to use. Remember, this is the path where my files are located. In your case, it might be a little bit different, depending on your operating system and your name. This is the File handle, it’s an integer value and we use FileOpen for the file with the name signal.txt. We use File_Read, because we only want to read what’s in the file. File_ANSI means it’s a file that is containing strings of ANSI type. Ansi is only using one byte. You could, for example, also use File_Unicode. That would be used for two byte symbols. So if you see any weird characters on your screen, the reason might be the wrong encoding here. And File_Common is used for the file path in the common folder of all client terminals. It ends with terminal, common files, like in this case. This pipe character here is used as a delimiter that is used to separate the different items in a txt file or in a comma separated file. And CP_ACP means we are currently using the current Windows ANSI code page. Now that our file is defined, we use File, Read String for the external file we have created here to read out a buy signal. It will be a text string. And afterwards, we close the file. That is done by using the command File Close for our external file. And if no open positions exist and a buy signal occurs, that would mean positions total equals zero and the text in our file is “Buy it Now”. Well, in that case, we want to open a buy position by using trade.buy for 10 micro lots on the current chart for the current Ask Price. We have no stop loss defined. Our take profit is 100 points above the current Ask Price and we don’t need a comment here, so we use null for the last parameter. The last step is to create a chart output by using the comment function. It will show us the current buy signal that is the text that is contained in our file, followed by the text positions total and the value we have calculated for positions total. And if everything is okay, please click on the compile button. And if you don’t have any errors or any warnings, click on a little button here or press F4 to go back to Metatrader. Now in Metatrader, please click on View, Strategy Tester, or press CTRL and R. And here you need to select the file simple external signals.ex5, enable the visualization and start the test. Now our little expert advisor is running and you see the buy signal right now is: don’t buy it now. The number of open positions is zero. So let’s change the text file here. click on File, Save. And immediately a new trade is opened here. And if you speed up the process, you will see that new trades are opened and closed. But if the external condition is no longer true, or if I change the file content manually and save it, the buy signal will change to stop buying or whatever is in the text file. Let’s save that again. Now it says, Buy signal is stop buying or whatever is in the text file. Okay, Now you know how you can create an Expert Advisor that can read external Txt files. Actually, you could also use Excel files or whatever to use external signals. And you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 Tutorial – Simple External Signals In A File appeared first on MQL5 Tutorial.
Trading can often feel like a high stakes game where the challenge lies not only in making profits, but also in managing the inherent risks and inevitable lows. That is also true for the robot trading system, a trading tool that is reshaping traditional approaches by emphasizing resilience as much as reward. About a week ago, I set out on a new journey with this live trading system. As with all things new, the onset wasn’t particularly smooth. I found myself in what traders often dread, a drawdown situation. This scenario occurred despite the fact that I had chosen what is a proven strategy, opening a sell position during a downtrend. The unpredictability of the market, however, took its course and I ended up facing the opposite direction of the intended profit. As a result, for an entire week, my trading account saw no influx of profits. For many, a week without profits might signal an ineffective system. But I beg to differ. While it’s true that the first week didn’t bring any financial gain, the noteworthy detail lies in the absence of losses. It’s crucial to mention here that the robot trading system I was using is designed specifically to handle such draw downs. The system deploys an intelligent algorithm that efficiently hedges positions, thereby maintaining a balance even when the market doesn’t move in the predicted direction. This might seem like a small win, but when you’re trading, especially in a volatile market, avoiding losses can be just as important, if not more, than making significant profits. On the closing date of June 23rd, my account, despite the week’s market turbulence, stood at a net gain of a single dollar. This may not seem like a significant achievement on the surface, but when considering the context, it’s evidence of the system’s effectiveness in safeguarding against potential losses. For those intrigued by the system’s ability to mitigate losses during unpredictable market conditions, the robot trading system offers a demo account for you to test. This thing provides a risk free opportunity to understand the system’s operations and explore its unique features. The system’s emphasis on resilience and risk mitigation might be a refreshing change from traditional systems that primarily focus on profit generation. In the world of trading, where the tides can turn swiftly and unexpectedly, it’s a comfort to have a tool that can withstand the push and pull of the market trends. The robot trading system does precisely this by striking a balance between risk and reward. It may not always provide an instant profit, but it offers a buffer against potential losses during turbulent market phases, thus providing a safer trading experience. With its unique emphasis on resilience and a strategic approach to risk management, it stands apart from other trading systems. For anyone seeking a reliable stress tested system that can withstand the unpredictability of the markets, the robot trading system is definitely worth considering. The link is below and as always, thank you for watching and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – HOW TO STILL BENEFIT WHEN THE PRICE RUNS AGAINST YOU appeared first on MQL5 Tutorial.
This video, I would like to show you something that you might not know, but you should be aware that all the historical data we see is calculated data, more or less. And I will show you something that is a little bit weird. So if you see the scale here below, we have several months that are listed one behind the other. And suddenly here, we have January the third, January the fourth, and so on. So why is the same scale here much less complex? And that’s because when you zoom into the chart, you will notice that each of those candles here has a value that can be shown when you hover with the mouse over the chart. This is the price for the open, the high, the low, and the close price for November the 15th. And the next candle here will show us the same data for the next day. But actually, we have said that we want to trade on a one hour chart. So what you see with your own eyes here is that for January, we have a price for Midnight. Let’s go a little bit further into the data. This is the next year. And here suddenly we have a price for 10 o’clock. The next candle is for 11 o’clock, and the next one is for 12 o’clock. That is the way it should be. But actually, when you look at the chart like this one, you might probably not notice that up to the date where we started the strategy test, all the data is just one candle per day. Even we have chosen to trade the hourly chart. So basically, this is a quality issue for visual data. And if we start the test here and zoom into the chart, you will see now we have separate candles for each hour. So data quality might be an issue, especially if you’re trading the early years. Let’s do another test. This time I’m using the Euro US Dollar. Here we are. And if we go back in time, you can see we have hourly charts and data that is available for December 2002. Just remember, we have picked to trade from February 2003. So in this case, the data quality is okay. Now let’s pick the whole year. Let’s set that back to the default and start. Now, we should get a result in a few seconds. There we are. And it says that the history quality was 99 %. So if you don’t understand why you have bad results, one of the things that you need to check is the history quality. Let’s repeat the whole thing for the Australian dollar against the Canadian dollar. And here it says the history quality is zero. So make sure to check out the back test tab and the value for the history quality every time you do a strategy test. Okay, so far so good. Thank you for watching and I will see you in the next video. Bye..
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – BEWARE OF HISTORY QUALITY ISSUES appeared first on MQL5 Tutorial.
In this video, let’s take a look at how to calculate a lot size based on the account balance and how to round up or down the result to make it fit. So let’s take a look at how to do that with MQL Five. To do that, in MetaTrader please click on the icon up here or press the F Four key. Then you should end up in the MetaEditor. And here we click on File, New Expert Advisor from template, next, assign a name here. I have already done this. My file is called Simple Lot Size Rounding and we’ve already pre-programmed this. We’ll start with the on tick function. There we first want to calculate the account balance. This is done using the Account Info Double, Account Balance function and based on the account balance we want to calculate the position size. In our case, we use the gross balance value and divide it by 100,000. We also create two variables for the rounded values, one rounded up and one rounded down. We determine these with the help of the respective function, which we program ourselves.
The first function is called Round up, the second Round down and we pass the calculated lot size and the value for the decimal rounding as parameters. We want to round this to one decimal place. With Normalize Double, we can output the final results in a more formatted way. Although we have specified two decimal places here, we see that our results are truncated after the first digit. And using the Comment function, we output the whole thing on the chart. Let’s move on to the actual functions. To round up, we pass our input value. That’s the position size that we passed above and our rounding value. Let’s add the second parameter here for the decimal places. And to get the result, we multiply the rounding value by the result of this function. If you press F1 once and call that up in the help, you’ll see that there’s an integer value returned. And as parameters, we pass the input value and the rounding value to the MathCeil function. Then we use Return to return our result back to the function. The second function for rounding the value works similarly.
Here, however, we do not use MathCeil, but MathFloor. And here we also return the result to our main function. And this then results in the rounded up value 0.3 and the rounded down value 0.2 for a determined lot size of 0.25 lot. Depending on which account type you have, you can adjust this accordingly and thus pass the correct values so that a position can also be opened correctly. Because not all content types support the staggering in microlot sizes down to the second decimal place. By the way, this was again a request from a premium customer. And if you are a premium customer and have an idea for such a video, just send me an email. Otherwise, you can find the premium course on our website. And in this video, you learned how to easily round up or round down lot sizes so that that fits your account type. And you programmed that yourself with these few lines here in MQL5.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – 135 SIMPLE LOT SIZE ROUNDING appeared first on MQL5 Tutorial.
In this video we are going to trade this little Indicator; it’s the Fractal Adaptive Moving Average and we are going to create a Standalone Expert Advisor that is actually going to open positions.
Now how can we do that?
First please click on the little button here or press F4 in your Metatrader and 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 version: “SimpleIFRAMAStandaloneEA” click on “Continue”, “Continue” and “Finish”, now we delete everything above the “OnTick” function and the two comment lines here.
So first let’s use the “include” function to import the file: “Trade.mqh”, it comes with a few useful trading functions that we are going to use to open new positions. We use it to create an instance of “CTrade” that will be called: “trade”.
Inside of the “OnTick” function we just need to calculate the Ask price and the Bid price, those are needed to open new positions. We get the Ask price by using “SymbolInfoDouble“ for the current symbol on the chart and with “SYMBOL_ASK” we will get delivered the price we want. For the Bid price we would use “SYMBOL_BID” and “NormalizeDouble” and “_Digits” are used to calculate the number of digits behind the dot, which might be different from one currency pair to another.
We also create string for the signal; please don’t assign a value right now because that is going to be calculated later. Let’s use “MqlRates” to create a price array (myPriceArray), “MqlRates” is a structure that stores the information about prices, volumes and spread.
Let’s sort the array (myPriceArray) downwards by using “ArraySetAsSeries” and fill the array (myPriceArray) with data for 3 candles by using “CopyRates” for the current symbol and the current period. We start from the current candle 0 (zero) and we store the prices for 3 candles in our price array (myPriceArray).
Now we need another array for the Expert Advisor, this one will be called: “FramaArray”, our frama definition (FramaDefinition) can be created by using the internal function: “iFrAMA” that comes with MQL5, it needs a few parameters; the first one is for the current symbol on the chart, the second one for the period, it’s calculated based on 14 candles and if you click on “Insert/ Indicators/ Trend/ Fractal Adaptive Moving Average” you will see that we use 14 candles and we have a shift value of 0 (zero) – that’s what we use here – and the calculation is based on the close price.
We also need to sort this one from the current candle downwards once again by using “ArraySetAsSeries” for our frama array (FramaArray).
Let’s use “CopyBuffer” according to the frama definition (FramaDefinition) that we have created here for the first buffer in the Indicator – that’s the blue line – from the current candle 0 (zero) and we store the values for 3 candles in our frama array (FramaArray) and now we can calculate our frama value (FramaValue) by looking at candle 1 in the frama array (FramaArray) and we want to sell if the frama value (FramaValue) is above the last candle high – so if our frama value (FramaValue) is bigger than the high for candle 1 in our price array (myPriceArray) we assign the word “sell” to our signal.
There is also a buy signal; we want to buy if the frama value (FramaValue) is below the last candle low – so if frama value (FramaValue) is below the low of candle 1 in our price array (myPriceArray) we would assign the word “buy” to our signal.
Here comes the order; if the signal equals sell and “PositionsTotal” is less than 1 – in other words we don’t have any open positions – we use “trade.Sell” to sell 10 micro lot.
In the other case we buy 10 micro lot if the signal equals buy and we have no open positions; in this case we use “trade.Buy” to buy 10 micro lot.
Finally we create a chart output by using the “Comment” function, it will output the text: ”The current signal is:” followed by the “signal” and now if you are ready you can click on the “Compile” button here or press F7, that should work without any errors here and in that case please click here or press F4 to go back to Metatrader.
In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, please pick the file: “SimpleIFRAMAStandaloneEA.ex5”, enable the visualization mode here and start your test.
…and here we are! We have just opened our first sell trade here, this is our first position and in this little video you learned how to output buy and sell signals for the Fractal Adaptive Moving Average and how to automatically open positions in a Standalone Expert Advisor and you have coded it yourself with a few lines of MQL5 code.
Download “MQL5 TUTORIAL - SIMPLE IFRAMA STANDALONE EXPERT ADVISOR”
SimpleIFRAMAStandaloneEA.txt – Downloaded 308 times – 1.83 KBNot sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE IFRAMA STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video we are going to create an Expert Advisor that is able to automatically trade a Bollinger Bands entry signal and a filter for the MacD Oscillator in Metatrader5. Both indicators are very popular and can be combined to create buy and sell signals that can automatically traded with this standalone Expert Advisor. So let’s see how to do that in MQL5. Please open the MetaEditor. We start by creating a new Expert Advisor by clicking on File, New, Expert Advisor from template. Let’s continue, with the include function to include the file Trade.mqh which comes with MQL5. It provides simplified trading functions and we create an instance of the class CTrade so we can use them.
Afterwards we include two files for the entry and the filter signal. The first one is for the Bollinger Bands and it will give us a trading signal. The second one is for the MacD and it will give us a filter signal. Both files have been coded before as separate modules, so they can also be used for other Expert Advisors. If you want to save time and effort, you can go to MQL5Tutorial.com where you can find the premium course and a lot of precoded source code files in the store. In the next step we need to calculate the Ask price and the Bid price. That can be done by using the function SymbolInfoDouble for the current Symbol on the chart. We use Symbol_Ask to calculate the Ask price and Symbol_Bid to calculate the Bid price. With NormalizeDouble and UnderscoreDigits we can calculate the number of digits behind the dot. Depending on the currency pair, that might be 3 or 5 digits.
With MqlRates we create an Array for prices, called PriceInfo. Inside of the Ontick function we use ArraySetAsSeries to sort our price array from the current candle downwards. Then we can use CopyRates to fill our price array with data. We do that for the current symbol and the currently selected period on our chart, starting from candle 0, for 3 candles and store the result in our price info array. Now let’s calculate the current price by looking at the close price of candle 0 in our price info array. We create a string variable for the Trading Signal and call the function CheckEntryBollinger to check for a buy or sell signal. And we do the same thing for a string variable called Filter and call the function CheckEntryMacD to get the filter signal. If the trading signal and the filter both return a buy signal and we have no open positions, we want to use trade.buy to buy 10 Micro Lot. In the other case, if the trading signal and the filter both return a sell signal, we use trade.sell to sell 10 Micro Lot. Finally, we use the Comment statement to output the trading signal and the filter on our chart. Press F7 to compile the code, if that works without any errors, you can return to Metatrader by pressing the F4 key.
Okay, if everything went well, you should now have a working standalone Expert Advisor for the Bollinger Bands signal and the MacD filter. You can run a strategy test like this one by pressing Control and R in Metatrader5. If you want to improve your trading results, you can find the premium course and more source codes on MQL5TUTORIAL.com and in our shop. Thank you for watching and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – 134 STANDALONE BOLLINGER MACD EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video we are going to talk about this Indicator, it’s the Bears Power Indicator and we want to create an Expert Advisor that is able to actually produce signals that will be seen right here on the chart and in this case we use the Bears Power Indicator tool trade automated.
Usually this Indicator is used as a filter and you would use another signal and only when the signal and the filter are pointing in the right direction you would open a new position.
To code that please click on the little button here or press F4 on your keyboard, now you should see the Metaeditor window and here we want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this one: “SimpleBearsPowerStandaloneEA”, click on “Continue”, “Continue” and “Finish”, now you can delete everything above the “OnTick” function and the two comment lines here.
We start by including the file: “Trade.mqh”, this one comes with MQL5 and it contains some trading functions. We need to create an instance from the class: “CTrade” that will be called: ”trade” and we are going to use it to open positions later on.
Inside of the “OnTick” function we calculate the Ask price and the Bid price, that’s done by using “SymbolInfoDouble” for the current symbol on the chart, “SYMBOL_ASK” will give us the Ask price while “SYMBOL_BID” will give us the Bid price and with “NormalizeDouble” and “_Digits” we calculate the right number of digits after the decimal point.
We also need to create a string for the signal, that string variable will also be called: ”signal” and so far we don’t have any value because that is going to be calculated later.
Let’s create an array for the price data that will be called: “PriceInformation” and we use “MqlRates” to create it because “MqlRates” is the structure that stores the information about prices, volumes and spread. We sort the array downwards from the current candle by using “ArraySetAsSeries” and with “CopyRates” we fill the array (PriceInformation) with price data for the current symbol on the chart and the currently selected period. We start with the current candle 0 (zero) and we need price data for 3 candles – that’s enough – and store the result in our price information array (PriceInformation).
Now let’s create another array called: “myPriceArray” this one is for the Expert Advisor data, the other one was for the candle prices.
The second array also needs to be sorted downwards by using “ArraySetAsSeries”.
Now we use the “iBearsPower” function that comes with MQL5 for the current symbol and the currently selected period on the chart, the last parameter 13, is the number of candles that you also will see when you drag the Bears Power Oscillator on your chart.
Now we use “CopyBuffer” for the bears power definition (BearsPowerDefinition) that we have created here to calculate the values for buffer 0 (zero) – that’s the first buffer – from the current candle 0 (zero) for 3 candles and store the result in our price array (myPriceArray) that makes it possible to calculate the current array value by looking at candle 0 (zero) in our price array (myPriceArray) and we store a result in the bears power value (BearsPowerValue) and if the “BearsPowerValue” is above 0 we would consider that to be a buy signal so we assign the word: “buy” to our signal.
Otherwise if the “BearsPowerValue” is below 0 we consider that to be a sell signal so now we assign the word: “sell” to our signal and if the signal equals sell and we have no open positions we use “trade.Sell” to sell 10 micro lot.
Otherwise if the signal equals buy and we have no open positions we would use “trade.Buy” and buy 10 micro lot.
Finally we create a chart output that is done by using the “Comment” function and we want to output the words: “The current signal is:” followed by the calculated “signal”.
Now let’s compile the code, we don’t have any errors and in that case we can click here or press F4 to go back to Metatrader.
In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, you will select the “SimpleBearsPowerStandaloneEA”. Let’s also enable the visualization option here and start your test.
…and here is our little example at work, we have buy and sell signals, usually you would use the Bears Power Oscillator to filter another entry signal but now you know how to code a standalone Expert Advisor for Metatrader 5 and you have coded it yourself with a few lines of MQL5 code.
Download “MQL5 Tutorial - Simple Bears Power Standalone Expert Advisor”
SimpleBearsPowerStandaloneEA.txt – Downloaded 156 times – 1.71 KBNot sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE BEARS POWER STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
Today I got another request from an interested, starting MQL programmer who asked me if it was possible to make at least 3% profit in a month. In fact, I heard that even Warren Buffett as an investor can only make about 20% profit in a year and he is one of the richest men in the world. A 3% monthly profit would equate to an annual profit of about 36%, which is much higher than Warren Buffett’s average return. Now, does that mean that’s not possible?
Well, actually it is rather the case that a profitable solution over a longer period of time is difficult to implement if you want or need to achieve at least 3% per month. The idea is basically not to make a particularly high profit immediately, but to make as few mistakes as possible, especially in the initial phase, and to lose as little money as possible. The majority of all beginners lose a large part or even the entire trading capital within a few months. So the first step is not to optimize profits, but to limit losses while you are still learning and have enough capital. The second problem with this is that every month is slightly different. You can’t think of profits from automatic trading as a regular salary. There may be months when you make minus. In return, you may make a little more plus in another month. In addition, there is the problem that people always tend to question their own system and want to improve it.
If you can’t stick to your own rules, you will realize by the third or fourth exception at the latest that you did exactly the wrong thing at exactly the wrong time. This can lead to being frustrated and out of that comes such things as revenge trades. Humans are emotional and that leads to situations always arising where we feel uncomfortable or do rash things. The intention behind it may be good, but often the result is quite disastrous. Many people also see automatic trading as a kind of fortune telling or a substitute for gambling. But in fact it is more about statistical probabilities. And that means that there can be deviations from the norm.
An average profit expectation does not mean that you should expect that for every week or month you trade. If you are not able to sustain your own trading system over a long period of time, you will basically have a hard time. Regardless of whether you prefer automatic or manual trading. To be successful, it is important to develop a solid strategy, stick to your own rules and avoid emotional decisions. This is the only way to be successful in trading in the long run and make steady profits. At the same time, one should have realistic expectations and be aware that trading is not a fast track to riches, but rather a discipline that requires time, patience and constant learning.
Constant testing and adapting to changing market conditions is essential to be successful in the long run.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – IS 3 PERCENT MONTHLY TRADING PROFIT POSSIBLE appeared first on MQL5 Tutorial.
In the ever-changing world of the trading market, knowing how to protect your investments is essential. One of the most popular ways to do this is by using a stop-loss order. A stop-loss order is an essential tool in any trader’s arsenal, but what is the best stop loss percentage to use? In this comprehensive guide, we’ll explore various stop-loss strategies and help you determine the optimal percentage for your trading style.
What is a Stop-Loss Order?A stop-loss order is a type of trading order designed to limit an investor’s loss on a position in the stock market. It works by automatically closing a position when it reaches a predetermined price, known as the stop-loss level. This helps traders protect their capital and minimize losses during times of strong market movements.
Types of Stop-Loss Orders [Stock and Forex]There are several types of stop-loss orders, including traditional stop-loss, trailing stop-loss, and stop-limit orders. Each type has its own unique advantages and disadvantages, but they all serve the same purpose: to limit your losses in the market.
Factors to Consider When Determining the Best Stop Loss PercentageWhen determining the perfect stop loss percentage for your trading strategy, several factors should be taken into account. These include:
Popular Stop-Loss Strategies1. Percentage method: Set your stop-loss order a certain percentage below the stock’s current price or entry point. For example, if you bought at $100 and set a 5 percent stop-loss, your order would automatically close the position if it dropped to $95. 2. Moving average method: Use a moving average (such as the 50-day or 200-day moving average) as a reference point for setting your stop-loss order. This strategy can help you adapt to changing market conditions and trends. 3. ATR (Average True Range) method: The ATR is a measure of volatility that calculates the average range of price movement over a specified period. By multiplying the ATR by a certain number, you can determine an appropriate volatility stop loss level based on the stock’s volatility. 4. Support level method: Set your stop-loss order just below a recent support level. This strategy helps protect your position while allowing for normal market fluctuations.
The Importance of a Well-Defined Stop-Loss Order StrategyHaving a clear stop-loss order strategy in place is crucial for successful trading. It allows you to predetermine your maximum loss, manage risk effectively, and prevent emotional decision-making in times of market uncertainty. By considering factors like volatility, support and resistance levels, and your personal trading style, you can determine a better stop loss percentage for your unique situation.
How to find the perfect stop loss order percentage?When engaging in trading, it is essential to have a personalized and well tailored stop loss policy in place to shield your money from potential losses. A stop loss should protect an investor from suffering severe losses, but determining the appropriate amount of the stop loss can be difficult. For most traders, their own stop loss order is to blame for eighty percent of the losses that they had hoped to avoid. Therefore, what would be the best approach to take? First and foremost, investors need to be aware that there are several distinct types of stop loss strategies, such as fixed, trailing, and dynamic stop loss strategies. Each kind has its own set of pros and cons, and the trader’s decision as to which one to use depends on the level of risk he or she is willing to take and the current state of the market. There is a school of thought among traders that a predetermined percent stop loss is the most foolproof choice.
Each stop loss solution comes with a cost!When it comes to stop loss solutions there is something every investor needs to understand: there is no free lunch! Each solution comes with a cost, and it is crucial to calculate that upfront. However, in my opinion, there is one solution that beats them all. It is called the equity stop. Now, you might be wondering what an equity stop is and why it is more effective than all other solutions. Well, let me inform you that most people don’t know about this hidden gem in the world of investing. Unlike other stop loss solutions, the equity stop puts a stop loss order on the amount of equity based on the account. This means that an investor sets a percentage at which they will exit their position, based on the amount of account equity they have. It is a more flexible and dynamic solution that allows for adjustments according to the account monetization. It is less restrictive than other solutions and provides greater control over risk management. Remember, when it comes to investing, it’s not just about the profits – it’s also about minimizing losses. Therefore, if you are looking for a stop loss solution that does not come with a high cost, consider the equity stop. It may just be the answer you’ve been searching for!
Should I use a fixed or dynamic solution?A fixed stop loss requires the trader to choose a particular percentage, and once the price of the securities reaches that amount, the trader is required to quit the position. The benefit of taking this technique is that it is unaffected by the current state of the market, and the trader is aware of the maximum amount of money that may be lost on their investment. Fixed stop losses, on the other hand, are fundamentally stiff and might not be appropriate for markets that are more volatile. On the other hand, trailing stop losses are more adaptable and modify themselves according on the state of the market. Because it is determined by the asset’s current value in the market, a trailing stop loss is a type of dynamic trading technique. A predetermined percentage or cash amount is used to determine if the distance between the current price and the stop loss should be increased or decreased. As a result of the stop loss moving in tandem with the market’s movement, traders are able to maximize their profits and minimize their losses. In general, a trailing stop loss is more suited when the market is volatile than a fixed stop loss. In conclusion, dynamic stop losses combine elements of a trailing stop loss with a fixed stop loss. Taking this strategy gives traders the ability to modify their stop loss according on the state of the market. If the market is particularly volatile, for instance, the trader may choose to increase the size of the stop loss order in order to better safeguard their investment. It may be possible for dynamic stop losses to reduce losses more effectively, but using them requires investing time and effort into monitoring market swings. In conclusion, determining the appropriate stop loss % can be difficult because it is contingent on a wide range of circumstances. Traders need to have a solid understanding of the various stop loss techniques, as well as their own risk tolerance and the current market conditions. Fixed stop losses may be appropriate for markets with lower levels of volatility, while following or dynamic stop losses may be more appropriate for markets with higher levels of volatility. In the end, traders should have a well-defined plan and the discipline to follow it in order to limit losses while simultaneously maximizing gains.
Not sure what to do? Click on the automated trading assistant below
The post Choosing the Best Stop Loss Percentage Solution for Stock and Forex appeared first on MQL5 Tutorial.
In this video we are going to create a Standalone version for an Expert Advisor that is able to handle this Indicator here: it is the Triple Exponential Average, whenever the red line is below the dotted line that’s a sell signal and when it crosses the line and is above the dotted line that is a buy signal.
Now how can we create an Expert Advisor that is able to automatically open trades for the signal here?
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: “SimpleItrixStandaloneExpertAdvisor” , click on “Continue”, “Continue” and “Finish”.
Now we can delete everything above the “OnTick” function and let’s also remove the two comment lines here.
We start by including the “Trade.mqh” file that one comes with MQL5 and it helps us to create an instance of the class “CTrade” that will be called: “trade” and we are going to open trades with it later on.
Inside the “OnTick” function we start by calculating the Ask and the Bid price, we get that by using “SymbolInfoDouble” for the current symbol and with “SYMBOL_ASK” we will get the Ask price and “SYMBOL_BID” will deliver us the Bid price.
We also use “NormalizeDouble” and “_Digits” to calculate the right number of digits behind the dot for each currency pair. With “MqlRates” we create a price info (PriceInfo) array that will hold our price data, first we use “ArraySetAsSeries” for the price info array (PriceInfo) to sort the price array from the current candle downwards and afterwards we use “CopyRates” for the current symbol and the currently selected period on the chart to fill the price array (PriceInfo) with price data. We start at candle 0 (zero) – that’s the current candle – we copy the price info for 3 candles and store the values in the price info array (PriceInfo).
Let’s create a string variable for the signal that will also get the name “signal” but we don’t assign a value here because that needs to be calculated later on, first we need to create another array. This one will hold the price data for the Indicator (myPriceArray), MQL5 comes with the built-in “iTriX” function that will help us to create the definition for our Expert Advisor here. We are also using the current symbol, the currently selected period on the chart, 14 is the number of candles, you will also see it in the brackets here and the calculation will be done for the close prices.
Once again we use “ArraySetAsSeries” to sort the price array (myPriceArray) from the current candle downwards and now we use “CopyBuffer” according to the itrix definition (iTriXDefinition) that we have created here to fill our price array (myPriceArray) with data for the buffer 0 (zero) – that’s the red line here – and we do that from the current candle 0 (zero) for 3 candles.
Now we can get the value for the current candle by looking into candle 0 (zero) of our price array (myPriceArray) and assign the value to the variable itrix value (iTriXValue) and if that “iTriXValue” is above 0 that would be a buy signal so we assign the word: “buy” to our signal.
Otherwise if the “iTriXValue” is below 0 that would be a sell signal and in that case we assign the word: “sell” to our signal.
If the signal equals sell and “PositionsTotal” is below 1 – in other words we don’t have any open positions – that’s when we want to use “trade.Sell” to sell 10 micro lot. In the other case if the signal equals buy and we have no open positions we use “trade.Buy” to buy 10 micro lot.
Finally we use the “Comment” function to output the sentence: “The current signal is:” followed by the calculated “signal” directly on our chart.
Okay, that’s it, please click on: “Compile” or press F7, that worked without any errors here so now I can click on the little button here or press F4 to go back to Metatrader and in Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, here we pick the file: “SimpleItrixStandaloneExpertAdvisor”, mark the visualization option and start a test.
…and here we are! We already have opened a trade here and now you know how to create a standalone version that is able to trade the Triple Exponential Average, output the buy and sell signals directly on the chart and you have coded it yourself with a few lines of MQL5 code.
Download “MQL5 TUTORIAL - SIMPLE ITRIX STANDALONE EXPERT ADVISOR”
SimpleItrixStandaloneEA.txt – Downloaded 305 times – 1.71 KBNot sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE ITRIX STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
YouTube privacy policy
If you accept this notice, your choice will be saved and the page will refresh.
Accept YouTube Content
MQL5 Trading: The Future of Algorithmic Trading SignalsHave you ever wondered how trading robots have revolutionized the forex market? MQL5 trading, the programming language behind MetaTrader 5, is one of the best advances in algorithmic trading, making it an incredibly interesting platform for traders around the world.
As a trader, the MQL5 language enables you to create trading robots and technical indicators, allowing you to take advantage of automation and sophisticated strategies. With the ever-growing library of mathematical calculations, the possibilities are endless.
MetaTrader 5: A Trading Platform for the Modern TraderMetaTrader 5, a leading trading platform, has captured the attention of financial markets with its user-friendly interface and real-time insights. Offering a lot of currency pairs and indices, this platform facilitates automated trading and expert advisors for trading signals and risk management.
Expert Advisors: Your Personalized Trading AssistantsOne unique feature of MQL5 trading is its ability to develop your own trading robot. These robots, known as Expert Advisors (EAs), are applications programmed to execute trading strategies and manage your trades. With the MQL5 programming language, you can develop, code, and download your custom EAs to stay ahead of the market trends.
MQL5 Language: A Powerful Tool for Financial MarketsBut what sets MQL5 apart from other programming languages? It’s specifically designed for financial markets, offering advanced functions and real-time execution of trading strategies. This language caters to both novice and expert programmers, making it an ideal choice for creating trading robots and indicators.
The MQL5 Community: A Forum for Collaboration and LearningThe MetaTrader 5 trading platform also provides a dedicated forum for traders and developers, where they can discuss strategies, share trading signals, and access a vast range of resources. This interactive community invites collaboration, fosters learning, and paves the way for future advancements in MQL5 trading.
MQL5 Market: A One-Stop Shop for Trading ToolsMoreover, the MQL5 Market offers a plethora of ready-made trading robots, expert advisors, and technical indicators for purchase or rent. With secure payment options, this marketplace presents an opportunity for developers to monetize their skills while providing traders with a chance to enhance their trading arsenal.
Risk Management: Staying Ahead in Forex TradingAnother fascinating aspect of MQL5 trading is the implementation of risk management strategies. Algorithmic trading allows you to calculate and manage risks in real-time, improving your chances of success in the ever-changing world of forex.
Embracing the Possibilities of MQL5 TradingUltimately, MQL5 trading is transforming the way traders approach the forex market. With its combination of automation, algorithmic trading, and technical analysis, MQL5 offers endless possibilities for creating trading robots and indicators. This exciting platform is redefining the future of forex trading, inviting traders and programmers alike to take advantage of its sophisticated tools and innovative approach to financial markets.
Why upgrade from Metatrader 4 to Metatrader 5? Upgrading from Metatrader 4 to Metatrader 5 has many benefits for traders. First, with Metatrader5, traders can access improved algorithmic trading features that allow them to create more complex trading patterns and strategies. Additionally, Metatrader5 has a more powerful compute engine which enhances the speed and efficiency of back-testing and optimization of strategies. MT5 has also seen significant improvements to MT4’s language (which was MQL4) giving algorithmic traders more flexibility in building custom indicators and automated trading systems.
How to become a Developer and create your own Trading Robot Becoming a developer and creating your own trading bot is an exciting and challenging endeavor. First, you need to familiarize yourself with a programming language such as MQL5, which is the language used in MetaTrader 5 (MT5). MT5 comes with MQL5, which makes it easy to create automated trading-robots. One way to learn MQL5 is to watch video tutorials on our YouTube channel MQL5Tutorial. Once you have a good understanding of MQL and have watched the tutorials, you can start developing your first simple robot fast. Be sure to test your robot thoroughly using backtesting and forward testing before you deploy it live in the market. By following these steps, you can become a successful programmer and create your own bot.
Not sure what to do? Click on the automated trading assistant below
The post Use MQL5 Trading to beat the Market: MetaTrader 5 Platform for Trading Robots, and Algorithmic Trading appeared first on MQL5 Tutorial.
Mastering the Bollinger Bands Indicator for Automated Forex Trading with MQL5Are you a fan of rollercoasters? If so, you might find the world of forex trading with the Bollinger Bands indicator exhilarating. Just like a rollercoaster, Bollinger Bands can help you navigate the ups and downs of the market with precision and excitement. Technical analysis focuses on market action — specifically, volume and price. The study of market behavior, particularly the movement of prices and volume, is the primary focus of technical analysis on your chart.
But hold on tight, because we’re about to embark on an entertaining journey to discover how to use this fantastic indicator for automated trading with MQL5.
Use Bollinger Bands Indicator – Your Chart Rollercoaster to buy or sellYou might be wondering how Bollinger Bands can be used? The Trading Bands were created by John Bollinger in the 1980s as a way to measure price volatility. Think of them as dynamic, rubbery bands that surround the price action, expanding and contracting as the market’s volatility changes.
These magical bands consist of three lines: the middle line, also known as the Simple Moving Average (SMA), and two outer lines known as the upper and lower Bollinger Bands. The space between the upper and lower bands represents the volatility, and it’s this very space that holds the secret to your trading success. The calculation typically involves using a 20-period Simple Moving Average (SMA) and 2 standard deviations.
Buckle Up: Automating Bollinger Bands with MQL5Now that you’re familiar with the concept of Bollinger Bands let’s dive into the world of MQL5 and learn how to automate this indicator for forex trading to make trading decisions.
MQL5 is a powerful language used for developing trading robots, technical indicators, and scripts. It’s like the master chef of the forex kitchen, whipping up delectable trading strategies for your automated trading pleasure. The first step to using Bollinger Bands with MQL5 is to understand the basic syntax and structure of the language.
Before you start building your automated trading masterpiece, you’ll need a clean and organized workspace. In the MQL5 world, this means setting up MetaEditor – the specialized editor for creating trading robots and technical indicators. MetaEditor comes with MetaTrader 5, your trusty trading platform.
With your MQL5 Workspace ready, it’s time to create a new Expert Advisor (EA) that will use the Bollinger Bands indicator. Begin by opening MetaEditor and creating a new MQL5 file with the Expert Advisor template.
Now, you’ll need to declare the Bollinger Bands indicator handle and a few input parameters for customization. These parameters include the period of the Simple Moving Average, the price type used (close, open, high, low), and the deviation for the upper and lower bands.
You’ve got your ingredients; now it’s time to cook up the trading logic for your Bollinger Bands Expert Advisor. Within the OnInit() function, initialize the Bollinger Bands indicator handle by calling the iBands() function. This function requires the symbol, timeframe, period, deviation, and applied price as input parameters.
In the OnTick() function, retrieve the Bollinger Bands values using the CopyBuffer() function. This step allows your Expert Advisor to access the upper, middle, and lower band values for the current and previous bars.
With the Bollinger Bands values in hand, it’s time to decide on your trading style. You could opt for a simple breakout or a mean reversion approach. The choice is yours, but remember, the goal is to create a trading system that takes advantage of the Bollinger Bands’ ability to measure market volatility.
For those thrill-seekers who love riding rollercoasters, a breakout strategy could be the perfect fit. In this approach, you’ll look for moments when the price breaks above the upper Bollinger Band or below the lower Bollinger Band, signaling a potential trend continuation.
To implement this strategy, traders use the OnTick() function to monitor the current and previous bar’s prices relative to the Bollinger Bands. If the price breaks above the upper band, you’ll place a buy order, and if it breaks below the lower band, you’ll place a sell order. Remember to implement proper risk management, such as setting stop-loss and take-profit levels, to protect your account from unexpected market moves.
If you prefer a more cautious approach, the mean reversion strategy might be the one for you. This method relies on the idea that the price will eventually revert to the mean (the middle Bollinger Band) after reaching the outer bands.
To put this strategy into action, monitor the current and previous bar’s prices in relation to the Trading Bands within the OnTick() function. If the price reaches the upper band and then starts to retreat, you’ll place a sell order, anticipating a move back to the middle band. Similarly, if the price touches the lower band and begins to bounce back, you’ll place a buy order. Don’t forget to decide about your stop-loss and take-profit levels to manage your risk.
With your Bollinger Bands EA built and ready to conquer the market, it’s time to put it through rigorous testing and optimization. Use the MetaTrader 5 Strategy Tester to test your EA’s performance on historical data, and fine-tune its parameters to achieve the best results. Optimization is an essential step in creating a reliable and profitable trading system.
Conclusion – Bollinger Bands® best usedCongratulations! You’ve successfully navigated the twists and turns of the Bollinger Bands indicator for automated trading with MQL5. With your newly acquired knowledge, you’re ready to take the forex market by storm and ride the rollercoaster of price volatility to greater profits. Just remember, trading is like baking a cake or building a house – it requires a well-defined recipe, a solid plan, and a consistent approach. So strap in, hold on tight, and enjoy the ride!
Why I like technical trading with the Bollinger BandsLike many traders, I really like the indicator that the technical trader John Bollinger suggests, it is a good solution and best used when volatility increases. A price move in high or low volatility can be handled with this solution developed by John Bollinger. I actually used them in my very first Expert Advisor and I still like them to this day. I ignored everything within these bands and traded re-entries when the price was outside the bands. They are a very solid indicator and I find them to be very effective in identifying potential entry and exit points for trades. The Bands widen when the volatility increases. Of course, it is important to remember that all trading signals are based on past data and are not always perfect predictors of future market movements. However, I have found that the Bollinger Bands tend to be a bit more reliable than many other indicators out there, because the bands show even signals when they are close together. Overall, I think this is a good solution for any trader to have as a technical analysis tool.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – Why should I use Bollinger Bands? appeared first on MQL5 Tutorial.
What is a simple moving average?A simple moving average (SMA) is a basic technical analysis indicator commonly used in financial markets. It is a calculation of average price over a certain period of time, where each data point is given equal weight. The SMA is a widely used tool for traders and investors, as it can help to identify trends and potential opportunities. For example, a trader may use a 50-day SMA to determine an overall trend in a stock’s price. If the stock’s price is consistently above the SMA line, it may indicate a bullish market trend. Conversely, a trader may interpret a stock’s price consistently below the SMA line as a bearish trend. The SMA can be customized to fit different timeframes and periods, making it a versatile tool in technical analysis. While SMA is a relatively simple indicator, it can be a valuable tool for investors and traders to help identify potential trading opportunities. Moving averages are an important analytical tool used to identify current price trends and the potential for a change in an established trend. The utilization of moving averages is significant in the realm of analysis as it enables recognition of the present price tendencies and likelihood of a shift in a preexisting trend.
Why should I use a simple moving average?As an aspiring trader or investor, you might wonder why you should use a simple moving average (SMA). The answer lies in the usefulness of this technical tool in identifying trends in the market. By calculating the average price of an asset over a specific period, SMAs give a clear picture of its movement and direction. This makes it easy to understand the overall trend and take advantage of potential opportunities. Moreover, SMAs are widely used by thousands of traders across multiple markets, making it a reliable and trusted tool in the trading community. By utilizing SMAs, you gain greater insight into market movements and improve your chances of making profitable trades.
What is the best setting for Simple moving average?When it comes to determining the best setting for a simple moving average, there is no one-size-fits-all answer. This is because the optimal settings for an SMA depend largely on your personal trading strategy as well as whether you’re focused on long-term or short-term trading. For example, a day trader may find that a 15 or 20-day SMA provides the best signals for making quick decisions given the volatility of intraday price movements. On the other hand, for those focused on longer-term trades, a higher SMA setting between 50 and 200 days (the 200-day SMA is popular) can help capture long-term trends more effectively. In short, the best setting will depend on factors like the timeframe of trades, the market being traded, and the level of volatility. Ultimately, finding the optimal SMA setting requires trial and error, as different traders will have different preferences and goals when using moving averages.
Should I use a simple or exponential moving average?The decision to use a simple or exponential moving average depends on the individual trader’s strategy and goals. Simple moving averages weight all candles equally, providing a smoother and less responsive signal. In contrast, EMAs put a higher weight on current candles, making them more responsive to recent price movements. If a trader believes that current events are more important in predicting future price movements, then an EMA may be preferred over an SMA. However, if a trader is looking for a more long-term trend signal, a simple moving average may be more appropriate. Ultimately, traders should experiment with both types of moving averages and decide which one works best for their trading style and goals.
What is a weighted moving average?A weighted moving average is a common technique used in statistical analysis to smooth out a data set. It is a type of moving average where different time periods are assigned different weights in the calculation. This is in contrast to a simple moving average (SMA) which assigns equal weight to all time periods. The weights assigned in a weighted moving average can be based on various factors such as importance and relevance of data points. The exponential moving average (EMA) is also a type of weighted moving average, where more weight is given to recent data points. The purpose of using a weighted moving average is to reduce the effect of noise or outliers in the data and provide a clearer trend analysis.
What is a crossover strategy?Using two moving averages in combination can result in the creation of signals indicating crossovers.
When calculating crossover signals, it is possible to employ a combination of two distinct moving averages.
A bullish crossover occurs when the shorter moving average crosses above the longer moving average. This is also known as a golden cross.
A bearish crossover occurs when the shorter moving average crosses below the longer moving average.
A crossover can indicate an uptrend or a downtrend. Price action and price movement for the SMA can be calculated by adding
Multiple moving averages can be used to confirm trendsMultiple moving averages can be a great tool to confirm long term trends. Using 3 or more moving averages, such as the popular triple SMA (Simple Moving Average) strategy, can help to smooth out short term volatility and provide a clearer picture of the direction of the market. By plotting the moving averages on a chart, traders can identify when they cross over each other, indicating a potential change in trend direction. If the prices are consistently trading above the moving averages, it suggests a bullish trend, whereas if the prices are consistently trading below the moving averages, it indicates a bearish trend. Overall, incorporating multiple moving averages into technical analysis can lead to better decision making and more accurate trading strategies.
How do I calculate a Simple Moving Average (SMA)?The SMA is calculated by taking the average price of an asset over a specified time period. The formula for calculating the SMA is simple; all you need to do is add the closing prices of the asset for the specified period and divide the total by the number of periods. For example, to calculate a 10-day SMA, you would add the closing prices of the asset for the last 10 days and divide by 10. This will give you the value of the SMA for the 10-day period. The SMA is a useful tool for traders and investors to identify trends in the market and make informed decisions. It is important to note that the SMA is a lagging indicator and should be used in conjunction with other technical analysis tools for a more comprehensive analysis.
ConclusionWether you use SMA crosses to detect long-term price changes with a long-term SMA in the current trend, or to detect short term fluctuation with another moving average, or even to identify support or resistance, an SMA is one good tool that you might want to add to your trading toolbox.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – Simple Moving Average – Do I need an SMA for my trading strategy? appeared first on MQL5 Tutorial.
In this video we are going to create a standalone Expert Advisor for the Double Exponential Moving Average Indicator; it’s the red line here and whenever it crosses our price it will produce either a buy or a sell signal and now we are going to find out how to create an EA that is able to actually trade the signals automated.
To do that please click on the little button here or press F4 in 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 give it the name: “SimpleIDEMAStandaloneEA”, click on “Continue”, “Continue” and “Finish”.
Now we can delete everything above the “OnTick” function. We start by including the file: “Trade.mqh” that is part of MQL5, now we create an instance of “CTrade” that will be called: “trade”, let’s remove the two comment lines here.
Inside of the “OnTick” function we calculate the Ask price and the Bid price by using “SymbolInfoDouble” for the current symbol on the chart, “SYMBOL_ASK” will give us the Ask price while “SYMBOL_BID” will give us the Bid price and with “NormalizeDouble” and “_Digits” we calculate the number of digits behind the dot because some currency pairs have 3 and others have 5 digits behind the dot.
Now let’s continue by using “MqlRates”, we create an array for the price data that will be called: “PriceInfo”, we sort the price array (PriceInfo) from the current candle downwards that is done by using “ArraySetAsSeries” for the price info array (PriceInfo) we just created and by using “CopyRates” we fill the array (PriceInfo) with price data, that is done for the current symbol and currently select a period on the chart, we start with candle 0 (zero) – that’s the current candle – and we copy the prices for 3 candles and store it in the price info array (PriceInfo).
We also need to create a signal that is a string type variable, this is an empty value because we need to calculate the value later on. Let’s create an array for the price data of the Expert Advisor that will be called: “MyEaArray” and we define the properties for the Double Exponential Moving Average by using the built in “iDEMA” function that comes with MQL5 for the current symbol and the currently selected period on the chart.
We will calculate the result based on 14 candles without any shift to the right or to the left and we use “PRICE_CLOSE” to calculate the results based on the close price.
Now when you click on: “Insert/ Indicators/ Trend/ Double Exponential Moving Average” you will see that we here also see the period of 14 candles, the shift value of 0 (zero) and it is applied to the close price so that’s what we use here.
Let’s sort that array also by using “ArraySetAsSeries” and use “CopyBuffer” to fill it according to the my moving average definition (movingAverageDefinition) that we have created here for buffer 0 (zero) – that’s the red line here – from the current candle 0 (zero) for 3 candles and store the values in our price array (MyEaArray).
Now we can calculate the Expert Advisor for the last finished candle – that’s candle 1 in our EA array – (MyEaArray) and we assign the result to the variable “myMovingAverageValue” and if that moving average value (myMovingAverageValue) is bigger than the close price for candle 1 in our price info array (PriceInfo) that would be a sell signal and in that case we assign the word: “sell” to our signal.
Otherwise if the moving average value (myMovingAverageValue) is below the close price for candle 1 in our price info array (PriceInfo) – that’s when we want to buy – so now we assign the word: “buy” to our signal.
So if our signal equals sell and “PositionsTotal” is below 1 – in other words we don’t have any open positions – that’s when we use “trade.Sell” to sell 10 micro lot.
Otherwise if the signal equals buy and we have no open positions we use “trade.Buy” and buy 10 micro lot.
In the last step we are going to use the “Comment” function to output the words: “The current signal is:” and the calculated “signal” directly on our chart.
Don’t forget the closing bracket here and when you’re done please click on the “Compile” button or press F7, that worked without any errors, so now we can click here or press a F4 to go back to Metatrader.
And in Metatrader we click on: “View/ Strategy Tester” or press “CTRL and R” here we pick the file: “SimpleIDEMAStandaloneEA.ex5”, mark the visualization option here and start a test.
…and here we go, our Expert Advisor is already trading and now you know how you can create an MQL5 EA that is able to actually trade the Double Exponential Moving Average signal and you have coded it yourself with a few lines of MQL5 code.
Download “MQL5 TUTORIAL - SIMPLE IDEMA STANDALONE EXPERT ADVISOR”
SimpleIDEMAStandaloneEA.txt – Downloaded 187 times – 2.12 KBNot sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE IDEMA STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video, we are going to create a very simple strategy that will open a trade whenever we have three bullish candles in a row. This is a very simple strategy, but it works actually okay.
So let’s find out how you can create an expert advisor like this one with MQL5.
Let’s take a look at the source code for our expert advisor. We start here with an include command. With this, we import trade.mqh. This is a library that provides simplified trading functions. With this, we can create an instance of the class Ctrade with the name trade. In the function itself, we determine the price using symbol info double for the current currency pair on the chart. We want to determine the ask price and with underscore digits we get in combination with normalized double the correct number of decimal places for the respective currency pair. We repeat the whole thing here again with the bid price. The line is so far identical except for this part where we use symbol underscore bid. We are also interested in the growth balance. We determine this with account info double and here we pass as parameter account_balance. For the net balance called equity, we repeat this again. But in this case we use account underline equity as parameter. After that, we create a price array with the name price info using MQL rates. Using array set as series, we can now sort our price info array from the current candle downward.
And using copy rates, we now fill the price array for the current currency pair and the time unit selected on the chart. We start from candle zero and fill the array with the value for four candles, which we store in our price info array. Why do I use four candles here? Quite simply, in the experiment, you can swap the numbers around here because candle zero is the current candle and the result changes quite a bit if you omit the current candle. For now, we want to find out if the closing price for candle zero in our price info array is greater than the opening price for candle zero. If it is, we have a bullish candle. We then repeat the whole thing again here for the closing prices and the opening prices of candle 1 and candle 2 and immediately, if we have three bullish candles in a row, we want to know if the current number of positions is zero. If it is, then we would like to open a position. To do this, we use trade sell to open a position for 10 micro lot. Finally, we use the comment command to display the value for the balance, that is, the gross balance and the value for the equity on the chart.
That’s about it for the most part. When you’re ready, you can pop up the toolbar here at the top and click compile or press the F7 key. That should work here without any errors. And if it does for you, then you can click on this little icon up here or press F4 to return to Metatrader. Now here we are going to run our new Expert Advisor simple triple bullish candle. If the strategy tester is not displayed, you can show it here via the menu or with the key combination control and R. Let’s start our test. Then you can see here already the first graphical development and you have programmed this yourself with this few lines here in MQL5.
Okay, if everything went well, you should already have the expert advisor running here. I hope it worked for you. If you don’t know what all the MQL5 code means or if this was too fast for you, you maybe want to open one of the other basic videos in our channel, or maybe the premium course on our website might be interesting for you. For now, I would like to say thank you for watching and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE TRIPLE CANDLE STRATEGY appeared first on MQL5 Tutorial.
In this video we are going to create a Standalone Expert Advisor that is going to trade random entries. It creates buy and sell signals directly on the chart, here is our first open position and now we are going to find out how to create something like this in and MQL5.
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: “SimpleStandaloneRandomEA”, click on “Continue”, “Continue” and “Finish” and now we are going to delete everything above the “OnTick” function and the two comment lines here.
We start by using the “include” function to include the file: “Trade.mqh” that one comes with MQL5 and it allows us to create an instance of the class “CTrade” that we will call: “trade” and we are going to use it later on to open new positions.
Inside of the “OnTick” function we want to calculate the Ask price and the Bid price that’s done by using “SymbolInfoDouble”, the first parameter is for the current currency pair on the chart, the second one will deliver the Ask price or the Bid price, it depends on if we use “SYMBOL_ASK” or “SYMBOL _BID” and “NormalizeDouble” and “_Digits” will make sure that we get the right amount of digits behind the dot.
Now we use “MqlRates” that structure stores the information about prices, volumes and spread for the candles. We sort the price info array (PriceInfo) downwards from the current candle by using “ArraySetAsSeries” and with “CopyRates” we fill our price info array (PriceInfo) for the current symbol and the currently selected period on the chart with price data from the current candle 0 (zero) for 3 candles.
Now let’s create a string variable called: “signal” that will be used to calculate the signal later on, right now it’s empty and here comes the interesting part; we use ”MathSrand” and “GetTickCount” to initialize the random generator because we want to calculate a random number. We use “MathRand” %2 because “MathRand” can return a pseudorandom integer within the range of 0 to 32,767 but we only need 2 random numbers, so let’s say if the random number is 0 (zero) that would be a buy signal and in that case we would assign the word: “buy” to our signal. Otherwise if the random number is 1 we suppose that this one is a sell signal so we assign the word: “sell” to our signal and whenever the signal equals sell and “PositionsTotal” is below 1 – in other words we don’t have any open positions – we use “trade.Sell” to sell 10 micro lot. Otherwise if the signal equals buy and we have no open positions we use “trade.Buy” to buy 10 micro lot.
Finally we use the “Comment” function to output the words: ”The current signal is:” followed by the calculated “signal” directly on our chart.
That’s it, please click on the “Compile” button or press F7, now you should see that it went well without any errors and in that case you can click here or press F4 to go back to Metatrader.
In Metatrader we click on: “View/ Strategy Tester” or we press CTRL and R, please select the “SimpleStandaloneRandomEA” file, enable the visualization here and start your test.
And now you should see the first trade on the chart, let’s speed that up a little bit here and you see that we have made several trades, in this case we have made a profit and if you have no idea which results you could expect from a random entry you should definitely try this out.
Okay. In this video you have learned how to create an MQL5 Expert Advisor that is going to trade random entries and output signals directly on the chart and you have coded it yourself with a few lines of MQL5 code.
Download “MQL5 TUTORIAL - SIMPLE STANDALONE RANDOM EXPERT ADVISOR”
SimpleStandaloneRandomEA.txt – Downloaded 340 times – 1.38 KBNot sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE STANDALONE RANDOM ENTRY EA appeared first on MQL5 Tutorial.
In this video, we are going to create a little simple expert advisor to secure your account number. So nobody else will be able to use your expert advisor if not a certain type of account is used. So let’s see how that can be done with MQL5.
The account number variable: the first part of the code is the declaration of the account number variable. This variable is used to store the account number that is to be compared against the predetermined number. The OnTick function: the OnTick function is a special function that is automatically called by the Metatrader platform whenever a new tick is received. In this case, the Ontick function is used to call the check account number function, which will be discussed in more detail later. The check account number function: The check account number function is the main function used to verify the account number. It begins by declaring the is licensed account boolean variable and setting it to false. This variable is used to store the result of the comparison between the account number and the predetermined number. The next line of code uses the account info integer function to retrieve the account number from the Metatrader platform and store it in the account number variable. The following line of code uses the account info integer function to retrieve the account type from the Metatrader platform and store it in the account type variable. The next part of the code is an if statement that compares the account number variable to the predetermined number.
If the comparison returns true, then the is licensed account variable is set to true and a message is printed to the terminal window. The last part of the code is an if statement that checks the value of the is licensed account variable. If the value is false, then a message is printed to the terminal window. Finally, the function returns the value of the is licensed account variable. You can now press F7 to compile your code and return to the Meta trader by pressing F4. Conclusion: This MQL5 code is used to verify if an account number is true or false. It does this by comparing the account number to a predetermined number and then returning a boolean value of true or false depending on the result of the comparison.
Okay, so far so good. If everything worked out as it should, you should now be able to run the expert advisor on the correct account. So let’s change that here. I will stop the strategy tester. Let’s pick the right account here, restart the test, and now we get the output, the account number is true. And in this little video, you have learned how to hard code an account number into your expert advisor to make sure that it is not used by anybody else. Thank you for watching and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – SIMPLE ACCOUNT CHECK appeared first on MQL5 Tutorial.
LEARN THE WHILE LOOP HERE
The while function in MQL5 is an incredibly powerful tool for algorithmic trading. It allows traders to create automated trading strategies that can be executed with minimal manual intervention. The while loop is a fundamental building block of algorithmic trading, allowing traders to create complex trading strategies and automate them with ease.
The while loop is a type of looping construct that allows a program to execute a set of instructions multiple times. In MQL5, the while loop is used to create a loop that will execute until a certain condition is met. The condition can be anything from a certain price level being reached to a certain number of trades being executed. Once the condition is met, the loop will terminate and the program will continue.
The basic syntax of a while loop in MQL5 is as follows:
while (condition)
{
// code to execute
}
The condition can be any valid MQL5 expression, such as an equality comparison or a logical expression. For example, a while loop could be used to execute a set of instructions until a certain price level is reached. In this case, the condition would be something like “Price > 10.00”.
In addition to the basic while loop, MQL5 also provides a few additional features to make it easier to create more complex trading strategies. For example, the break and continue statements can be used to control the flow of the loop. The break statement will terminate the loop immediately, while the continue statement will skip the rest of the loop and continue to the next iteration.
Another useful feature of MQL5’s while loop is the ability to use nested loops. Nested loops allow a program to execute multiple loops within a single loop. This can be used to create complex trading strategies that involve multiple conditions and multiple actions.
Finally, MQL5 also provides a few additional features to make it easier to debug and optimize trading strategies. For example, the loop counter can be used to monitor the number of iterations that have been executed, and the loop time can be used to measure the amount of time taken for each iteration. This can be useful when trying to optimize a trading strategy for speed and accuracy.
In conclusion, the while function in MQL5 is an incredibly powerful tool for algorithmic trading. It allows traders to create automated trading strategies that can be executed with minimal manual intervention. The while loop is a fundamental building block of algorithmic trading, allowing traders to create complex trading strategies and automate them with ease. With the additional features provided by MQL5, such as break and continue statements and the ability to use nested loops, traders can create even more sophisticated trading strategies.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – WHAT THE WHILE LOOP CAN DO appeared first on MQL5 Tutorial.
In this video we are going to create buy and sell signals and code a standalone version that is able to calculate this one line from the Ichimoku Kinko Hyo, it’s called a Tenkan-sen, that’s the red line here.
Now we want to find out how to do that in MQL5?
To do that 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/ Expert Advisor (template)” from template, “ Continue”, I will call this file: “SimpleTenkansenStandaloneEA”, click on “Continue”, “Continue” and “Finish”.
Now you can delete everything above the “OnTick” function and the two comment lines here.
We start with the “include” statement to include the file “Trade.mqh”, that comes with MQL5 and we need it to create an instance of “CTrade” that will be called: “trade” and we will use it to open and close positions later on.
We start by calculating the Ask price and the Bid price, this is done by using “SymbolInfoDouble” for the current symbol on the chart, we use “SYMBOL_ASK” to calculate the Ask price and “SYMBOL_BID” to calculate the Bid price.
“NormalizeDouble” and “_Digits” will automatically calculate the right number of digits behind the dot.
Next we need to create a signal variable for the signal that also will be called: “signal” and we don’t assign a value here.
We use “MqlRates” to create a price array called: “PriceInformation”, that one will contain the prices of the candles, we use “ArraySetAsSeries” to sort the array (PriceInformation) from the current candle downwards and with “CopyRates” we fill the price array (PriceInformation) with data for the current symbol on the chart and the currently selected period on the chart. We start from the candle 0 (zero) and copy the price information for 3 candles into our price array (PriceInformation).
For the Tenkan-sen we need to create another array and we use the MQL5 function: “iIchimoku”, this one can calculate the Tenkan-sen, the Kijun-sen, the Senkou Span depending on the index buffer that we use, buffer 0 (zero) is for the Tenkan-sen, buffer 1 is for the Kijun-sen and so on.
For the parameters we use the current symbol, the currently selected period on the chart, here we have three more values; 9, 26 and 52 and when we click on: “Insert/ Indicators/ Trend/ Ichimoku Kinko Hyo” we will see the same values here so that’s how we use them. 9 is for the Tenkan-sen, 26 is for the Kijun-sen and 52 is for the Senkou Span B.
In our example we only calculate one of them; that’s the Tenkan-sen, so let’s use “ArraySetAsSeries” to sort our Tenkan-sen array (TenkansenArray) from the current candle downwards and with “CopyBuffer” we fill our Tenkan-sen array (TenkansenArray) according to the Ichimoku definition (IchimokuDefinition) that we have created here for buffer 0 (zero), we start with the current candle 0 (zero) and we use the data for 3 candles.
Now we can calculate the Tenkan-sen value (TenkansenValue) by looking at candle 0 (zero) in our “TenkansenArray”.
For our simplified example we would say that whenever the value is above, so the “ThenkansenValue” would be greater than the close price for candle 1 in our “PriceInformation” array, we would consider that to be a sell signal and so we assign the word: “sell” to or signal.
In the other case if the “TenkansenValue” is below the “PriceInformation” close price for candle 1 we would consider that to be a buy signal and now we would assign the word: “buy” to our signal.
And when the signal equals sell and we have no open positions that’s when we would use “trade.Sell” to sell 10 micro lot, otherwise if the signal equals buy and we have no open positions we would use: “trade.Buy” and buy 10 micro lot.
We finish by creating a chart output using the “Comment” function to output the text: “The current signal is:” followed by the calculated “signal”.
Now this is only one of several values that you could calculate for this Indicator, you can spend hours to learn how to read it and there are also several interpretations but in our simplified case we just go with the red line here so when you are done you can click on the “Compile” button or press F7, that should work without any errors here and if this is the case please click here or press F4 to go back to Metatrader.
When inside of Metatrader we click on; “View/ Strategy Tester” or press CTRL and R, here we select the: “SimpleTenkansenStandaloneEA.ex5”, please enable the visualization option and start your test.
…and here we are! We have a buy signal right now and whenever the price crosses the red line that would switch to a sell signal.
Now you know how to calculate the Tenkan-sen value for the Ichimoku Kinko Hyo Indicator, it’s also possible to calculate all the other values here and create specific rules but now you know how to automate the Tenkan-sen and you have coded it yourself with a few lines of MQL5 code.
Download “MQL5 Tutorial - Simple Tenkansen Standalone Expert Advisor”
SimpleTenkansenStandaloneEA.txt – Downloaded 223 times – 1.83 KBNot sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE TENKANSEN STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
This video is about the result of 197 days in real trading. Today is February 3, 2023 and I wanted to contribute to the result of my system and have just accidentally started here again a new trade. We will now close the trade because actually I have already reached my goal on the 1 February 2023. The goal with the whole action was to close the system with 10% profit. If you take a look at this, we just crossed $11,000. And here in the the order history you can see that I deposited $10,000 at was as far as I can remember, on July 18 and in fact I exceeded my own profit goal on February 1.
This is the corresponding statistic on my website and if you click here you can have a look at the exact statistics of all data of this system on the FX Blue website. Here one can represent the whole again as total profit. On February 3, just now, I closed the last trade and the first position was opened on July 18, 2022. Overall we have a growth of 10.0% with a monthly growth of 1.4%. The system closed only 68% of all positions in profit and on average we made twelve trades per day over a period of 199 days. Actually, this would only be 197 days if I hadn’t accidentally opened a position when I started this video.
If we take a calculator to help us here and divide the 10% by 197 days and multiply by 365, then we would come to a growth of 18.5% annually. What I find interesting is the equity issue, because here you can see quite well that over the period we traded most of the time the equity was very close to balance. That means we had little drawdowns in the analysis. You can see that we traded exclusively with the Euro US dollar. That was 2408 orders, a gross profit of over $2,000, a gross loss of $1,112 and that results in a total profit of $1,001.28 with a profit factor of 1.9. Here are some additional statistics.
For example, the average trading time in hours. This one is an outlier at 334.9 hours. But on the whole you can say that the vast majority was under 100 hours. fxblue statistics here show a total loss risk of 0%. And you can look at 100 more statistics here. Whoever is interested in it can do that here on the FX Blue side or call the webpage PlatinSystem.com. This is currently redirected, but also here you can have a look at the statistics. And here below is somewhere still the playlist linked. For DSGVO, you have to enable the YouTube content here, but then you can have a look at the playlist. This is the video from day one.
All in all, I documented this a little bit and I’ll add this video in there right now. Personally, I’m very happy with the results and now I’m moving on to the next system.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – SIMPLY GOOD PLATIN SYSTEM RESULTS (TO ANALYZE AND RETRADE) appeared first on MQL5 Tutorial.
The “Comment” function in MQL5 is a powerful tool for displaying information on a chart in the MetaTrader 5 trading platform. This function allows a programmer to add a text message to a chart, which can be used to display important information such as the current market conditions, the status of a trading strategy, or any other information relevant to the trades being executed.
Using the Comment function is straightforward. Simply type the function name followed by the text message you want to display, and it will be added to the chart. For example:
Comment(“The market is currently in a bullish trend”);
This will display the message “The market is currently in a bullish trend” on the chart. It is important to note that the Comment function can only be used within the context of an MQL5 script or expert advisor.
One of the benefits of using the Comment function is that it allows you to keep track of important information while executing trades. For example, if you are running a trading strategy that relies on the market being in a bullish trend, you can use the Comment function to display this information on the chart. This can help you make informed trading decisions and stay focused on your goals.
Another benefit of the Comment function is that it can be used to display information about the current state of your trades. For example, you could use the Comment function to display the status of each open position, including the entry price, stop loss, and take profit levels. This information can be valuable for monitoring the performance of your trades and making adjustments as needed.
Overall, the Comment function is an essential tool for any MQL5 programmer. Whether you are a seasoned trader or just starting out, it can help you keep track of important information and make better trading decisions. With its simple syntax and powerful capabilities, the Comment function is an essential tool for anyone looking to automate their trading activities in the MetaTrader 5 platform.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL EXAMPLES – THE COMMENT COMMAND appeared first on MQL5 Tutorial.
In this video we are going to create an Expert Advisor that is going to output buy or sell signals based on the SMA (Simple Moving Average) here, it’s a Moving Average signal that is created for 50 candles, this one is the current signal and this one is the signal predicted into the future and whenever those two lines cross we either get a buy or a sell signal.
When the future SMA is below the other one, we have a buy signal and when the current SMA crosses the future SMA and is below it – like here – we have a sell signal.
To create the Expert Advisor 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, please click on “Continue”, I will call this one: “SimpleShiftedSMA”, click on “Continue”, “Continue” and “Finish”.
Now we can delete everything above the “OnTick” function and the two comment lines here.
We start by creating a string for the signal, this one will also be called: “signal” and we don’t assign a value right now because this one needs to be calculated later on.
Let’s create two arrays; one for the current Moving Average and one for the shifted Moving Average, afterwards we define the properties for the Moving Average by using the built in “iMA” function that comes with MQL5 for the current symbol on the chart and the currently selected period, the calculation will be based on 50 candles, here we use a shift value of 0 (zero), the calculation will be for an SMA so we use “MODE_SMA”, that stands for Simple Moving Average and the result will be based on the close price.
The second calculation looks almost like the first one, we have two differences here; the first difference is that this one is for the shifted average definition (ShiftedAverageDefinition) and the second one is that we use a shift value of 20 here, this will move our SMA 20 candles into the future, so when we pass this you will see that this is the current candle, this is the current value and this one is the predicted value that is shifted into the future.
For both of our arrays we use “ArraySetAsSeries” to sort the current array from the current candle downwards here for the Moving Average array (myMovingAverageArray) and here for the shifted average array (myShiftedAverageAttay) and with “CopyBuffer” we fill our array according to the definition that we have created here for the current buffer 0 (zero) – that’s the first line for our Indicator – from the current candle 0 (zero) for 3 candles and we store the result in our Moving Average array (myMovingAverageArray).
For the shifted average it’s the same, the only difference is that the value will be stored in the shifted average array (myShiftedAverageAttay).
To get both values we look at candle 0 (zero) either in the Moving Average array (myMovingAverageArray) or in the shifted Average array (myShiftedAverageAttay) and if the average array value (myMovingAverageValue) is above the shifted average array value (myShiftedAverageValue) we would assign the word: “buy” to our signal.
In the other case if the average array value (myMovingAverageValue) is below the shifted average value (myShiftedAverageValue) that would be a sell signal so now we assign the word: “sell” to our signal.
Last but not least we use the “Comment” function to output the words: “The current signal is:” followed by our current “signal” directly on the chart.
Okay, when you’re done you can click on the “Compile” button or press F7, that should work without any errors and if that is the case you can click here or press F4 to go back to Metatrader and in Metatrader we click on: “View/ Strategy Tester”, here we pick the file: “SimpleShiftedSMA.ex5”, mark the visualization option and start our test.
…and here we are, currently we have an uptrend, the shifted value is below the current value so that’s a buy signal and as soon as we see a crossover here – like right now – we get a sell signal. So now you know how to create an Expert Advisor that is going to calculate a shifted SMA value and you have coded it yourself with a few lines of MQL5 code.
Download “MQL5 TUTORIAL - SIMPLE SHIFTED SMA STANDALONE EXPERT ADIVSOR”
SimpleShiftedSMA.txt – Downloaded 169 times – 2 KBNot sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE SHIFTED SMA EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video we are looking at this little Indicator, it’s the Onbalance Volume Indicator.
Investopedia (www.investopedia.com) says that the Onbalance Volume should show us that whenever the Indicator increases without a significant price change the price should follow and now we are going to find out how to automate the Onbalance Volume Indicator in MQL5.
To do that please click on a little button here or press F4 in your Metatrader, now you should see the Metaeditor window and here we click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “SimpleIOBValue”, 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.
This is a very simple Indicator, we start by creating an array for the Expert Advisor (EAArray), this one will be a double array so it can hold floating type values, now we use “ArraySetAsSeries” to sort the array (EAArray) from the current candle downwards and to define the Onbalance Volume we use the included function that is called: “iOBV”, so let’s mark that and press F1, here we see that it uses the current symbol on the chart, the currently selected period on the chart and the third parameter is called: applied volume so let’s click on this link and we see that we could use the tick volume or the real volume. In our case we use “VOLUME_TICK”.
Now we use “CopyBuffer” to fill our Expert Advisor array (EAArray) according to the IOBV definition (IOBVDefinition) that we have created here for the first buffer… well, a buffer is in our case this line here, some Indicators have more than one buffer for example if I would “Insert/ Indicators/ Trend/ Bollinger Bands”, this one has three different lines, so it uses 3 buffers and the first buffers is always called buffer 0 (zero), the second buffer would be number one and so on. That’s because arrays are zero based in MQL5 so the first item in an array is always called by calling the index zero.
Let’s copy the data for 3 candles and the result will be stored in our EA array (EAArray).
To calculate the current Onbalance Value (IOBVVALUE) we now need to look at the value for candle 0 (zero) in our EA array (EAArray), remember this one is the current candle so this would be candle 0 (zero), candle 1, candle 2, and so on.
Finally we want to create a chart output that’s done with the “Comment” function and it will output the words: “The IOB Value is:” followed by the calculated value, so let’s compile that and this worked without any errors, we only have a minor warning – you see the little triangle here – I have used an int value, let’s try double recompile the code and now the warning is gone, so now that everything is finished we can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader we click on: “View/ Strategy Tester”, I select a new file: “SimpleIOBValue”, mark the visualization option here and start a test.
…and here we are, this is the value and it’s also drawn on the chart here as you can see, it has one digit behind the dot and this digit is always zero so if I use an integer here recompile the code I will get the warning again but when I restart the test you will see that the digit and the dot are gone, I prefer it this way.
…and now you know how to calculate the Onbalance Volume and you have coded it yourself with a few lines of MQL5 code.
Download “MQL5 TUTORIAL - SIMPLE ONBALANCE VOLUME EXPERT ADVISOR”
SimpleIOBValue.txt – Downloaded 147 times – 580 BNot sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE ON BALANCE VOLUME appeared first on MQL5 Tutorial.
A sell stop is an order that has been placed into the market and that will be triggered whenever the price is falling below the price level that we have defined, this one has already been triggered, so let’s see if we can create another one. Here you see that we have placed a sell stop order and as soon as the price reaches the price level that we have defined a sell position is opened.
Now how can we create an Expert Advisor that is able to place such a sell stop?
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 file: “SimpleSellStop”, click on “Continue”, “Continue” and “Finish”.
Now we can delete everything above the “OnTick” function and the two comment lines here.
We are going to start by using the “include” statement to include the file “Trade.mqh”, this one comes with MQL5 and we use the included “CTrade” class to create an instance that will be called: “trade” and we are going to use it to open our sell stop later on.
Inside of the “OnTick” function we get the Bid price, that is done by using “SymbolInfoDouble” for the current symbol on the chart, we use “SYMBOL_BID” to get the Bid price and with “NormalizeDouble” and “_Digits” we make sure that we calculate the right amount of digits behind the dot, that could be 3 digits like for this currency pair or 5 digits like for this one.
Let’s get the account balance by using “AccountInfoDouble”, “ACCOUNT_BALANCE” and we also want to calculate the equity by using “AccountInfoDouble” ,“ACCOUNT_EQUITY”, so if you mark “AccountInfoDouble” and press F1 you will see examples and here are all the values that you could use. This is all account related information.
Now If we have no open positions and no open orders, so if “PositionsTotal” equals 0 (zero) and “OrdersTotal” also equals 0 (zero) we want to open a new order for a sell stop for 10 micro lot. The difference between a position and the order is that a position is something that has already been triggered, so this is a sell position but when the position is closed we place an order below the current price level and as soon our order is triggered it becomes a position.
To do that we use “trade.SellStop” to open an order for 10 micro lot, 100 points below the current price level, we don’t use a stop loss here and the take profit should be 300 points below the current Bid price, the last parameters here are used to set an expiration or a comment but we don’t need that.
Instead we use the “Comment” function to output the current balance and the current equity directly on our chart.
Okay, that’s it. Please click on the “Compile” button or press F7, and if you don’t have any errors here please click here or press F4 to go back to Metatrader.
Now in Metatrader we click on; “View/ Strategy Tester” or we press CTRL and R, let’s pick the new file here: “SimplesellStop.ex5”, mark the visualization option and start your test.
…and here we are! This is our sell stop and it will be triggered as soon as the price level drops below this line here, that has happened now and here is our first open position.
Now you know how to code an Expert Advisor that is going to create automated sell stops and you have done it yourself with a few lines of MQL5 code.
Download “MQL5 TUTORIAL - SIMPLE SELL STOP EXPERT ADVISOR”
SimpleSellStop.txt – Downloaded 17 times – 718 B
Not sure what to do? Click on the automated trading assistant below
The post MQL5 Tutorial – Simple Sell Stop Expert Advisor appeared first on MQL5 Tutorial.
REAL RESULTS FOR 2022: Right now it is Friday evening and it is the last Friday of the year 2022.
I have just adjusted my Platin System Live Trading accounts to not open any further positions after the current one, because I wanted to show you real results and statistics.
If you visit the Website fxblue.com for the account number 37044019, you will see that the current balance for this account is $10856. The current equity is also $10856.
That means that Equity and Balance are equal and there are no open losses.
The account was traded for 166 days in a row and the return of investment is 8.56 percent, because the initial investment was $10000.
That means that the annual return would be 8.56 percent divided through 166 days and multiplied by 365 days, so the yearly return would be 18.82 percent.
Well I have just googled the results for the best and most known trader in the world which is Warren Buffet.
I have opened Google and I have used the search term “Warren Buffett average annual return”.
According to the most optimistic Google results Warren Buffett has made 29.5 percent a year, even in good times.
Please do your own research and make your own conclusions.
But Warren Buffet has over 60 years of experience, one of the biggest companies in the world and can pay for the best technology and advice in the world with a fraction of the change money that is available.
Most of us do not have this ability.
We have to achieve our own results with the resources that are available to us.
We are not the owners of Berkshire Hathaway.
We don’t have business partners and friends like Bill Gates.
We are not able to spend a few hundred thousand dollars for the best technology and the best advice in the world.
But we have the ability to use automated trading systems and achieve results on our own.
Even in a pandemic situation.
Even in a recession.
Even in times where war is breaking out in several areas.
So, at the end of the year 2022, I would like you to check those results and make your own conclusions.
I think nothing can replace self-made insights, because nobody needs to convince you of your own conclusions.
Personally, I have done this and I have seen hundreds and hundreds of course members since 2014 doing this.
I am convinced that it is possible to achieve good results with automated trading systems, because I have done it and I have seen other people do it.
But I am also convinced that it is not possible for everybody.
You need to be able to do what it takes and that includes to endure bad emotions and resist the temptation to manipulate your own system to feel better.
Some people can do that, others can’t.
But it is possible to train to get better and only 2 out of 10 people are willing to really do what it takes.
At the end of the day, or in this case, at the end of the year it is your own choice.
It is possible to do it, you can check the results.
It is probable to do it if you can stick to the rules.
But if you can do it, that is a question of if you are willing to invest the time, effort and money it takes to become the person in front of the screen that can actually do it.
This is the key to better or worse results and you are the one who can prove that you have what it takes to make it possible for you.
Not sure what to do? Click on the automated trading assistant below
(Coupon Code PLATINSYSTEMDEMO)
After we all have heard songs from Mariah Carey and George Michael about what they want for Christmas, there is this special time that Germans call “between the years”. That is when most traders want to buy themselves a Christmas present that actually will improve their results.
That is when the TV stations start to show the summary of what happened in the last year. That is when we step on the scale and it shows that we gained a whopping 5 pounds or so within three days.
And just a few days later, everybody is going to sign a gym contract to get fit for the next year. I think people spend a lot of money for New Year’s resolutions because it actually feels like “it” is really going to happen. January seems the month when we all desperately want to change our life. We want to train for the next season. And now you can do that for automated trading without any further cost.
Just use the coupon code below this video and get started with a demo version. No cost, no obligation, no time restrictions. The only catch is that it will only work with original Metaquotes demo accounts. You don’t need to wait to get started on the 1 January 2023.
You can start right away. So put on your trading sneakers, get the Platinum System demo version and the demo course today and get fit for 2023.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – FREE TRADING TRAINING FOR 2023 appeared first on MQL5 Tutorial.
If you have been trading for a while, chances are high that you have used or maybe you have seen a moving average.
This is a moving average and it is a line and you can use it to find out if the current price is above or below the average value of a particular number of candles.
This is a moving average for the last twenty candles and if you right click on it, you can change the properties here.
So let’s change the period to one and now you see that the moving average for one candle is connecting all the closed prices.
This is a bearish candle so it closes here. This is a bullish candle so here is the closing price.
Let’s look again at the properties and select one hundred and now you don’t even see the moving average because it’s far above the candles.
As traders we use moving averages to find out if it’s going down and that would be the case when the current prices crosses the moving average from the above.
Or if it’s going up and that would be the case when the current price crosses the moving average from below.
Now how can we create an Expert Advisor for this? Now if you point your mouse on any point of the moving average, you will see a value and you will see that the value would change with very candle.
Here it is 0.988749 and the closing price is 0.98848.
So let’s create an Expert Advisor for that, to do that please hit this little button here or press the F4 key to bring up the Meta Editor.
Now you need to click on new Expert Advisor from template, continue. We will give it the name simple moving average, continue, continue, finish and remove everything above the OnTick function.
Let’s remove the two comment lines and the first thing we need is an array to hold our price values.
So we will create an array with the name my moving average array and in the next step we need to define how the moving average should look like.
We want to give it the name moving average definition and it should be for the current symbol on the chart and for the current used period on the chart.
I would like to use the last twenty candles for the calculation. I don’t want to shift it to the right or to the left direction and it should be a simple moving average.
That’s what MODE_SMA does for closed price of the candle.
Now that we have defined how our simple moving average should look like, we need to sort the price range from the current candle downwards.
This is done with arraysetasseries, we do it for the moving average array.
And now we want to fill it with prize data, that is done with copy buffer for the defined EA moving average definition.
It has only one line so we places a zero here, we want the current candle, this is another zero and we want to copy the prize for three candles so let’s put in a three.
And MQL 5 should store the results in the my moving average array. So let’s calculate the current value by assigning the value of my moving average array for the current candle to the my moving average value and the last thing we want to do is to output the current EA on the chart so we use the comment function to print out the text moving average value and the calculated value we created here.
Okay let’s compile the Expert Advisor, click this little button or hit the F4 key.
And now we want to do a little trick, we now want to insert an indicator for the trend and it should be a moving average and for our calculation we use the twenty candles period, a shift value of zero.
It should be a simple moving average and it should be applied to the close price. This is the color I want to choose for the A and I want to have these kinds of lines.
So let’s click on okay and here is our visual representation.
Now we right click on the chart, go to templates and save the template as tester.tpl because this is the template the Strategy Tester is going to use, when we test our little Expert Advisor.
Bring up the Strategy Tester by choosing it from the menu or clicking control and R, select the simple moving average.ex5 file, mark the visualisation option and start the test.
And here is how it looks like.
Let’s pause the test here and our calculated value is 0.993984 and this is exactly what the current Expert Advisor value for the moving average on a chart currently is.
Continue, now it’s 0.994416, well let’s check the current value here and it’s 0.9994416. So it works!
Now you know, how you can calculate the current moving average by creating this little Expert Advisor.
Download “MQL5 Simple Moving Average Expert Advisor from MQL5 Tutorial”
SimpleMovingAverage.txt – Downloaded 605 times – 769 BNot sure what to do? Click on the automated trading assistant below
The post MQL5 Tutorial Classics – Simple Moving Average Robot with MQL5 appeared first on MQL5 Tutorial.
In this little video, we are going to calculate an entry signal for this Oscillator that is called the DeMarker Oscillator. It is not so well known, but we will create an entry signal for it. So let’s see how we can do that with MQL5.
A separate window below the candle chart shows the Demarker oscillator.
It has a scale and two lines.
Most of the time, oscillators are used to filter other signals, but they can also be used to make entry signals, which is what we’ll do here.
To use it, we need to create a separate MQ5 file and put it in the same folder as the other Platin System files.
CheckEntry iDEMARKER mq5 is the name of the file, and CheckEntry is the only function it has.
It will figure out what our entry signal is and send that info back to the main module.
We want to make a string variable for the calculated signal, but we won’t give it a value yet because that will be figured out later.
We need a price array. Please choose the type double as it can hold floating type values.
MQL5 includes a function called iDEMARKER that we can use to define our oscillator.
A few parameters need to be set. The first parameter is the chart’s symbol. The period on the chart is the second parameter.
And the last parameter is used for the number of candles we want to use for our calculation.
When you drag the Demarker oscillator onto one of your charts, you will also see these values.
Now we use array set as series to sort the array that we have created from the current candle 0 downwards.
With CopyBuffer, we put data into the array. We do it according to our definition from above and calculate values for buffer 0, beginning with the current candle 0 and the next three candles.
Let’s keep going and figure out the current candle’s value by looking at the value of candle 0 in our array. With Normalize Double we can format the value to show 3 digits behind the dot.
To figure out when to buy, we look for a value that is below the lower line. That would be the case then it is below 0.3 !
So it would be a buy signal, and when that happens, we give our signal the word “buy.”
Otherwise, if the value is above 0.7 or above the upper line of the oscillator scale that would be a sell signal, so we put the word “sell” into our signal.
At the end of the function, the signal is sent back to the main module using the return command.
Please don’t forget to save the file!
You don’t need to compile it right now. Just save it and go back to where the OnTick function is in the main module.
There, you need to add the new file to the section that contains the include statements. Using the include statement, followed by the name of the file we have created.
Please use two slashes to comment out any other entry signals, and press F7 or click the Compile button to compile both the main module and the new entry file you just made.
Okay, I hope that the compilation process has worked for you. You should now be able to use the DeMarker Oscillator either as an entry signal or as a filter.
Thank you for watching this video, and I will see you in the next one.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – DEMARKER OSCILLATOR appeared first on MQL5 Tutorial.
In this video we are going to calculate this little red line here. It is called the double exponential moving average, and we will now create an entry module to calculate buy and sell signals.
This time, we’re going to figure out the IDEMA indicator and use it to calculate a trading system entry signal.
The IDEMA indicator is painted right on the candle chart, and it shows up as a red line. If you point your mouse cursor over it, you will see that it creates a double exponential moving average.
To start, we make a new file called CheckEntry IDEMA and put it in the same directory as the other system files.
The new file will use a function called CheckEntry, and we’ll make a variable called signal that will be used to return our calculated signal at the end of the function.
We’ll also need an array to store price information for a few candles.
Now, we use Array set as Series to sort our array starting with the current candle and going down.
With copy rates we fill our price array with data.
We do it for the current symbol and the currently selected period, starting from the current candle 0 and copy the data for 3 candles to store them in our price array.
For the indicator we need a new array that we also need to sort downwards by using array set as series.
Let’s keep going and define what our function is. For this, MQL5 has a built-in function called IDEMA.
There must be 5 parameters defined. The first two are for the current symbol and period on the chart, and the third is for the calculation period. It is 14 in our case.
Parameter 4 is for a potential candle shift, we set it to 0.
And the last parameter defines that we are going to calculate the result based on close prices.
With copy buffer we can now fill our Array with price data according to our definition. We do that for buffer 0, starting from the current candle and store the prices for 3 candles.
Afterwards, you can now get the value for the current candle by looking at that price array and, in particular, the value for candle 0.
We can now figure out the buy signal.
When the red line is below the close price for candle 1, we want to use that as a sign to buy.
So let’s give our signal the word “buy.”
In the other case, we want to sell whenever the red line is above the close price of candle 1.
At that point, we want to give the signal variable the value “sell.”
At the end of the function, please use the return function to send the calculated value back to our main module.
The entry module is now finished. Save it right away.
Then you need to open the main file and look for the part where you need to add the entry signal.
You can do that by putting the file name for our entry signal after the include statement.
Please disable any other entry signal by putting two slashes in front of it.
When you’re done, you can compile the main module and the entry module you just made by pressing F7 or clicking the compile button.
If everything went well, you shouldn’t get any errors!
If you do, please look at the error messages and try to figure out what they mean.
On MQL5.com, you can find a list of all of these error codes.
Okay, by now you should have a working for the double exponential moving average indicator that we see on our chart. I would like to say thank you for watching this video and I will see you in the next one.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – IDEMA INDICATOR appeared first on MQL5 Tutorial.
In this video, we are going to create an entry signal for the bolts Power Oscillator. It looks very similar to the Bears Power Oscillator that we have created before. And it’s similar to do. So let’s find out how to do it with MQL5.
This time, we’re going to figure out the Bulls power oscillator and use it to make a trading system entry signal.
The Bulls Power is shown below the candle chart, and it shows numbers that are either above or below 0.
To start, we make a new file called CheckEntry BullsPower and put it in the same directory as the other system files.
The new file will use a function called CheckEntry, and we’ll make a variable called signal that will be used to return our calculated signal at the end of the function.
We’ll also need an array to store price information for a few candles.
Now, let’s keep going and define what our oscillating function is. For this, MQL5 has a built-in function called iBullsPower.
There must be three parameters. The first two are for the current symbol and period on the chart, and the third is for the calculation period. It is 13 in our case.
Then, we use Array set as Series to sort our array starting with the current candle and going down.
Now we can use CopyBuffer to add data to our array.
We do it for the definition we just made and for buffer 0!
We want to start with the current candle 0 and copy the price data for the next three candles.
Our price array holds the result.
And because of that, you can now find the value for the current candle by looking at that price array and, in particular, the value for candle 0.
We can now figure out the buy signal.
When the Bulls power value is greater than 0, we want to use that as a sign to buy.
So let’s give our signal the word “buy.”
In the other case, we want to sell whenever the value is less than 0.
At that point, we want to give the signal variable the value “sell.”
At the end of the function, please use the return function to send the calculated value back to our main module.
The entry module is done, now. Save it right away.
Then you need to open the main file and look for the part where you need to add the entry signal.
You can do that by putting the file name for our entry signal after the include statement.
Please remove any other entry signal by putting two slashes in front of it.
When you’re done, you can compile the main module and the entry module you just made by pressing F7 or clicking the compile button.
If everything went well, you shouldn’t get any errors, just some warnings!!
Okay, that’s it for the Bulls Power Oscillator. Smart idea to do two Oscillators that look almost exactly the same. Thank you for watching this video. I will see you in the next one.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – BULLS POWER OSCILLATOR appeared first on MQL5 Tutorial.
In this video, we are looking at the Bears Power Oscillator. That’s the little Oscillator here below the candle chart. So let’s find out how to create an expert advisor entry signal for this Oscillator.
This time we want to calculate the bears power oscillator and use it to create an entry signal for your trading system.
The Bears Power is shown below the candle chart and it creates values that are either above or below 0!
To get started, we create a new file called CheckEntry_BearsPower in our directory where the other system files are already stored.
The new file will use a function called CheckEntry and we create a variable called signal that will be used to return our calculated signal, at the end of the function.
And, of course, we also need an array to hold price data for a few candles.
Now let’s continue and create a definition for our oscillating function. MQL5 offers an integrated function for that called iBearsPower.
Three parameters are required. The first two are for the current symbol and period on the chart, the third one is for the calculation period. In our case it is 13.
Afterwards we use Array set as Series to sort our array from the current candle downwards.
And now we can fill our array with data by using CopyBuffer.
We do it for the definition that we have created a minute ago and for buffer 0!
We want to start with the current candle 0 and copy price data for 3 candles.
The result is stored in our price array.
And that makes it possible to now get the value for the current candle by looking into that price array and especially at the value for candle 0!
Now we can calculate the buy signal.
Whenever the bears power value is above 0 we want to use it as a buy signal.
So let’s assign the word buy to our signal.
In the other case, we want to sell whenever the value is below 0!
That is when we want to assign the word sell to the signal variable.
And now please use the return function to return the calculated value to our main module at the end of the function.
That’s it for the entry module. Please save it now.
And afterwards you need to open the main file and look for the part where the entry signal now needs to be included.
You can do that by using the include statement followed by the file name for our entry signal.
Please outcomment any other entry signal by adding two slashes.
When you are finished, you can press F7 or click the compile button to compile the main module and the entry module you have just created!
If everything went well, you should not get any errors!
If you do, please check out the error messages and what they mean!
On MQL5.com there is a list of those error codes available!
Okay, by now, you should have a working version for the Bears Power Oscillator. I would like to say thank you for watching this video and I will see you in the next one.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – BEARS POWER OSCILLATOR appeared first on MQL5 Tutorial.
In this video, we are going to create an entry module for this oscillator here. It is called the Chaiken oscillator. So let’s find out how we can code an entry module. The chaikin oscillator is usually used to confirm other signals, because it is an oscillator. But in this example we will use it to generate buy and sell signals! Let’s create a new file called CheckEntry_Chaikin.mp5 in the same directory where the other files are stored. Like we have done for other entry modules we need to create a function called CheckEntry. The signal is later returned by this function. And now we need a string variable and a price array! MQL5 comes with a function called iChaikin that we can use to create our definition for the calculation. Parameter 1 is for the current symbol and parameter 2 for the current period on our chart. Afterwards we have two numbers! If you open Metatrader5 and select insert, indicators, oscillators, you will learn that these values are for the fast moving average and for the slow moving average. The standard values are 3 and 10! The following parameter is used to define that we want to calculate the result based on Mode_EMA, that stands for exponential moving average. And in the last parameter we have defined that the result should be calculated on the tick basis. Now let’s continue and sort the array from the current candle downwards by using array set as series. And then we use Copy Buffer to fill our array with data! We do it for the formerly created definition and buffer zero, starting from the current candle 0. We want to store the values for 3 candles in our array! Now we can calculate the values for the current candle and the one before. We do that by looking at the values of candle 0 and candle 1 in our array. If the current chaikin value is above 0 and the previous value was below 0, we consider that to be a buy signal and assign the word buy to our signal. Otherwise, if the current value is below 0 and the previous value was above 0, that will be a sell signal, so we assign the word sell to our signal. And finally we use the return function to return the calculated value to our main module. That is it for the entry, please do not forget to save it. Compiling is not required as it is imported into the main module. Now let’s open the main module and find the include section. There you can outcomment the other entry modules with two slashes and add a new include statement for the new file that we have created. And now we need to press F7 or click on the compile button to compile both modules. You will see some warnings, but you should not get any errors. Okay, so far, this is it for the Chaikin oscillator. I hope the compilation process worked for you. Thank you for watching, and thank you for watching, and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – CHAIKIN OSCILLATOR appeared first on MQL5 Tutorial.
In this video we are going to create an Expert Advisor for this signal here; it’s the Commodity Channel Index, and you see that we have already opened a position, it produces buy and sell signals here on the chart. Whenever the signal is below the lower line we are going to buy and when it’s above we are going to sell. Now how can we create an Expert Advisor in MQL5 that is actually able to trade the Commodity Channel Index? To do that please click on the 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/ Expert Advisor (template)” from template, “Continue”, I will call this one: “SimpleICCIStandaloneEA”, click on “Continue”, “Continue” and “Finish”, now you can remove everything that is above the “OnTick” function and let’s also delete the two comment lines here. First we want to include the file: “Trade.mqh”, it comes with MQL5 and it will help us to create an instance of the class “CTrade” that will be called: “trade” and we are going to use it to actually open positions later on but before we can do that we need to calculate a few things. For example the Ask price. We get that by using “SymbolInfoDouble” for the current symbol and with “SYMBOL_ASK” we will get the Ask price. “NormalizeDouble” and “_Digits” will help us to get the price with either 3 or 5 digits behind the dot depending on the currency pair. Let’s do the same for the Bid price, it’s almost exactly the same but this time we use “SYMBOL_BID”. Now we use “MqlRates” to create an array for the prices, we will call that:”PriceInfo” and we sort the array from the current candle downwards by using “ArraySetAsSeries” and we use “CopyRates” to fill our “PriceInfo” array with price data for the last candles. We will use the current symbol on the chart, the currently selected period and we will start with the prices for candle 0 (zero) – that’s the current candle – and we only need prices for 3 candles and store that result in the “PriceInfo” array. We also need to create a string for the signal that will be called: “signal” and it has no value right now because we are going to calculate that later on. We need to create another array, this time we will call it: “myPriceArray”. Well, this one was for the candle prices (PriceInfo) and the second one will be for the Expert Advisor (myPriceArray). Let’s define the Commodity Channel Index here (CCIDefinition), we are going to use the built-in: “iCCI” function for the current symbol and the current period on the chart, it will be calculated based on 14 candles – that’s also what you see if you click on: “Insert/ Indicators/ Oscillators/ Commodity Channel Index”, you see 14 candles – and our result will be calculated based on the close prices. Let’s sort the price array (myPriceArray) from the current candle downwards by using “ArraySetAsSeries” and with “CopyBuffer” we fill our price array (myPriceArray) according to the Commodity Channel Index definition (CCIDefinition) that we have created here for the first signal buffer, – that’s the line here – we start with candle 0 (zero) – that’s the current candle – and we copy the values of 3 candles and store it in our price array (myPriceArray). Finally we are able to get the value of the current candle by looking at candle 0 (zero) in our price array (myPriceArray) and the result will be stored in the variable called: ”CCIValue” and if the “CCIValue” is bigger than 100 – that would be the case whenever the blue line is above the upper dotted line, you see the 100 mark here – and if that is the case we want to sell so we assign the word: “sell” to our signal. Otherwise if the “CCIValue” is below the -100 (minus 100) line – that is the lower dotted line here – we want to buy so we assign the word: “buy” to our signal. And if the signal equals sell and “PositionsTotal” is less than 1 – with other words we wouldn’t have any open positions on the chart – we want to sell so we use “trade.Sell” to sell 10 micro lot. Otherwise if the signal equals buy and we have no open positions we want to buy so we use “trade.Buy” to buy 10 micro lot. Finally we create an output on the chart by using the “Comment” function, it will output the words: “The current signal is:” followed by the “signal” that we have calculated. Okay, that’s it so far, please click on the “Compile” button or press F7. We don’t see any errors here so now we can click on the little button here or press F4 to go back to Metatrader. In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, please select the “SimpleICCIStandaloneEA”, mark the visualization option here and click on start. Here we are! This is our first position, we can speed up the process a little bit and you see that it is creating buy and sell signals, we already have opened a position here and now you know how to create an Expert Advisor that is able to trade the Commodity Channel Index in MQL5 and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL- SIMPLE ICCI STANDALONE EA appeared first on MQL5 Tutorial.
This colorful indicator here below the chart window is called the awesome Oscillator. We want to create an entry signal to calculate the values for our entry signals that are traded here. So let’s find out how we can do that with MQL5. Since the Awesome indicator is an oscillator, it will be shown in a separate window below the candle chart. To use it, we make a separate MQ5 file and put it in the same directory as the other Platin System files. CheckEntry IAO.mq5 is the name of the file, and it only has one function called CheckEntry. The buy and sell signals for our system are worked out by this function. We start with a string variable called signal, but we don’t give it a value right away because we’ll figure that out later. The next thing we do is make an array. We use the “double” data type because it can also be used with “floating point” numbers. Then, we use the function iAO that comes with MQL5 to create a definition for the Awesome Oscillator signal. And we want to do that for the current symbol on the chart and the period that is currently selected on that chart. No further parameters are required. Now we use Array Set as Series for our IAO Array to sort it from the current candle downwards. Afterwards we can fill our IAO Array according to the definition that we have done above. We do it for buffer 0, starting from candle 0 for 3 candles and store the values in our price array. That makes it possible to calculate the current IAO Value by looking at candle 0 in our array. With normalize double, we make sure to format the output with 6 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 current value is above 0 we want to buy, so we assign the word buy to our signal. And when the current value is below 0, we want to sell so we assign the word sell to the signal. The last part is to give back the calculated value by using the return function and we also need to save the file. Compiling will be done in the main file, so please open it and look for the include statements that are already contained in the source code. There we will use two slashes to outcomment the other entry signals and add another line to include the new file called CheckEntry_ IAO.mq5. Afterwards we can click the compile button or simply press the F7 key to get both files compiled. A few warnings are expected, but you should not see any further error codes. Okay, by now, you should have a compiled version for this little oscillator here. You see that it’s creating lots of trades. And I would like to say thank you for watching this video, and I will see you in the next one.
Not sure what to do? Click on the automated trading assistant below
The post MQL5-TUTORIAL-PLATIN-SYSTEM-THE-AWESOME-OSCILLATOR appeared first on MQL5 Tutorial.
In this video, we want to check out this Oscillator here. It is called the Stochastic oscillator, and it is very popular. So let’s find out how we can create an entry signal for this one with MQL5. In this video, we’re going to make an entry signal for this little oscillator that an expert advisor can use. It’s called the “Stochastic oscillator,” and a lot of people use it. So let’s find out how MQL5 can help us do that. The Stochastic oscillator is shown in a separate window below the candle chart. It has two lines and a scale. Most of the time, oscillators are used to filter out signals, but they can also be used to make entry signals, which is what we’ll do here. To use it, we make a separate MQ5 file and put it in the same folder as the other Platin System files. The file is called CheckEntry Stochastic.mq5, and it has only one function called CheckEntry. It will figure out what our entry signal is and send that information back to the main module. We want to make a string variable for the calculated signal, but we won’t give it a value yet because that will be worked out later. Now we need two double-type arrays to hold the different prices. The first one is called the K-Array and the second one is called the D-Array. We sort both arrays from the current candle downwards by using Array set as Series. MQL5 comes with a function called iStochastic which we can use to create a definition for our oscillator. We need to pass a few parameters. The first parameter is for the symbol on the chart. The second parameter is for the period on the chart. Parameters 3, 4 and 5 are the standard values for the Stochastic oscillator to define the so-called K-period, the D-period and the slowing. You will also see these values when you drag the Stochastic indicator onto one of your charts. In the last two parameters, we define that we want to use MODE_SMA which stands for the simple moving average mode and we want to calculate the result based on the low and high prices. With CopyBuffer we fill both arrays with data and we do that for buffer 0 and buffer 1. In both cases from the current candle 0 and for 3 candles. Let’s continue and calculate the value for the current candle by looking at the value of candle 0 in both arrays. Afterwards we do the same for the candle before by looking at the values for candle 1 in both arrays. To calculate the buy signal, we check for a crossover. So if the K-value and the D-value for candle 0 are below 20, we want to know if the K-value is now above the D-value and if it was below for the candle before. That would be a buy signal and that is when we assign the word buy to our signal. Otherwise, if the K-value and the D-value for candle 0 are above 80 we want to know if the K-value is now below the D-value and if it was higher for the candle before. That would be a sell signal and that is when we assign the word sell to our signal. At the end of the function we use the return command to return the signal to the main module. Please remember to save the file. You don’t have to compile it. Just save it and go back to the main module, where the OnTick function is. There, you must add the new file to the include section. This can be done with the help of the include statement. Please use two slashes to outcomment any other entry signals and press F7 or click the Compile button to compile both the main module and the new entry file you just made. Okay, if everything worked out as it should, you should now have a working version for the Stochastic Oscillator. Please note that this one will not create so many signals, because it will only create signals when we see a cross over here. That’s it for now. Thank you for watching, and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – STOCHASTIC OSCILLATOR appeared first on MQL5 Tutorial.
This time we are going to calculate the Adaptive Moving Average Indicator; this is the red line you see on the chart. Whenever the candles are above the line we have a buy signal, otherwise if the candles are below the red line this is a sell signal. Now we are going to find out how to create an Expert Advisor in MQL5 that is actually going to trade the Advanced Moving Average. To do that please click on the little button here or press F4 in Metatrader and 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 file: “SimpleAMAStandaloneEA” (Expert Advisor), click on: “Continue”, “Continue” and “Finish”. Now let’s delete everything above the “OnTick” function and please also remove the two comment lines. We start by including the file: “Trade.mqh”, that file contains a few useful functions and now we can create an instance of “CTrade” that will be called: “trade” and we are going to use it to open positions later on. First we calculate the Ask price and the Bid price by using “SymbolInfoDouble” for the current symbol on the chart, “SYMBOL_ASK” will deliver the Ask price, “SYMBOL_BID” will deliver the Bid price and with “NormalizeDouble” and “_Digits” we automatically calculate the right number of digits behind the dot because this currency pair would have 3 digits while this one has 5 digits and this function (_Digits) is going to handle that. We create an array for the prices by using “MqlRates”, let’s call that array: “PriceInfo”, now we sort the price array (PriceInfo) from the current candle downwards by using the “ArraySetAsSeries” function, we use “CopyRates” to fill the array with price data for the symbol that is currently selected on the chart and the current period on the chart. We start with candle 0 (zero) for 3 candles. Candle 0 (zero) is the current candle. Let’s create a string variable for the signal, we will call it: “signal” and we don’t assign a value here that is going to be calculated now. We need another array (myPriceArray), this one for several prices that contain the Indicator values; the one here was just for the candle prices (PriceInfo). Let’s define the properties for the Adaptive Moving Average value (AdaptiveMovingAverageValue) that is done by using the “iAMA” – it’s an included function in MQL5 – once again for the current symbol and the currently selected period on the chart. You will see three values here; 9, 2 and 30 and when you right click the Indicator and select “Properties” you would see that is calculated for 9 candles, the “Fast EMA:” is 2, the “Slow EMA:” is 30 and the “Shift:” is 0 (zero), that’s exactly what we are using here and the calculation will be based on the close prices. Now let’s sort the second array from the current candle downwards, once again we use “ArraySetAsSeries”, with “CopyBuffer” we fill our price array (myPriceArray) according to the Adaptive Moving Average definition (AdaptiveMovingAverageDefinition) we have created here for the first buffer – that’s the first signal – from candle 0 (zero) for 3 candles and store the result in our price array (myPriceArray). To get the value for the current candle we just look at candle 0 (zero) in our price array (myPriceArray) and with “NormalizeDouble” and the 6 we calculate the current value, as you can see here it has 6 digits behind the dot and if the Adaptive Moving Average value (AdaptiveMovingAverageValue) is above the close price for candle 0 (zero) – that’s actually a shortcut for the current price because close prices are always the last price for a finished candle and candle 0 (zero) isn’t finished so the close price will deliver the current price here – and if this expression is true we want to assign the word: “sell” to our signal. In the other case if the Adaptive Moving Average is below the current price that’s a buy signal and now we assign the word: “buy” to our signal. And if the signal equals sell and “PositionsTotal” is below 1 – that means we don’t have any open positions – we use “trade.Sell” to sell 10 micro lot. Otherwise if the signal equals buy and we have no open positions we use “trade.Buy” to buy 10 micro lot. Finally we use the “Comment” function to create a chart output that will say: “The current signal is:” followed by the calculated signal. So far so good, please click on the “Compile” button or press F7. I don’t have any errors and I don’t have any warnings so now we can click here or press F4 to go back to Metatrader. In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, here we select the: “SimpleAMAStandaloneEA.ex5” file, enable the visualization mode here and start a test. …and here we are! Our Expert Advisor is creating buy and sell signals, we already have an open position here and in this little video you learned how to code an Expert Advisor that is actually going to trade the Adaptive Moving Average Indicator and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE AMA STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video, we want to create a file for the entry signal of this interesting indicator with the little dots here. This one is called the parabolic SAR. So let’s find out how we can calculate that with MQL5. This time we want to create an entry signal for an indicator that is painted right above or below the candles. It is called the parabolic SAR and you will see little dots above or below the current price. To get started, we want to create a new file called CheckEntry_SAR and save it in the same directory where the other files for the system are located. The file uses one function called CheckEntry to calculate the signal which will be returned to the main file at the end of the function. First we use MQLRates to create a price array. Then we use Array set as series to sort that price array from the current candle downwards. And with copy rates we fill the price array with data for the currently selected symbol on the chart and the period that we have selected on that chart. We want to start with candle 0, that is the current candle and copy price data for 3 candles. The price array will hold that data. So let’s create a signal variable that can hold text values, but don’t assign any values at this stage. And we need a second array for the indicator data. We use the function i-SAR for the symbol on the chart and the selected period for parameter 1 and 2. Parameter 3 is a so-called step value and parameter 4 is a maximum value. You will see the values 0.02 and 0.2 when you drag the Parabolic SAR indicator onto any of your charts. Now we use array set as series to sort the SAR array from the current candle downwards. And with copy buffer we fill the array according to the SAR definition that we have already created. We do that for buffer 0, starting from candle 0 for 3 candles. Now we can extract values from our array. In this case we are interested to get the value for candle 1. That will calculate the last value of the indicator. With NormalizeDouble and the number 5 we can format our output to show 5 digits behind the dot. And if the last SAR value was below the value for the lowest price of candle 1 in our price array, we want to buy and assign the word buy to our signal. Otherwise, if the last SAR value was above the value for the highest price of candle 1 in our price array, we want to sell and assign the word sell to our signal. Finally we use the return function to return the calculated value to our main file. Now please don’t forget to save the file. Afterwards please switch to the main file and find the part with the include statement for the entry signal. You can outcomment other entries by adding two slashes at the start of the line. Please add the include statement for our new file named CheckEntry_SAR and press F7 or click on the compile button to compile both files. You might see some warnings, but you shouldn’t get any errors. If you do, please consider watching one of the basic video tutorials first, or maybe the Premium course on our website might also be interesting for you. I hope that the compilation process was okay. The parabolic SAR indicator is interesting for people who like to watch charts. But now you should have a working function. That’s it for this video. Thank you and I will see you in the next one.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – PARABOLIC SAR INDICATOR appeared first on MQL5 Tutorial.
This time we are going to create a standalone Expert Advisor to trade the Awesome Oscillator, it will output buy and sell signals directly on the chart and whenever the line is crossed here we either get a sell signal when it’s below the dotted line or we would get a buy signal as soon as it crosses the line like right now the bars are above and now we consider that to be a buy signal. Now how can we create an Expert Advisor in MQL5 that is able to not only output the signals on the chart but to automatically trade them? To do that 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/ Expert Advisor (template)” from template, “ Continue”, I will call this file: “SimpleAwesomeStandaloneEA”, click on “Continue”, “Continue” and “Finish”. Now you can delete everything above the “OnTick” function and the two comment lines here. We start by including the file “Trade.mqh”, this one comes with MQL5 and it makes it possible to create an instance from the class “CTrade” that will be called: “trade” and we are going to use it to open positions later on. Before we do that we calculate the Ask price and the Bid price that is done by using “SymbolInfoDouble” for the current symbol on the chart, “SYMBOL_ASK” will give us the Ask price and “SYMBOL_BID” will give us the Bid price. With “NormalizeDouble” and “_Digits” we automatically calculate the right number of digits because the current currency pair has 5 digits behind the dot but there are also other currency pairs with 3 digits behind the dot. Now we need a signal variable that will be a string variable so it can contain text later on right now we don’t assign any values because we need to calculate them later on. With “MqlRates” we create a price information array (PriceInformation), that function here stores the information about the prices, the volumes and the spread. Now we sort the array from the current candle downwards by using “ArraySetAsSeries” and with “CopyRates” we fill it for the current symbol and the currently selected period on the chart from candle 0 (zero) for 3 candles and we store the data in our price information array (PriceInformation). Let’s create another array called: “PriceArray” that one will hold the data for our Oscillator, so let’s use the integrated “iAO” function of MQL5 to define the Awesome Oscillator Indicator for the current symbol and the current period on the chart. This array (PriceArray) also needs to be sorted from the current candle downwards so we use “ArraySetAsSeries” for this one and now we use “CopyBuffer” to fill our price array (PriceArray) for the first buffer – that’s the line here – from the current candle 0 (zero) for 3 candles and store the information for the Expert Advisor in our price array (PriceArray). And to calculate the Expert Advisor for the current candle we simply look at the value of candle 0 (zero) in our price array (PriceArray), we also use “NormalizeDouble” and a 6 to get six digits behind the dot like here and the result will be stored in the Awesome Oscillator value (AwesomeOscillatorValue) and if that value is above 0 (zero) we consider that to be a buy signal and now we assign the word: “buy” to our signal. Otherwise if the value (AwesomeOscillatorValue) is below 0 (zero), so if the Awesome Oscillator value (AwesomeOscillatorValue) is less than 0 (zero) we assign the word: “sell” to our signal and if the signal equals sell and “PositionsTotal” is below 1 – in other words we don’t have any open position – we use “trade.Sell” to sell 10 micro lot. Otherwise if the signal equals buy and we have no open positions we use “trade.Buy” to buy 10 micro lot. The last thing is to create a chart output by using the “Comment” function to output the text: “The current signal is:” and the calculated “signal” directly on our chart. Okay, if you’re done you can click on the “Compile” button here or press F7, that should work without any errors and in that case you can click on the little button here or press F4 to go back to Metatrader and in Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, please select the new file: “SimpleAwesomeStandaloneEA”, let’s also mark the visualization option here and start a test. …and here we are, our Expert Advisor is working, actually we have opened the first automated trade and now you know how to code the Awesome Oscillator Standalone Expert Advisor and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE AWESOME STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video, we want to calculate the entry signal for this little Oscillator here. It has actually two signal lines, and it is called the Relative Vigor Index. So let’s see how we can create the entry module by using MQL5. In this video, we’ll show you how to build an entry signal module for the oscillator that is called Relative Vigor Index. Because oscillators provide values that are distinct from the price values on the candle chart, that indicator will once again be drawn on a separate chart window beneath the candle chart. In the same directory as the main file and the other entry files, we first create a new file called CheckEntry RVI.mq5. The function CheckEntry, which returns a string variable for the calculated signal, is contained in this file. Let’s start by generating the signal. Since that is a string-type variable, it is capable of holding text data. We currently keep it empty since we must determine the value as shown. So let’s create two price arrays, one for the first and one for the second line that is shown in the RVI oscillator window. Afterwards we define our oscillator and use the i RVI function that comes with MQL5. That will use the current chart symbol, the chosen time period and the value 10 for the definition. As you might have guessed, the value 10 is the number of candles for the calculation. Both arrays need to be sorted from the current candle downwards by using array set as series. Now we want to fill our two arrays with data and we can do that by using CopyBuffer. In both cases we use the definition that we have created before. The first parameter is for the buffer, either 0 or 1. The second parameter is the starting candle 0. Parameter 3 is for the number of candles that we want, in our case we want 3 candles. And the last parameter is the target array for both signals. In the next step we use Normalize double to get a formatted output with 3 digits behind the dot for the current candle 0. We do that for both arrays. Now that we have the current values for both buffers, we can define a buy and a sell signal. In our example we want to buy when value 0 is below value 1 and when both values are below 0. If that is the case, we assign the word buy to our signal variable. Otherwise, when value 0 is above value 1 and when both values are bigger than 0, we assign the word sell to the variable. Now that we have calculated the signal, we want to return it by using the return statement. Please save the file without compilation, the compilation process will be done in the main file. Please open it and find the include section. There you can outcomment all other entries by using two slashes. Add a new line and include the new file called Check_Entry RVI.mq5. Then you can compile both files at the same time by pressing F7 or clicking the compile button in the tool bar. The compilation process should work without any error messages, some warnings are expected. Okay, I hope you have a successfully compiled version by now. For now, I want to say thank you for watching the video, and I will see you in the next one.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – RELATIVE VIGOR INDEX appeared first on MQL5 Tutorial.
In this video, we are going to create an expert advisor entry signal for this little oscillator here. It is called the Relative Strength Index, and it’s very popular. So let’s find out how we can do that with MQL5. The RSI oscillator is drawn in a separate window below the candle chart. It only has one line, which will be our entry signal. Most of the time, oscillators are used to make filters, but they can also be used to make entry signals, which is what we will do here. To use it, we make a separate MQ5 file and put it in the same directory as the other Platin System files. CheckEntry RSI.mq5 is the name of the file, and it only has one function called CheckEntry. It will calculate what our entry signal is and send that result back to the main module. We want to make a string variable for the signal file, but we won’t give it a value yet because it will be worked out later. So, we build a double-type array to hold the different prices. In the next step, we’ll use the function iRSI, which is part of the MQL5 programming language. And we can use it to define our oscillator. Four parameters need to be passed. The first parameter is the symbol on the chart that is selected at the moment. The second parameter is the time range we’ve chosen on that chart. The third parameter is for the number of candles that we want to calculate. In our case we use 14 candles. The fourth parameter is used to define what we want to use for the result. In our case we calculate it for the close price. The next step is to sort our array by using Array Set As Series. We want to put it in order from the current candle down. And now, thanks to CopyBuffer, we can fill the price array with the data for the prices. The first parameter is for the definition we made above. Parameter 2 is for the first buffer, which is the oscillator’s signal line. Candle 0 is used for parameter 3, which is the number of the current candle. The number of candles we want to use in the calculation is the fourth parameter. We use three candles. And the price array is the last parameter. This is where we want to store these values. We only need to look at the value for candle 0 in our price array to find the value for the current candle. With NormalizeDouble and the number 2 we can create a number with two digits. If that number is greater than 70, we call that a “sell” signal and put the word “sell” into our signal. If it is below 30, however, we give our signal the word “buy.” Lastly, we use the return function to send the calculated value back to our main module. Don’t forget to save the file, please. You don’t have to compile it! Jjust save it and go back to the main module, where the OnTick function is included. There, you need to add the new file to the import section. You can do this by using the include statement. Please uncomment any other entry signals and press F7 or click the Compile button to compile the main module and the new entry file you just made. Okay, you should now have a version of the oscillator that works. This version is called the RSI oscillator. You can use it in your own system, or if you have the Platin System or the Robot Trading system, you can import it into those. By the way, a demo version is now available on PlatinSystem.org. That’s all for now. Thank you for watching, and I’ll see you in the next video. Okay. I hope the compilation process worked for you. If that is the case, you should have a working version for the RSI that you can use to create signals, or you can use it as a filter. For now, I say thank you for watching, and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – RELATIVE STRENGTH INDICATOR appeared first on MQL5 Tutorial.
In this video we want to check out the indicator for this little red line here. It is called the variable index dynamic average. And we want to create an entry module for it. So let’s see how that can be done with MQL5. This indicator is drawn on the candle chart as it produces values that can be shown inside of the price range of the candles. To calculate the entry signal, we first need to create a new file inside of the directory where the other files of your system are located. The name of the file is CheckEntry_IVIDYA.mq5 and we use a simple function named CheckEntry to calculate the signal for the indicator which will be returned at the end of the function. But first we need to do a few things to actually calculate the signal. Let’s start with the signal. Please create a variable called signal. It is of the type string, so it can hold text values. Afterwards we create an Array for price data by using MqlRates. And to sort that array we use Array set as series. That will sort it from candle 0 downwards. So far, so good. Now we want to fill the array. That can be done by using CopyRates and we do it for the current symbol and the currently selected period for that particular symbol. We want to store prices, starting with the current candle 0, for three candles and the results will be stored in our price array. Now, please create another array for our Expert Advisor. This also will be sorted downwards by using Array set as series, like we have done above. MQL5 has an included function that is called iVIDyA. We use it with the following parameters. First we pass the symbol and the period, followed by the values 9,12 and 0. If you open a Metatrader chart and click on Insert, Indicators, Trend, Variable Index Dynamic Average, you will find that those are the standard values for the CMO period, the EMA period and the shift value. So let’s continue with the code here and in the last parameter we use PRICE_CLOSE, because we want the result to be calculated based on the close price. Afterwards we use CopyBuffer for the definition for our Expert Advisor. We want to calculate the buffer 0, we want data from candle 0 for 3 candles and we want to store the result in our array for the Expert Advisor. The rest is easy. When we pick the value for candle 0 inside of our array, we can use that to compare it with the candle prices. If that value is above the close price for candle 1, we want to buy. If it is below the close price for candle 1, we want to sell. So we assign the word buy or sell to our signal variable and use return to return the calculated signal to our main file, which is the one that contains the OnTick function. Don’t forget to save the file. Compiling will be done in the main file, you just need to save it. Let’s open our main file now and find the include statement section. There you want to outcomment other entry signals. Just add two slashes before the include statement, that will disable them. Add another line to include the file we have just created and afterwards you can compile the main file and the entry signal module at once by pressing F7. You can also use the compile button if your toolbar is enabled. That should not produce any error messages, but if you have errors, please check your file line by line. If this was too fast for you or if you have no idea what all those code lines mean, you might want to watch a few more basic videos or maybe the premium course on our website might be interesting for you. Okay, if everything worked well, you should see the indicator on your chart. It is trading in my case. If you have any problems, you can contact me. And in this little video, you have seen how to create an entry signal for this indicator. I can’t even remember the name. It is called variable index dynamic average. Thank you for watching and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – VARIABLE INDEX DYNAMIC AVERAGE appeared first on MQL5 Tutorial.
In this video, we are going to create an entry module for this oscillator here. This is called the momentum oscillator. It is shown on a separate chart below the candle chart. So let’s find out how to calculate that with MQL5. In this video we want to create an entry signal module for the so-called momentum oscillator. That is once again an indicator that will be drawn on a separate chart window below the candle chart, because oscillators create values that are different from the price values on the candle chart. To get started we create a new file named CheckEntry_Momentum.mq5 in the same directory where the main file and the other entry files are located. This file will contain the function CheckEntry which will return a string variable for the calculated signal. Let’s first create the signal. That is a variable of the type string, so it can contain text values. For now we leave it empty as we need to calculate the value as follows. We want to store some price data in an array, so we create that first. To define the momentum oscillator, we can use the function iMomentum. That is included in MQL5 and it needs a few parameters that we need to define. Parameter 1 is for the symbol on the chart. The second parameter is for the period on that chart. Parameter 3 is the number of candles that we want to use for the calculation. In our case, we will use 14 candles. That is also the default value that you will see when you drag the momentum indicator onto one of your charts. Finally, we use PRICE_CLOSE to calculate the value based on the close prices. Afterwards we use Array set as series. That will sort the array from the current candle downwards. And now we can use CopyBuffer to fill the array with data. We do it for the definition that we have created, for buffer 0 and we want to do it from candle 0 and for three candles. The result is stored in the price array. And now that we have done that, we can calculate the current value for the momentum. All we need to do is to look at the value for candle 0 in our array. As the momentum indicator has two digits behind the dot, we use Normalize Double and the value 2 to create a formatted output. Now let’s calculate the signal. If the momentum value is below 100 we consider that to be a buy signal. So we assign the word buy to our signal. Otherwise, when the momentum value is above 100, that’s when we want to assign the word sell to our variable, because that is when we want to sell. At the end of the function we use return to return the calculated result to our main module. Now please save your entry file if you not already have done that. Compilation is not necessary, it will be compiled together with the main module. Therefore we open our main file and go to the include section where we can outcomment other entry signals by adding two slashes. Instead of the old entry signal, we now add an include statement for our new file CheckEntry_Momentum.mq5. Afterwards we compile the whole thing, by pressing F7. You can also click on the compile button on the toolbar. That should work without any error messages. Otherwise please check out the basic videos about compilation or maybe the Premium course on our website might be interesting for you. OK, that’s it for the momentum oscillator calculation. I hope it works for you. Thank you for watching and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – MOMENTUM OSCILLATOR appeared first on MQL5 Tutorial.
In this video, we want to check out this Oscillator here. It’s a very popular one. It is called the MACD Oscillator. We want to calculate the main signal for this one. So let’s find out how this is done with MQL5. The Mac D oscillator is shown on a separate chart below the candle chart. It has two values that show a value as a signal. In this case we want to calculate the main line signal. To use it, we build a separate MQ5 file and put it in the same directory as the other Platin System files. CheckEntryMacD.mq5 is the name of the file, and it only has one function called CheckEntry. The buy and sell signals for our system are calculated and returned by this function. In fact, oscillators aren’t meant to make signals. Instead, they are used to confirm or filter out other signals. But that doesn’t mean we can’t use them, since all we need for our trading system is a clear and well defined entry signal. We start by putting the signal into a string variable. That will be sent back to our main function later, but first we have to calculate it. We also have to make an array for data about prices. And with ArraySetAsSeries, we arrange our array and we want to sort it from the current candle 0 downwards. MQL5 comes with an included function to calculate the MacD and that function is called I MacD. We pass the symbol as the first parameter, followed by the period that is currently selected on our chart. Three more values follow to define the period for the fast exponential moving average, then the slow exponential moving average and the signal period. The values are 12, 26 and 9 as these are the standard values for the MacD oscillator. The last parameter is used to define how the signal should be calculated. We want to use PRICE_CLOSE here to use the close price. With CopyBuffer we will now fill our array, according to the definition that we have created. We do that for buffer 0 as that is the main buffer for the MacD oscillator. We want to start with the current candle, that is candle 0. And we want to store the value for 3 candles, the target is our price array. Now that we have done that, we can calculate the current value by looking at the value of candle 0 in our price array. If that value is bigger than 0, we want to sell and that is when we assign the word sell to our signal. If the value is below 0, that would mean that we want to buy, therefore we now assign the word buy to the signal. And at the end of our function we want to return the MacD signal to our main module, which is the one with the OnTick function. Please don’t forget to save your entry file, but you actually don’t have to compile it right now. The compilation is done in the main module, but before you do that, find the include statement for the entry signal and change it to use our new file, CheckEntry MacD.mq5. By putting two slashes at the beginning of a line, you can comment out other entry modules. After that, press F7 or click the compile button to compile your main module and the entry signal file that came with it. There shouldn’t be any problems. If you run into problems, you might want to buy the Premium course or watch one of the beginner videos to learn how it works. OK, by now, you should have a working version for this entry signal for the MACD Oscillator. If you want to, you could also calculate the difference between the main line and the signal line here. But in this little video, you have learned how to calculate the main module for the MACD Oscillator. I will see you in the next video. Thank you for watching.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – MACD OSCILLATOR appeared first on MQL5 Tutorial.
In this video, we are going to create an entry signal file for this oscillator here. It is called accumulation distribution. Usually, oscillators are used to confirm signals, but in this case, we are using it as an entry signal. And as you can see, it is actually working. The Accumulation Distribution oscillator is drawn on a separate chart below the candle chart. It has a single signal line which will show a value. 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_IAD.mq5 and it contains a single function that is called CheckEntry. This function calculates the buy and sell signals for our system. Actually oscillators are not meant to generate signals, they are rather used as filters for other indicators. But that doesn’t mean that we can’t use them, because all we need for our trading system is a working signal that is well defined. We start by creating a string variable for the signal. That will later be returned to our main function, but before we do that, we need to create the signal first. We also need to create an array for price data. And with ArraySetAsSeries we sort our array from the current candle downwards. Afterwards we can create our definition for the oscillator by using the iAD function that is already included in MQL5. The first parameter is for the current symbol on our chart and the second parameter is used for the currently selected period on that chart. The third parameter can be used to select the applied volume. We will use Volume_Tick here. Now let’s use CopyBuffer to fill our array with data. The first parameter here is the definition that we have created above. Parameter 2 is for the buffer that we want to calculate. This oscillator has only one buffer, so we set it to 0. The next parameter is for the candle where we want to start. We pick the current candle 0 and in the next parameter we define the number of candles that we want to calculate. In our case we do it for 3 candles. The last parameter is for the target array, that is our price array. Now we are able to calculate the values for the current candle and the candle before. To get the current value, we look at the value for candle 0 in our price array. To get the value for the candle before, we do the same for candle 1. Now we are actually able to calculate our signal. If the value for the current candle is higher than the value for candle 1, we assume that this is a buy signal. Therefore we assign the word buy to our signal. Otherwise, when the current value for candle 0 is below the value for candle 1, we assume this is a sell signal. Then we will assign the word sell to our signal. And finally we use the return statement to return our calculated signal to the main module. Please do not forget to save your entry file, but you don’t need to compile it right now. The compilation is done in the main module, but before you do that, please find the include statement for the entry signal and modify it to use our new file named CheckEntry_IAD.mq5. You can outcomment other entry modules by adding two slashes at the beginning of the line. Once you have done that, you can press F7 or click on the compile button to compile your main module and the included entry signal file. You shouldn’t get any errors. If you do, you should consider buying the Premium course or watch one of the starter videos to understand the process. Okay. If all went well, you should now have a working version of the accumulation distribution oscillator on your chart. So that’s it for this oscillator video, and I will see and the next one. Thank you for watching.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM ACCUMULATION DISTRIBUTION OSCILLATOR appeared first on MQL5 Tutorial.
In this video, I’d like to talk about something that seems so obvious that it’s almost blinding. When you use the strategy tester to test something, you might miss things that are important when you trade in real time. This is an example of that. When you test your strategy, you probably forget one or two things that could hurt you when trading in real time. The first thing is that real time conditions are not the same. When you’re using the strategy tester, you might not have a lot of different conditions, but that’s part of the game when you’re trading in real time. If you lose power or have trouble connecting to the internet, your Expert Advisor might not work for a few hours or even days. That happened to us a lot. And if there’s one thing that’s likely to happen, it’s that one of these power outages will happen at the worst time and in the worst way. It could happen while you are on vacation, for example. What happened a few years ago is as follows. The Expert Advisor knew what the last price to buy was and what the last price to sell was, but then it was disconnected. During the outage, the market changed, but the Expert Advisor didn’t notice. Later, the Expert Advisor kept making decisions based on conditions that were no longer true. You can’t simulate a 7-hour internet outage in a strategy test, so that’s not tested in backtests. People were very hard on me when I first started using MQL4 because I didn’t use the OnInit function. Yes, it takes more processing power to figure out everything every time a new Tick comes in. But it is worth the CPU time when you want to avoid values and assumptions that don’t match up. Think of something from the real world. You might have ended up wearing the wrong clothes because the weather changed while you weren’t paying attention. For example, you might come home from a summer vacation and find that a T-shirt is not enough because the airport in your home country is covered in snow. The OnInit function will only run once, when the Expert Advisor starts up, so it is a good idea to check every time the price changes to see if some important conditions are still true. In our Platin System, we do this with a function called CheckForTick. If you only use one file and don’t import any libraries, you can use your own Expert Advisor right in the MQL OnTick function. And don’t just go by the results of strategy tests. Those are good ways to tell if something will work or not. But nothing beats trading in real time, even on a Cent account. So, when you trade in real time, make sure you check the conditions and assumptions you have, because as Mark Twain once said: “It’s not what we don’t know that gets us into trouble. It’s the things we know for sure that aren’t true.”
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – WHY THE ONINIT FUNCTION WILL NOT SAVE YOU appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor to create an entry signal for this Oscillator here. It’s the Accelerator oscillator. So let’s find out how to do that with MQL5. The Accelerator oszillator is drawn on a separate window below the candle chart. It has a single line which we will use for our entry signal. Oscillators are usually used to create filters, but it is also possible to create entry signals like we will do in this case. 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_IAC.mq5 and it contains a single function that is called CheckEntry. It will calculate our entry signal and return it to the main module. We want to create a string variable for the signal file and for now we will not assign any value as this is going to be calculated now. Therefore we create an array of the type double to hold several prices. In the next step we will use the function iAC that is included in the MQL5 language to create a definition for our oscillator. We only have to pass two parameters here. The first parameter is for the current symbol on the chart. The second parameter is for the time period that we have selected on that chart. In the next step we use ArraySetAsSeries to sort our array. We want to sort it from the current candle downwards. And with CopyBuffer we can now fill the price array accordingly. Parameter 1 is for the definition that we have created above. Parameter 2 is for the first buffer, the signal line of our oscillator. Parameter 3 is for the starting candle, here we use candle 0. Parameter 4 is the number of candles that we want to use for the calculation. And the last parameter is the price array where we want to store those values. To get the value for the current candle, we simply have to look at the value for candle 0 in our price array. If that value is above 0, we consider that to be a buy signal and assign the word buy to our signal. Otherwise, if it is below zero, we assign the word sell to our signal. Finally we use the return function to return the calculated value to our main module. Please don’t forget to save the file. Compilation is not necessary, just save it and go back to the main module which contains the OnTick function. There you need to add the new file in the import section where you can do that by using the include statement. Please outcomment any other antry signals and press F7 or click on the Compile button to compile the main module and the new entry file that you have just created. Okay, by now, you should have a working version for the oscillator that is called the Accelerator. You can use it in your own system, or you can import it into the Platin System or into the Robot Trading system, if you have one of those. By the way, by now we have a demo version available on Platinum System.org. For now that’s it. Thank you for watching and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – ACCELERATOR OSCILLATOR appeared first on MQL5 Tutorial.
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. Afterwards please click on Compile or press F7 to compile your new version. You should not get any errors. If you do, please check out the content from the other videos before or consider the premium course on our website. Okay, by now you should see a working version of the Envelopes indicator right on your chart. You can use it with the Platin System, the Robot Trading System – and of course – you can use it in your own system. That’s it for now. Thank you for your attention and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – ENVELOPES ENTRY SIGNAL appeared first on MQL5 Tutorial.
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 candle instead of the highest point for the highest candle that we have used for line one. And to calculate our trading range we take the highest high of the last one hundred candidates minus the lowest low of the last one hundred candles. In the last step we will use the comment function to output the text “The current trading range is… ” followed by the calculated trading range. Now let’s compile the code and that worked without any errors so we now click this little button here or press F4 on our keyboard to go back to Meta Trader, and in Meta Trader you want to click on View Strategy Tester or press control and R on your keyboard and here you want to select the advanced trading range.ex5 file and enable the visualization option here and start your test. And this is how it looks like, right now are trading range is above four. I will zoom in a little bit and now you can see it shrink and when it falls below one we don’t want to trade because now we are in a sideways market. Okay now you know how to create an Expert Advisor that is able to calculate a trading range and you have done it yourself with a few lines of MQL 5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 Tutorial – Advanced Trading Range Calculation appeared first on MQL5 Tutorial.
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.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – CALCULATING TODAYS PROBABILITIES appeared first on MQL5 Tutorial.
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.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – BOLLINGER BANDS ENTRY SIGNAL appeared first on MQL5 Tutorial.
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. Or maybe even the premium course on our website might be interesting for you. But in this little video, you have learned how to create a WPR entry signal and you have done it with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – WILLIAMS PERCENT RANGE ENTRY SIGNAL appeared first on MQL5 Tutorial.
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. If you don’t see the Strategy tester panel here, you can click on View, Strategy Tester. Or press Control and R. In this case, I’m going to pick the free Platin Demo System which will only work with original MetaQuotes demo accounts. We will trade the Euro US dollar on the one hour chart, let’s say for the whole year 2021. Now I click on Inputs and set all parameters to the default values here. You can mark the visible mode and click on Start. And now you should see this little red line here. It produces buy and sell signals which are filtered by the long term trend here. But you can see that the system is working. Now let’s close that part. Disable the visible mode here, click on Start and on the graph tab you should see that the system is producing results. Here we have a drawdown. And it looks like we could get a second one here. But now it recovered. And this is the result with the standard settings. You can click on Backtest to see all the details. So in this case it worked. It’s probably not the best choice for the Platin system. I prefer the Commodity Channel Index. But you can check out yourself. A free demo version is available, because I only sell the system to long term customers who have
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – PLATIN SYSTEM – ADVANCED MOVING AVERAGE ENTRY appeared first on MQL5 Tutorial.
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.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – HOW TO GET THE 1000 PLATIN SYSTEM FOR FREE appeared first on MQL5 Tutorial.
MQL5 TUTORIAL BASICS – 57 HOW TO CREATE METAQUOTES DEMO ACCOUNTS INSIDE METATRADER Platin System In this video we are going to create an Expert Advisor that is actually going to trade. It´s going to trade the MACD indicator. That´s the little indicator here. You see that it changes directions and whenever we have a crossover from above to below, that would be a sell signal. In the other case, when the signal is below the line and it crosses the line from below, that´s a buy signal. Now, how can we create an automated Expert Advisor that actually is going to trade the MACD signal? To do that, please click on the little button here or press F4 on your keyboard. And now you should see the Meta Editor window and here you want to select File, New, Expert Advisor from template, Continue. I will call this file SimpleMACDStandAlone, click on Continue, Continue an Finish. And now you can delete everything that is above the on tick function, and let´s also delete the document lines here. First we need to include the Trade.mqh file. It comes with a few useful trading functions. So let´s create an instance of the class CTrade. We will call it trade and we will use it later on to actually open trades. Inside of the on tick function we create a string for the signal. That will be also called signal and we don´t asign a value here, because we need to calculate that later on. Let´s calculate the AskPrice and the BidPrice. That can be done by using SymbolInfoDouble for the current Symbol and we use SYMBOL_ASK to calculate the AskPrice. And SYMBOL_BID to calculate the BidPrice. And with NormalizeDouble and _Digits we make sure that we have the right amount of digits, because there are currency pairs with three digits and others with five digits behind the dot. Now we need to create a Price Array. That will hold the Price Data. We use ArraySetAsSeries for our PriceArray to sort the PriceArray from the current candle downwards. And now we are going to use the iMACD function to create a MACDDefinition for the current symbol and the currently selected period on the chart. We have three additional parameters here. 12, 26 and 9. And that´s also what we see here in the indicator window, because when you right click on the MACD and select Properties, you will see it uses a Fast EMA of 12, a Slow EMA of 26 and a MACD SMA of 9. That´s exactly what we use here. And the calculation is based on the close price. So we are going to use PRICE_CLOSE for the calculation. We use CopyBuffer to fill our PriceArray. According to the MACDDefinition that we have created here. And we are going to use Buffer 0 from the current candle, that’s candle 0, for 3 candles. That´s the 3 here. And we want to store the result in our PriceArray. Now we are able to calculate the Expert Advisor for the current candle, that´s candle 0 in our PriceArray. And we assign the result to the variable MACDValue. Let´s do that again, this time for candle 1. That´s the candle before. And this result will be stored in the last MACDValue. And whenever the MACDValue is above 0, that would be the case, when the signal ist above the dotted line here. And when the last MACDValue was below the 0 line, that would be a crossover from below, and that´s a buy signal. So we assign the word buy to our signal. In the other case: If the current MACDValue is below 0 and if the last MACDValue was above 0, that would be a sell signal. So we assign the word sell to our signal. If the signal equals buy and positions total is less than 1, that would be the case when we have no open positions. We use trade.buy to buy 10 microlot. Otherwise, if the signal equal sell and we have no open positions, we would use trade.sell to sell 10 microlot. And finally we want to create a chart output. That is done by using the comment function. It will output the words: “The current signal is”, followed by the calculated signal. Ok, please click on the Compile button or press F7. That should work without any errors here. We have two minor warnings that we could check the type conversion here. But for this simple example we are done. So now we click or press F4 to go back to Meta Trader. And in Meta Trader we click on view, Strategy Tester or press CTRL+R. And here you want to pick the SimpleMACDStandAlone.ex5 file. Mark the visualisation option here and start a test. And here is our little Expert Advisor at work. We actually have a MACD Signal. We see the output for the current signal here. And we have an open trade. Actually we already made a profit. And now you know how to create a Stand Alone Expert Advisor for MetaTrader 5, that actually is going to open and close real trades. And you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE MACD STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
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.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL ENGLISH – HOW TO PROFIT FROM A TREND CHANGE appeared first on MQL5 Tutorial.
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.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL ENGLISH – 3 COMMON ERRORS CAN LEAD TO SLEEPLESS NIGHTS appeared first on MQL5 Tutorial.
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 or press F4 in your Metaeditor to go back to Metatrader. In Metatrader you want to select the file: “SimpleSignalStacking.ex5”, pick a currency pair and mark the visualization option here. Now you can click on “Start” and here’s our little Expert Advisor at work, its producing a pretty stable trend signal and now you know how to calculate each of the four Exponential Moving Averages here and how to output buy or sell signals and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE SIGNAL STACKING appeared first on MQL5 Tutorial.
TO THE STATISTICS I have added the statistics for the new $1000 Platin Group System on the webpage Platinsystem.org so you can now analyze and take apart every detail. By now our first Platin System trading account has been online for a few weeks. We have crossed the 3 percent profit mark at the beginning of the week and we are approaching the $350 profit line. Thanks to a tip of a member named Rafael from Brazil I now have 3 streaming servers online that automatically trade the $1000 Platin Group System on Youtube for three different accounts. You will find them on my YouTube channels for MQL4 Tutorial, MQL5 Tutorial and Algorithmic Trading System.com. I lately noticed an error in the system that caused an inconsistency when I updated something in the source code. The reason was that the system was unable to deal with positions that had been opened before it was restarted during live operation. That is not happening while you do strategy tests, therefore it only comes up while trading live. And that is why it is so important to not only rely on strategy test results. So usually I do strategy tests on demo accounts until a system is ready to go into beta stage. Then I use so-called Cent accounts to see how the system behaves on a real money account in daily operation. And, as I often say to my clients, it is never a problem to scale up an account once everything works as it should. But this time I do it in a different way. And the reason is, that one of the premium course members came up with a system that he wanted me to investigate as he thought the good results had been caused because of a special entry. I didn’t believe that and therefore I exchanged the entry signal to see if the results still would be good. And guess what? That actually was the case so I took the whole thing apart and started to build my own version of the approach. About 3 months later the first Alpha version of the Platin System was ready and here we are now, just a few weeks later, with 3 systems in the beta stage. Therefore I have added the statistics on Platinsystem.org so you can check out the details and find out if this is something you might want to trade. Just click on the statistics sheet and you can see details about each and every trade. And most of the time the system has very little drawdowns and the average trade duration is only a few hours. If you are already a Premium Course Member I am curious about your thoughts about the current system, because I am planning to offer an upgrade to existing Premium Course members who have what it takes to get good results. If you think about becoming a premium course member, that is still possible on the website. I have taken the sales page for the RobotTradingSystem offline to invest that time for the new Platinum group which might be interesting for some existing members, but I have to admit that it is an expensive solution as it includes consulting and a few things that I have never offered before. One big thing is collaboration, so Rafael, if you see this video and if you are interested to become a Platin Group Member I have a coupon code for you. I still search for the original email and the attachment that got everything started in spring to give credit to the premium member who helped me to get the idea. But I wanted you to be able to check out the embedded statistics on PlatinSystem.org and probably you get a few valuable new insights as I did. I am curious about your response and I will see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5TUTORIAL – HOW TO GET ADVANCED STATISTICS FOR 3 LIVE SYSTEMS appeared first on MQL5 Tutorial.
In this video we are going to create a standalone Expert Advisor that is actually able to trade the Parabolic SAR Indicator. This is a very nice Indicator, you can see the dots above and below the price and whenever the direction changes here you will see that we have a buy or a sell signal. The signal output will be in the left upper corner here; this Expert Advisor will be able to automatically trade the signal. We have already an open position here and now we want to find out how we can code such a standalone Expert Advisor in MQL5. To do that please click on the little button here or press F4 on your keyboard and now you should see the Metaeditor window and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this version: “SimpleSARStandaloneEA” (Expert Advisor), click on: “Continue”, “Continue” and “Finish”. Now we delete everything that is above the “OnTick” function and let’s also remove the two comment lines here. We start by importing the file: “Trade.mqh” that will enable us to create an instance of “CTrade” that will be called: “trade” and we use it later on to open the positions. Inside the “OnTick” function we create a price array (PriceArray) that is done by using the “MqlRates” function that is included in MQL5, now we use “ArraySetAsSeries” to sort our price array (PriceArray) from the current candle downwards and with “CopyRates” we fill it for the current symbol on the chart and a currently selected period, we start with the current candle 0 (zero) and we copy price data for 3 candles and store it in our price array (PriceArray). We also need to create a string for the signal, that variable will be also called: “signal” and we don’t assign a value here because we are going to calculate that later on. First we need to get the Ask and the Bid price, that can be done by using “SymbolInfoDouble” for the current symbol, we use “SYMBOL_ASK” to get the Ask price and “SYMBOL_BID” to get the Bid price, and with “NormalizeDouble” and “_Digits“ we calculate the number of digits behind the dot – you see that this currency pair has 3 digits while other currency pairs may have 5 digits – and if you mark “_Digits“ and press F1 you will see that the “_Digits“ variable stores the number of digits after the decimal point. Let’s create another array for our SAR Indicator that will be called my SAR array (mySARArray), it’s a double array so it can hold floating type values and by using a “iSAR” we create an SAR definition (SARDefinition) for the symbol on the chart and the currently selected period. Now you might ask yourself; what these two parameters are? Well, if you click on “Insert/ Indicators/ Trend/ Parabolic SAR” you will see that we have a step value of: 0.02 and a max value of: 0.2, that’s exactly what we are using here. Now it’s time to sort the SAR array (mySARArray) with “ArraySetAsSeries” and we use “CopyBuffer” one more time to fill our SAR array (mySARArray) for the first buffer – that’s the one that is used for the dots here – from the current candle 0 (zero) for 3 candles and store the values in our SAR array (mySARArray). Now we are able to calculate the value for the last candle, I will call it: “LastSARValue”, I use ”NormalizeDouble” here and a 5 because when you pause the Strategy Tester and hold your mouse above one of these dots you will see that we have 5 digits behind the dot of the value – that’s what “NormalizeDouble” does; if I would use “NormalizeDouble” and a 4 we would have 4 digits behind the dot – and we get the value for the last candle by looking at candle 1 in our SAR array (mySARArray). We actually do the same here, this time for candle 2 – that’s the candle before the last candle – so I call it: “NextToLastSARValue” and whenever the “LastSARValue” is below the lowest price of candle 1 – or in other words; whenever the dots are below the candles – and if the “NextToLastSARValue” was greater than the highest price for the candle before that would be a buy signal so we assign the word: “buy” to our signal. Otherwise if the “LastSARValue” was above candle 1 and the value was below the candles before that would be a sell signal and now we would assign the word: “sell” to our signal. And if our signal equals sell and “PositionsTotal” is below 1 – in other words we have no open positions – we use “trade.Sell” to sell 10 micro lot, otherwise if the signal equals buy and we have no open positions we would use “trade.Buy” to buy 10 micro lot. Finally we create a chart output here, we use the “Comment” function to output the words: “The current signal is:” followed by our calculated “signal”. Okay. That’s it. Please click on the “Compile” button or press F7, you should get no errors and no warnings here and in that case we can click here or press F4 to go back to Metatrader. In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, please select the file: “SimpleSARStandaloneEA.ex5”, mark the visualization option here and start a test. …and here we are! Our Expert Advisor is actually trading, this is our first position and in this little video you have learned how to create a standalone Expert Advisor that is actually trading the SAR Indicator and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE SAR STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video we are going to create a standalone version for the Stochastic Oscillator, this is a very simple Oscillator; whenever the two lines crossed below the lower line here that would be a buy signal and whenever the two lines cross above that would be a sell signal. This Expert Advisor is actually going to trade and we will see the signal here on the chart. Now how can we create an Expert Advisor for the Stochastic Indicator? To do that please click on a little button here or press F4 and 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 version: “SimpleStochasticStandaloneEA”, click on “Continue”, “Continue” and “Finish” and now we can delete everything above the “OnTick” function and the two comment lines here. First we want to include the file: “Trade.mqh” and we want to create an instance of the class: “CTrade”, let’s call that one: “trade” and inside the “OnTick” function we create a string for the signal that is called: “signal” and we don’t assign a value now because we need to calculate that later on. To really trade something we need to calculate the Ask and the Bid price, that is done by using “SymbolInfoDouble” for the current symbol on the chart and we use “SYMBOL_ASK” to get the Ask price and “SYMBOL_BID” to get the Bid price and with “NormalizeDouble” and “_Digits” we get the right number of digits – this currency pair has 3 digits and other currency pairs may have 5 digits – and that’s a way to calculate the right value. Now we need 2 arrays; the first one is called K array (KArray) the second one D array (DArray) and when you click on: “Insert/ Indicators/ Oscillators/ Stochastic Oscillator”, you would see the same period values here: 5 for the K period and 3 for the D period, so we use “ArraySetAsSeries” to sort the “KArray” and the “DArray” from the current candle downwards and now we can call the “iStochastic” function that is included with MQL5 for the current symbol and the current period, here are our values: 5, 3 and another 3; that’s K period, D period and slowing. We use ”MODE_SMA” and “STO_LOWHIGH” – that’s the method here – SMA stands for Simple Moving Average and “Price field” is “Low/High”. Let’s fill the array with “CopyBuffer”, the first one is for the first buffer that’s buffer 0 (zero) – that’s for the “KArray”, the second one is for buffer 1 – that’s for the “DArray”. We start at candle 0 (zero) and fill it for 3 candles, and that makes it possible to calculate the current K value (KValue) by looking at the value of candle 0 (zero) of the “KArray” and the current D value by looking at the candle 0 (zero) of the “DArray” and because we need to find out if we had a crossover we also do the same and calculate the same values for candle 1. The buy signal would be true if both values are below 20 – so that’s the case when both lines are below the dotted line here – so “KValue0” would be less than 20 and “DValue0” would also be less than 20 and if the “KValue” has crossed the “DValue” from below – so now “KValue0” would be bigger than “DValue0” but “KValue1” was below “DValue1” – that would be a buy signal so we assign the word: ”buy” to our signal. We also have the sell signal, that’s if both values are above 80, that would be the case when both lines are above the upper dotted line here and if the “KValue” has crossed the “DValue” from above – so “KValue0” is below “DValue0” but “KValue1” was above “DValue1” – that would be a sell signal so we assign the word: “sell” to our signal. And if the signal equals sell and we have no open position – so “PositionsTotal” is less than 1 – we use “trade.Sell” to sell 10 micro lot in the other case if the signal equals buy and we have no open positions we use “trade.Buy” to buy 10 micro lot. Finally we are going to create a chart output by using the “Comment” function that will output the words: “The current signal is:” and the calculated “signal”. Okay, don’t forget the last bracket here, click on “Compile” or press F7 and now you should see no errors and no warnings here and in that case you can click here on the little button or press F4 to go back to Metatrader. In Metatrader we click on: “View/ Strategy Tester” or press “CTRL and R”, let’s pick the file: “SimpleStochasticStandaloneEA.ex5”, mark the visualization option here and start a test. …and here we see our little Expert Advisor, it is actually opening trades like this one and now you know how to automate an Expert Advisor that is able to trade the Stochastic Oscillator and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE STOCHASTIC STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video we are going to talk about a simple custom time function that we have created in MQL5. You see the output here on the chart, we have the date and we have the time including the seconds that is the local time that has been traded right here in the Strategy Tester and now we are going to find out how we can do a custom time function that is going to return the time and this readable format and to do that please click on the little button here or press F4 on your keyboard. Now you should see the Metaeditor and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “SimpleCustomTimeFunction”, click on “Continue”, “Continue” and “Finish” and now you can delete everything above the “OnTick” function and the two comment lines here. Okay, that’s it. First we need to create a string variable for our custom time that will be called: “myTime” and it’s of the type string, so it can contain text and to calculate it we just want to call a custom function called: “GetTime” to calculate the time, so the value of “myTime” will be calculated in the function “GetTime” and when we click on the “Compile” button right now we will see that the “GetTime” function is not defined, so that’s what we are going to do now. To create a custom function you can use a return type, in our case we will use the string return type, because we are going to deliver the time as text. The name of the function is: “GetTime” as we are calling it here and we don’t have any parameters so let’s add two brackets here, we use a local string that will be called: time with seconds (TimeWithSeconds). Now we create a string for the time with seconds (TimeWithSeconds) that’s also a string type variable and the name will be: “TimeWithSeconds”. Here comes the interesting part; we calculate the time with seconds (TimeWithSeconds) for the local time and that is done by using “TIME_LOCAL”. If you mark “TIME_LOCAL” and press the F1 key you will see that it returns the local time of a computer where the client terminal is running, but it’s a datetime variable so we use “TimeToStr” to change it to a text and the function: “TimeToStr” (time to string) is converting a value containing time in seconds since the 1st of January in 1970 into a string in this format. We use “TIME_DATE” that will give us the year, the month and the day – that’s the first part here, this is the pipe sign, it separates the first from the second parameter, the second parameter is “TIME_SECONDS” and that will deliver us the local time including the seconds. Okay. In the last step we want to return the calculated time to the main function by using the “return” function for “TimeWithSeconds” so it will return the calculated value here and assign it to “myTime” and to see it on the chart we use the “Comment” function to create a chart output for the time and when you are done you can click on the “Compile” button here, that should work without any errors now and if that is the case you can click on the little button here to go back to Metatrader. In Metatrader you want to click on “View/ Strategy Tester” or press CTRL and R and now you should see the Strategy Tester here, please select the “SimpleCustomTimeFunction.ex5”, mark the visualization option here and start your test. We have the date and the time directly on the Forex Chart and now you know how to create an Expert Advisor to calculate the formatted time output on your chart and you have done it with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE CUSTOM TIME FUNCTION appeared first on MQL5 Tutorial.
This video is about publishing statistics on the Internet. You see, I announced a while ago that I would be offering a four-digit platinum group membership with a brand new trading system in a short period of time. Now this is one of the pre-versions and we have an account hosted at Robo Forex Pro that has this account number here. And unlike my other habits, I’m now on FXBlue.com. Because with MyFxBook I was not able to reliably publish the account statistics on a Linux machine. Because this MetaTrader here runs on a Linux device and I have now built my own trading distribution built on Debian. In fact, I also managed to install FX Blue’s Expert Advisor on the Linux machine in MetaTrader. The whole thing runs here under Play on Linux and currently the Expert Advisor is red, because we get no new trading signals, it is weekend. But you can already see here, the last update was at 10:26 a.m. The account details are also visible. Fx Blue has different functionalities here. One can monitor certain core values. The whole thing can be displayed as a chart. Currently we have made 279 trades on the Euro US Dollar chart. With a total profit of 204.11 $. The net result is $89.16. Interestingly, we have 230 buy trades and 49 sell trades, although the Euro US Dollar has just this week reached its lowest level since the turn of the millennium. If you want, you can take a closer look at all these details here. I think it’s set up quite well. Then there is the whole thing here again as a print statement or you can download it here in Excel. On my Linux machine here I don’t have an Excel installation now, because it’s a so-called Stick PC. It runs silently in the background with just two gigabytes of memory, but it is more than powerful enough to run our Expert Advisor and has the advantage that we don’t have to worry about getting any Windows updates installed in the middle of the night and then the computer might even be restarted. So if you had problems in the past to establish the advanced statistics of MyFxBook on a Linux PC, you can set it up on the FXBlue.Com website here via this live tab map. This is pretty straightforward for MetaTrader 4 and MetaTrader 5 and allows you to collect such advanced statistics for your own account here in the future. This is very useful to improve your results in the long run. That’s it so far for today. Thanks for watching and see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL ENGLISH – SETUP YOUR ADVANCED STATISTICS appeared first on MQL5 Tutorial.
The topic today is possibilities and probabilities. Because once again I have received a request from a course member. And the question was whether it is possible to implement a certain profit expectation in practice. My answer was that it depends on a lot of factors and one of these factors is probability. My favorite example on this subject is a man named Roy Sullivan. Roy Sullivan was a park ranger in the United States and he was struck by lightning a full seven times in his life. The likelihood of something like that happening is vanishingly small. Nevertheless, it has become 100% reality for Roy Sullivan. That means even with a very low probability, it’s entirely possible that the consequences could be devastating. For example, one could also think about the statistics for plane crashes and make the argument that flying is the safest way to travel. Yet, there are always reports of plane crashes and for the people who are affected by that situation on the plane, it is 100% a nightmare. So the idea with trading is to find something that brings both of those things together in a way that gives us the best possible results. That means we need to find something that is possible and that has a fairly high probability of producing positive results. Thankfully, in automated trading, there’s the ability to find that out via a pretty intensive series of tests. What’s going on here in the background of this video is what I spend most of my time doing. In fact, programming an automated trading system is not that time consuming. Most of the time is spent on thorough testing. And the goal is always the same, to increase the probability of a good result as much as possible and to make the system as stable as possible. Of course, many people will now say with the results from this video that the profit expectation is too low and that one could get much more out of such a system. But I can argue that I have been testing this system intensively for only three months. That means I have already done many 100 test series like this one. I’m currently doing that on three different computers with three different account types. And it’s always about making the system a little bit more stable and less about getting a few more dollars out of it in profit expectation. In fact, with what you see on the screen here, I’m able to trade in different currency pairs from the turn of the millennium historical data to the present day without the system going down the tubes. And the goal here is to get a system stable enough so that you can ensure stable operations over long periods of time. Beginners are often on the hunt for a quick profit. But professionals like Ray Dalio know that the key is to find something that works for the long term based on fundamental laws. If you have the time and the inclination, you should take a closer look at Ray Dalio’s book Principles. I learned a lot from it. And when this system is ready here, there will be an exclusive offer to some existing customers who meet the necessary criteria to be able to trade such a system profitably. However, the price for this will be in the four-digit range, since consulting is also included. But until all this is ready to go, it will surely take a few more months. If this is interesting for you, then you can register in advance. In this video, I simply wanted to show what is not only possible, but also probable. Because as soon as you can guarantee the most stable operation possible, it’s no problem to continue optimizing a functioning system in the long term. That’s it for today. Thanks for watching and see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL ENGLISCH – POSSIBLE OR PROBABLE? appeared first on MQL5 Tutorial.
In this video we are going to create an Expert Advisor like this one that is able to trade the Bollinger Band signal and it also uses the RSI Oscillator as a filter. So let’s find out how to do that with MQL5. To get started, please click on the little button here or press F4 on your keyboard. Now you should see the meta editor window and here we have a pre coded version for the Bollinger Bands RSI Expert Advisor the first thing we do is to use the include function to include the file trade Mqh. This one comes with MQL5 and it provides some simplified trading functions and we also use to include two more modules that we are going to create later on. The first one is to check the entry for the bollinger bands and the second one is for the RSI Oscillator. 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 either use symbol underscore ask or symbol underscore bit and with normalize double and underscore digits we make sure to calculate the right number of digits behind the dot, that is depending on the currency pair we use. Now we use Ctrade to create an instance called trade. That will be used to open the trades later on. And we create an array called price info by using MQL rates. We do that outside of the ontick function because we need the same thing here in the bollinger bands module and in the on tick function we start with array set as series. To sort our price info array from the current candle downwards. Then we can use copy rates to fill our price info array for the current symbol on the chart and the currently selected period on that chart starting from candle zero for three candles. And to calculate the current price we look into the price info array, especially at candles zero and at close price. Now let’s find out how to get the trading signal. That can be done by using a function called check entry bollinger and this function exists in this module here. It is called Check entry bollinger and it will give back a string value to our main module. We start by creating a string variable for the signal. Now we create three arrays for the middle, the upper and the lower band. Array and we sort all three arrays by using array set as series. Afterwards we use the built in iBands function of MQL5 for the current symbol on the chart and the currently selected period on the chart. We want to calculate the values for 20 candles, no shift value and the deviation value is two. The results will be calculated based on the close price. Let’s continue to fill our arrays with copy buffer according to the bollinger bands definition that we have created above. We are going to do that for buffer zero. That’s the middle band array, buffer one for the upper band array and buffer two for the lower band array. All three values are starting from candle zero. That’s the current candle and we want to copy the values for three candles and store them in the according arrays. That makes it possible to get the current values for the middle band, the upper band and the lower band by looking at candle zero in the according arrays. That will give us the price for the current candle and we do that again for candle one. That’s the candle before the current one. And if the close price for candle one of our price info array was below the lower bollinger band, and if it is now above the lower bollinger band, that would mean we have a buy signal. In the other case, if the close price for candle one was above the upper band, and if it is now below the upper band for kennel zero that would mean we have a sell signal and that’s when we assign the word sell to our signal. And finally we return our signal to the main module. And that’s where we check the filter. By using a function check entry RSI, we can find that one in the second module. It is called Checkentry RSI and it returns a string value. Once again we create a signal and we need to create an array for the RSI and then we can use the built in Irsi function for the current symbol on the chart and the currently selected period on the chart to calculate the value for 14 candles based on the close price. Let’s also sort this array by using array set as series with copy buffer we fill our RSI array according to the definition that we have created here. For buffer zero, starting from the current candle zero for three candles. And that makes it possible to get the current RSI value by looking at candle zero in our array. And with normalize double and the last parameter here, we make the output having two digits behind the dots because that is how the RSI value looks like on the chart. Now, if the RSI value is above 70, that would mean we have a sell signal and if the RSI value is below 30, we consider that to be a buy signal. So finally we return the signal to our main module and here we can check if the trading signal equals buy and if the filter also equals buy. And when this condition – and when these conditions are true and positions total returns a value
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 132 STANDALONE BOLLINGER BANDS RSI EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video we are going to create an expert advisor that uses two exponential moving averages and the MACD as a filter to create, buy and sell signals. So let’s find out how to do that with MQL5. To get started, please click on the IDE button or press F4 on your keyboard. Here we have the pre-coded solution. We start by importing the file Trade.Mqh. This one comes with MQL5 and it provides a few functions for position management. The next two include statements here are for the modules that we use to create the EMA crossover signal and the MACD filter signal. We use normalise double and symbol info double for the current symbol on the chart to calculate the Ask price by using symbol underscore Ask and the Bid price by using symbol underscore Bid. And with normalise double and underscore digits, we make sure that we can calculate the right number of digits behind the dot. That is a different number depending on the currency pair you use . Now let’s create an instance of the class Ctrade. That will be called Trade and we are going to use it to open positions later on. Inside of the Ontick function we use MQL rates to create an array for the price data. And with array set as series we sort our price info array from the current candle downwards. And with copyrates we fill the price array with price data for the current symbol on the chart and the currently selected period on the chart. Starting from candle zero for three candles and we store the result in our price info array. To calculate the current price we declare a double variable and that will get the price info value for candle zero. Actually we are going to use the close price and as candle zero isn’t finished so far, the close price is the current price. In the next step we are going to find out if we have a trading signal by using the function Check entry EMA. That’s the one in this module. And afterwards we use a filter signal and check the entry signal for the MACD. That’s the one in this module. And if the trading signal equals buy and the filter also equals buy and we have no open positions, that’s when we use trade buy to buy ten microlot. In the other case, if the trading signal equals Sell and the filter signal also equals Sell and we have no open positions, that’s when we use trade sell to sell ten microlot. Finally, we use the comment statement to output the trading signal and the filter signal on our chart. That’s it for the main module. Now let’s check the EMA crossover module. Here we have a function called Checkentry EMA. First we need to define a string variable for the entry. Then we will create an array for the 20 candles moving average and for the 50 candles moving average to do that, we use the IMA function for the current symbol on the chart and the currently selected period on that chart. We do that for 20 candles or for 50 candles. We don’t use a shift value, so we set that to zero. We use Mode EMA for the close price and we repeat the whole thing here for the second moving average. Afterwards, we use array set as series for the moving average array for 20 candles, and we do that again for the moving average array for 50 candles. And with copy buffer we can fill our moving average array according to the definition that we have created above. The EMA only has one line, and we copy the values from the current candle for three candles and store them in the moving average array for 20 candles or below in the moving average array for 50 candles. And if the moving average for 20 candles is currently above the one for 50 candles, and if it was below for candle one before, that’s when we have a Buy signal, and that’s when we assign the word Buy to our entry signal. In the other case, if the moving average array for 20 candles now is below the moving average array for 50 candles, and if it was above for candle one, that’s the candle before, that’s when we have a sell signal, and that’s when we assign the word sell to our signal. Finally, we return our entry signal to the main module. That’s the one with the Ontick function here. Now let’s check out the MACD filter. Here we have a function called Check Entry MACD. We also create a string variable for the signal. Once again, we need two price arrays, and we use the function IMACD for the current symbol on the chart and the currently selected period on that chart. These are three standard parameters. You can check them out when you open the MACD on your chart, and we want to use the calculation based on the close price.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – 131 STANDALONE EMA MACD EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video we are going to talk about mass tests and why most people don’t get the reason why automated trading works even when you blow up an account. So let’s find out how to do that. This is a system that I’m testing right now. I hope it won’t blow up my computer while I’m recording because it uses lots of performance as it is doing 101 tests here. And that is for eleven years. Here is the current setting. I’m testing the Australian dollar against the yen and I’m doing it for 2010 until 2021. So that’s exactly eleven years. And the little dots here on the screen are results because I’m using a fast generic based algorithm to do all these tests here. That will take some more minutes. But you already can see that we have good results, a good expected pay off. But when you look at the drawdown, you will see that it can be as high as 70%. So at some point in time in these eleven years, your system will go down and down and you will be convinced that it’s going to crash. For some people, even a drawdown of 22% might be too much, while others are able to stand about 70%. And if you scroll down here, you will see that we have lots of different results, a different number of trades, different values for the expected payoff. And that is because I’m trading a random entry here. Now you might ask why should anybody trade a random entry? And here is the answer. Let’s think of a coin toss. If you flip a coin, there is a random chance that you will get heads or tails and that’s about 50 / 50. It might be possible that you lose the coin or that you throw it behind the cupboard. But most of the time you will get either heads or tails. The more often you do that, the clearer is the result. And that’s exactly why I’m doing eleven years for ten or 20 currency pairs and why I use a random entry to find out if it really works. Well, this currency pair looks very good. And this result also is okay. Some people might already give up when they see something like this. Here we have losses. The red dots mean that we have less money than we had before we started to trade for eleven years. And this result is even worse. But let’s have a look at the results here. Even without counting, you might see more green dots than red dots here. It’s even more obvious, I would think that we have 10 to 12% losses here and about 85% to 88% small or bigger profits. Now, most people want to avoid these losses here and once they see a loss, they stop testing. Or they see a big draw down and they stop testing. But let’s sort the results from the last test. I have done a few dozen today. This is the current one. And all the 101 automated tests for eleven years have been profitable. And I wouldn’t have been able to get this result if I didn’t do all the other tests here. So if you see something like this where you make more losses than profits, a simple change of a single parameter could change the whole thing. And the next result could look like this one. But here is where most people get out and say “I have just proven that it doesn’t work”! So really do mass tests for long periods and for lots of currency pairs. You can right click and export the files for Excel. So let’s save this file. And now I will pick the next currency pair and start over again. Here you can see that we have four cores who will do 25 tests each. That will take maybe about 20 minutes. Here is the current status and now you see the first results here. We would have made three times a good profit. And one time we would have lost almost the whole account. But please stick to the idea with the coin toss here. If you would flip a coin four times and you would get two and a half of what you have put in for three times, would it be a good idea to do that? This is a little later. Once again we have made good profits and two times we have made a big loss. Is it worth to trade a system like this one? Well that is exactly what you need to answer. And to do that you need these numbers. We have now done 18 out of 101 tests and you already can see that you have more positive results than negative results. But if you can pick a currency pair would you trade this one? Or would you prefer to trade this one? To find out you really need to do the tests and do the calculation that is involved. Yes it takes time, but in this video you have learned how to decide based on mass testing (!) by using a random entry (!) if the other components of your system work and if your profit expectancy for eleven years is good or bad. Thank you for watching and I will see you in the next video!
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL GRUNDLAGEN – 130 HOW TO IMPROVE YOUR RESULTS WITH MASSTESTS appeared first on MQL5 Tutorial.
In this video we are going to create a bollinger bands standalone expert advisor that is going to actually trade the bollinger band signals. We have already made a sell trade here and now we want to find out how we can do that in MQL5. 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 from template, Continue. I will call this one Simple Bollinger band stand alone. Click on Continue, continue and Finish. And now you can delete everything that is above the OnTick function and we will also remove the two comment lines here. First we need to include the trade mqh file. It will enable us to create a ctrade instance that will be called Trade and we are using it later to open a position. In the Ontick function we first need to create an empty string. We will call it entry. And we don’t assign a value because we are going to calculate that now. But before we do that we need to get the ask price and bid price. That is done by using symbol info double for the current symbol. We use symbol underscore ask to get the ask price and simple underscore bid to get the bid price. The normalize double function in combination with underscore digits will help us to get the number of digits for the current symbol of the current chart. Because we have currency pairs with only three digits and other ones with five digits behind the dot. We also need to create an array for the prices that will be called price info. We use MQL rates for that. MQL rate stores the information about prices like open, high, low and close. Now we sort the price array from the current candle downwards by using array set as series for our price info. Array that we have created here. And after we have done that we use copy rates for our price info array to fill the array with price data for the current symbol and the currently selected period on the chart from the current candle zero for three candles and we store the result in our price info array. We also need to create an array for several prices for the upper and the lower band of the bollinger bands. This is the upper band, this is the lower band. And whenever the price breaks out here and reenters into the bollinger bands, that would be a signal. When it does it from below, that’s a buy signal and when it does it from above like here, that would be a sell signal. Let’s also use array set as series to sort the upper band array and the lower band array. And now we actually define the bollinger bands by using the builtin Ibands definition for the current symbol on the chart under currently selected period we will use 20 candles. If you click on Insert, Indicators, Trend, Bollinger Bands you will see that we use a period of 20 candles. We have a shift value of zero. And the deviation value is two. Also what we use here and the calculation will be based on the close price. Let’s copy the price info into that array by using copy buffer for the bollinger bands definition that we have created here. Buffer one and buffer two are used to calculate the upper and the lower band from the current candle zero for three candles. And the result will be stored in the upper band array or the lower band array. Let’s calculate the expert advisor for the current candle. My upper band value will be the value for candle zero in the upper band array. The lower band value will be the value for candle zero in the lower band array. And to calculate a crossover, we would also need to calculate the expert advisor for the candle before. That is candle 1 and we store the results in the variable my last upper band value and my last lower band value. Now we want to check if we have a re entry from below. That would be true if the close price for candle zero – that’s the current price – is above my lower band value, and if the close price for the candle before was below my last lower band value. In that case we would have a buy entry. So we assign the word buy to our entry. In the other case, if we have a re entry from above. That would happen if the current price is below my upper band value and if the price for candle 1 was above my last upper band value. In that case we assign the word sell to our entry. And if the entry equals sell and positions total is less than one, that would be the case when we have no open positions, we want to sell ten micro lot. In the other case, if the entry equals buy and we have no open positions, we want to buy ten microlot. Last but not least, we want to use the comment function to output the words entry signal followed by our calculated entry directly on the chart. So that’s it. Please click on the compile button or press F7 on your keyboard. This worked without any errors and without any warnings. So now I can click here or press F4 to go back to MetaTrader. And in MetaTrader we click on view, Strategy Tester or press Control and R. And in
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 129 SIMPLE BOLLINGER BANDS EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video we are going to measure the long term trend and calculate if we want to open, buy or sell trades. So let’s find out how to do that with MQL5. To get started please click on the little button here. It is now called IDE. Now you should see the Meta Editor window and a bunch of new icons and here you want to click on File, new File, Expert Advisor from Template, continue I will call this file Simple Long Term Trend. 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. First we want to include the file Trade.Mqh. This one is part of MQL5 and it provides some simplified trading functions and now we can create an instance of the Class C trade. This is called Trade and we are going to use it to open new positions. Inside of the on tick function we first need to create a string variable for the entry. We use Normalize Double and Symbol Info Double to calculate the ask and the bid price for the current symbol on the chart. We either use symbol underscore Ask or underscore Bid and with underscore digits and normalize Double we make sure that we calculate either three or five digits behind the dot. That is depending on the currency pair. Now let’s create two arrays. The first one is called My Moving Average Array 950. The second one is called My Moving Average Array 1000 because this is for 1000 candles and this is for 950 candles. Let’s continue and define the properties. We are going to use the integrated IMA function for the current symbol on the chart and the currently selected period on that chart. In this case for 950 candles. We don’t need any shift value and we are going to use Mode EMA for Exponential Moving Average and this should be calculated based on the close price. Let’s repeat that and calculate the other one. Everything is similar but this time we are going to use 1000 candles. Afterwards we can use array set as series to sort the moving average for the 950 candles and 1000 candles from the current candle downwards and with copy buffer we fill the Moving Average arrays according to the definition that we have created before. For buffer zero starting from candle zero and we want to copy the price values for three candles and store them in the array for 950 candles or in the array for 1000 candles. Because that makes it possible to calculate the entry signal and if the Moving average array for 950 candles for the current candle zero is bigger than the moving Average array for a thousand candles for candle zero that would mean we have a buy signal and that’s when we assign buy to our entry signal. In the other case, if the Moving Average array for 950 candles for candle zero is below the Moving Average array value for 1000 candles for candle zero that would mean we have a sell signal and that’s when we assign the word sell to our entry signal. Finally we want to check if the entry signal equals sell and if positions total is below one that would mean we have a sell signal and we have no open positions and that’s when we want to use trade sell to sell ten micro lot. In the other case if the entry signal equals buy and we have no open positions we use trade dot buy to buy ten microlot. These parts here is the stop loss and the take profit value. You see that I have chosen 50 points for each value and this is the very interesting part. If you play around with the settings here you will find out what you can do to improve your results. So really do that! For now we are done. I have to remove the additional bracket here. Now let’s click on the compile button. Or Press F7 on your keyboard. That should work without any errors and if that is the case you can click on a little button here or Press F4 to go back to MetaTrader. And in MetaTrader please click on view, strategy tester or press control and R. Please pick the new file simple long term trend EX5, mark the option for the visual mode here and start your test. Here we are, the expert advisor is running, you see these two moving averages here and we already have the first position. So our little expert advisor works as expected and in this video you have learned how to create an expert advisor that is able to calculate the long term trend with two moving averages and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 128 SIMPLE LONG TERM TREND appeared first on MQL5 Tutorial.
In this video we are going to find out how to create an Expert Advisor that is able to trade buy and sell trades for this Indicator; it’s called the Envelopes Indicator, we have just opened a new position everything is traded automatically and it will also output buy and sell signals directly on the chart. So how are we going to code it in MQL5? To do that please click the 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/ Expert Advisor (template)” from template, I will call this one: “SimpleEnvelopeStandaloneExpertAdvisor”, click on “Continue”, “Continue” and “Finish”, let’s delete everything above the “OnTick” function and remove the two comment lines here. We start by including the file: “Trade.mqh” that comes with MQL5 and afterwards we create an instance from “CTrade” that is called: “trade” and we are going to use it to open new positions later on. Inside of the “OnTick” function we need to calculate the Ask price and the Bid price that can be done by using: “SymbolInfoDouble” for the current symbol on the chart, with SYMBOL_ASK” we will get the Ask price and with “SYMBOL_BID” we will get the Bid price. If you click on a currency pair you will see a red and a blue line, the red is the Ask price and the blue is the Bid price. There are some currency pairs with 3 digits behind the dot and others have 5 digits, so we use “NormalizeDouble” and “_Digits” to automatically calculate the right number of digits for the current currency pair. Now we create a string called: “signal”, we will assign the signal later on, right now it’s empty, let’s create an array for the prices (PriceInformation), we use “MqlRates”, if you mark “MqlRates” and press F1 you will learn that it stores the information about prices, volumes and spread and the array will be called: “PriceInformation”. We sort the array downwards from the current candle by using “ArraySetAsSeries” and with “CopyRates” we fill the price information array (PriceInformation) for the current symbol and the currently selected period on the chart. We start with the current candle 0 (zero) and we will fill it with price information for 3 candles. The Envelopes Indicator has 2 bands, the blue one and the red one, so we also need two arrays for the upper band array (UpperBandArray) and the lower band array (LowerBandArray), these will also be sorted by using “ArraySetAsSeries” and now we can create our envelopes definition (EnvelopesDefinition) by using the “iEnvelopes” function that is included with MQL5. This one also needs a few parameters: the first one is for the current symbol on the chart the second one for the period we are using, it will be calculated based on 14 candles and if you click on: “Insert/ Indicators/ Trend/ Envelopes” you will see the 14 candle period here, the shift value is 0 (zero), the deviation is 0.100 and the calculation will be based on the close prices and that’s exactly what we use here for the rest of the parameters. Now we use “CopyBuffer” to fill our upper and our lower band array according to the envelopes definition (EnvelopesDefinition) that we have created here, the first one will be filled for the buffer 0 (zero), the second one for the buffer 1, we start with candle 0 (zero) and copy the data for 3 candles. Let’s calculate the current value for the array values (myUpperBandValue and myLowerBandValue), when you hover with your mouse you will see that there is a value that is constantly changing and that’s what we need so we look at candle 0 (zero) in the upper band array (UpperBandArray) and the lower band array (LowerBandArray) and we use “NormalizeDouble” and a 6 to get only 6 digits behind the dot – that’s what “NormalizeDouble” does, its rounding floating point numbers to a specified accuracy – for the first parameter we say what we want to get rounded, the second parameter is for the number of digits we need and if the last candle closed below the lower band so if the close price for candle 1 in the price information (PriceInformation) is below the value for the lower band (myLowerBandValue) that would be a buy signal so we assign the word: “buy” to our signal. Otherwise if the close price for candle 1 in our price information array (PriceInformation) is above the upper band value (myUpperbandValue) that would be a sell signal and now we assign the word: “sell” to our signal. And when the signal equals sell and the function: “PositionsTotal” is below 1 – that expression will tell us that we have no open positions – and if that is the case we use “trade.Sell” to sell 10 micro lot. In the other case if the signal equals buy and “PositionsTotal” is below 1 then we use “trade.Buy” buy to buy 10 micro lot. Finally we create a chart output by using the “Comment” function that will output the words: “The current signal is:” and the calculated signal. Okay, that’s it! Please click on the “Compile” button or press F7, now you should see that you have no errors and in that case you can click on the little button here or press F4 to go back to Metatrader and in Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, we pick our new file: “SimpleEnvelopeStandaloneEA.ex5”, please enable the visualization here and start your test. …and here is our little Expert Advisor at work, we have already opened the first position and now you know how to automate the Envelopes Indicator and how to create an Expert Advisor that is automatically going to trade it and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE ENVELOPES STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
In this video we want to create a little Expert Advisor that will tell us how many positions we have opened for a currency pair. An Expert Advisor like this is useful if you want to handle more than one position for each currency pair as I do, this is called a Multi-currency Bot. As you can see I have opened one, two, three, four, five, six positions for the Euro U.S. dollar. So if I click on Euro U.S. dollar and drag it on the chart, it will say positions for this currency pair six. Now how can we do that? First of all please click on this button here or hit the F4 key to bring up that Meta Quote language editor also called Meta Editor. Now we need to click on new and select Expert Advisor from template, click on continue, I will give it the name Simple Position Count. Click on continue, and finish. You can delete everything above the OnTick function. We also will remove the two comment lines here and the first thing below is a variable but it will be a local variable to count the positions for this currency pair. Now we are going to count all the open positions, that is done by using the function PositionsTotal, subtract one and count down to zero until we have no open positions. We will need to open a bracket for loop, and a closing bracket, and between these two brackets we will get the symbol of the open position by using the function PositionGetSymbol. And if the symbol position is equal to the symbol on the chart, we want to add the value one to the current positions for this currency pair. And after we have counted all positions, we want to output the current positions for this currency pair on the chart. This is the text, this is the value and we are using the Comment function. So this is it. Let’s see if it compiles. Okay that worked without any errors or warnings. So let’s hit the F4 key, open a chart window and drag the EA simple position count on your chart. And it says we have two open positions for this currency pair. This is one and this is the other one. So let’s switch to Euro U.S. dollar, and now it says we have six open positions. Let’s check the Australian against the Canadian dollar and it says we have one open position, and this is this one. In this little video you learned how to create a simple MQL 5 Expert Advisor to count the positions for a currency pair and output the number on the chart.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 Tutorial – How to simply count your positions with MQL5 appeared first on MQL5 Tutorial.
Today we are looking at the advanced trailing stop. We have two open positions here, and as you can see, we have two trailing stops. I will speed it up a little bit here and now our two stops have been triggered and our trailing stop is continually rising – if the price is going up. And if the trailing stop is below 150 points from the current ask price. So let’s zoom in here and you can see what happens. Now the price is going up and you’ll see the trading stop is rising and as the price falls nothing happens. But when it goes up again, you will also see the rising trailing stop here. Actually, it’s two lines for two trailing stops. Now how can we create an expert advisor that is going to trail the stop loss for each of the open trades? To do that, please click on the little button here or Press F4 to open the Meta Editor. And in the Meta editor, you want to click On File, new, Expert Advisor from Template. Continue. I will call this Expert Advisor advanced Trailing stop. Continue, continue, finish. And now we can delete everything above the Ontick function and the two comment lines here. To use the trailing stop, we need an open trade, so let’s include the trade MQ file here and create an instance of the class Ctrade. And in the Ontick function, we need to calculate the ask price. That is done with the function symbol info double, and we use normalize double and the expression digits to get the actual value for the currency. Because we have some currencies with three and other currencies with five digits behind the dot. And we do that for the current symbol on the chart. And we use symbol underline Ask to get the ask price and put it into this double variable. If you mark symbol underline Ask and press the F1 key, you will see that you can get lots of information. For example, symbol underline bid would deliver the bid price. In our example, we want the trailing stop to work for more than one position. So now we check if we have less than two opened positions, and if that is the case, we use our trade instance to open a buy position. It will have a stop loss of 1000 points, and it will have a take profit of 500 points above the ask price. And now we want to call a function that will use the name Check trailing stop, and we deliver the ask price as a parameter here. This is the end of the Ontick function, and now we will create the function with the name check trailing stop. It needs the ask price as a parameter, and the first thing in the new function will be to set the desired stop loss to 150 points. So we create a double variable called Sl for stop loss. This expression will set it 150 points below the Ask Price and we use normalize double and underline digits to get the right value for a three digit or a five digit currency pair. Now we want to check all open positions for the current symbol. By counting through all the positions. And to get the position symbol, we use the function position get symbol for the current position. And if the symbol on the chart equals the symbol of our position, we need to get the ticket number of this position. That will be assigned to a variable called Position ticket and we can get it by using position get integer for position underline ticket. Now let’s define a double variable with the name current stop loss. That will get the current position stop loss by using Position get double and the expression position underline SL. If you Press F one on your keyboard while this expression is marked, you will see that position underline SL will deliver the stop loss level of an opened position and position underline TP will deliver the profit level. And if the current stop loss is below 150 points from the current ask price, remember, we have defined the 150 points for the SL variable in this line, so if the current stop loss is below the defined stop loss, we want to modify the stop loss by ten points that is done by using trade dot position modify for the current position ticket and we will use the current stop loss and add ten points to it. Okay, let’s close all the open brackets and click on the compile button here, and that did work without any errors. So now we can click on the button here or press F4 to go back to MetaTrader. And in MetaTrader, you want to click on View, Strategy Tester or press Control and R on your keyboard. And in the strategy tester, you want to select the advanced trailing Stop ex5 file.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 Tutorial – Advanced Trailing Stop appeared first on MQL5 Tutorial.
In this video we are going to create an object. This is a circle. It will show us the last, highest and lowest candle within the last 30 candles. So let’s find out how to do that with MQL Five. To get started 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 Ellipse Object as our circle is actually an Ellipse. Now let’s click on Continue, continue and finish. Now you can delete everything above be on Tick function and let’s remove the two comment lines here. We start by creating a variable for the highest and the lowest candle. Let’s also add two arrays for the High and the Low values. We use Array set as Series to sort the High and the Low array from the current candle downwards. And now we can fill our array for the current symbol on the chart and the currently selected period on that chart. From candle zero to candle 30, we use Copy High to copy the highest prices of each candle in the High array. The same can be done for the Low array, we use Copy Low. Everything else is the same, but this time the values will be stored in our Low Array. That makes it possible to calculate the highest candle by using Array Maximum. That will give us the highest value within our High Array. Starting from Index zero for 30 candles and as you might have guessed, for the lowest candle, we use Array Minimum and we look into our Low Array from candle zero to candle 30 and store the lowest value in this variable here. With MQL Rates, we create a Price Information array for the candle prices. This one as well needs to be sorted with Array set as Series and with copyrates for the current symbol on the chart and the currently selected period on that chart. Starting from candle zero for all the bars on the chart, we want to store the values in our Price Information array. This expression will give you all the bars that are available. On a slow computer you might use a fixed value like here for 30 candles. Now we have everything we need, but before we draw the circle, we want to use Object Delete for the current symbol. And we want to delete all the former Ellipse objects. You might not have such an object, at least for the very first time when you start the Expert Advisor. But once the old object is deleted, we can draw a new one. That is done by using Object Create for the current symbol on the chart. This is the object name. This is the object type. We use OBG_Ellipse. The object should be drawn in the main window. It will be started at the time when candle 30 has been drawn on the chart that is the left border. The upper border is for the highest price of the highest candle. The right border is the point in time where we see candle zero, the current candle . And the lower border will be the lowest price of the lowest of the last 30 candles. Let’s set a few object parameters. I would like to change the object line color. That can be done by using object set integer. If you mark that and Press F1, you will see that we need to pass a few parameters. The first one is for the current chart ID. Zero means we want to do it for an object in the main chart with the candles. The second parameter is the name of the object. The third one is the property that we want to change. In our case we want to change the object property color and we want to set it to blue. The next property I want to change is called object property fill. That’s the background color of the object and I want also to set it to blue and that’s about it. 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 videos in the basic video series. Or maybe even the premium course on our website might be interesting for you. That’s why you also can find source codes like this one in the shop. In case you don’t want to type everything. But 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 F4 to go back to Metatrader. And in MetaTrader we click on view, strategy tester or press control and R. Please pick the new file simple ellipse object ex five. Mark the option for the visual mode here and start your test. Here we are, we see that our circle is drawn and it is moving. And in this little video you have learned how to create an expert advisor that is able to draw a circle object and you have coded it yourself with a few lines of MQL five code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS 127 – SIMPLE ELLIPSE OBJECT appeared first on MQL5 Tutorial.
In this video we are going to create an Expert Advisor that is able to calculate the time that has passed since we have started the Expert Advisor. This can be useful for several things. Let’s find out how to do that with MQL Five. 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 Running Timer. 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 start by defining three datetime variables. Date time is the type of variable that we are going to use when we use something that contains a date or a time. And to get the time that the Expert Advisor is running, we want to check if the start time equals zero. That will be true the very first time we start the Expert Advisor. And if this is the case, we want to set the start time to time local. Time Local is a function that will return the local time of the computer where the client terminal is running. So this is the initial value for our counter and all the other times the current time will be set to time local because time is moving. So this value will change every time a tick comes in. Well the Ontick function will not run every second, it runs whenever the price changes, so keep that in mind. Now let’s calculate the past time. The past time will be the current time and we subtract the start time. Now let’s use MQL date Time. This is a date type structure and it makes it basically possible to get time based values in different formats. For example, we can calculate the hour, the minutes and the seconds. And that’s exactly what we are going to do now. To do that, we use Time to Struct. The first parameter is the past time. The second parameter is the date time structure that we have created here. To calculate the hour based value, we create an integer variable here and we assign Date Time structure dot hour for the minutes. We do the same, but this time we use date time structure dot min. And for the seconds we use Date Time structure dot SEC. If you would need something like days, this also would be possible because once you hit the dot you can pick one of these values here. The hour, the minute and the seconds will be enough for us. Now let’s create a chart output using the comment statement. This will output the start time, the current time, and the past time in hours, minutes and seconds. 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 videos from the basic video series or maybe even the premium course might be interesting for you. You can find that one on our website where you can also find a link to the store where you can download source codes like this one in case you don’t want to type everything. By the way, this once again was a suggestion from a premium course member. And if you are a premium member and if you have an idea for a video like this one, please let me know. For now, please click on the compile button here or Press F seven on your keyboard. You shouldn’t get any errors here and if that is the case you can click the little button here or Press F four to go back to MetaTrader. And in MetaTrader please click on view, Strategy Tester or press Control and R. Please pick the new file simple runningtimer EX5. Mark the option for the visible mode here and start your test. Here we are, our expert advisor is running. It counts the hours, the minutes and the seconds. This might be useful if you want to do something that is time related. From now on you will find the first videos for this MQL five tutorial in 26 languages. We have created subtitles for YouTube. And in this little video you have learned how to create an expert advisor that is able to calculate hours, minutes and seconds and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 126 SIMPLE RUNNING TIMER appeared first on MQL5 Tutorial.
In this video we are going to talk about simple event handling. Event handling is something that happens when you try to interact with your chart; in our case we are going to find out how to get a simple mouse click. Let’s left-click on the chart here and we get the text: “You pressed the mouse at the following coordinates:”, we have an “x” value and the “y” value here and when I press the mouse on the left side of the chart here you will see that we have a low “x” value because the “x” axis goes from the left to the right and the “y” axis goes from the upper to the lower border, so when I click here at the middle of the upper border we have a high “x” value and a low “y” value and you will get the highest values in the lower right corner here. In this video we are going to find out how to code and MQL5 Expert Advisor that is able to capture the coordinates of the mouse click wherever you click on the chart. To do that please click on the little button here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to select “File/ New/ Expert Advisor (template )” from template click on “Continue”, I will call this Expert Advisor “SimpleMouseClick”, click on “Continue”, “Continue” and “Finish” and now you can delete everything above the “OnTick” function here and the two comment lines and usually we would use the “OnTick” function here because this one is triggered whenever the price changes on the chart, but in our special case we are more interested in mouse clicks so let’s change the “OnTick” to an “OnChartEvent” function. The “OnChartEvent” occurs whenever you do something on the chart, for example you could press a key, move your mouse, create or change an object and whenever that happens the “OnChartEvent” will be fired. It has a few parameters; the first one is an ID – that’s for the event ID –, the second one is of the type long; it’s called “lparam” for long, the third parameter is the “dparam” for double 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. MQL5 has a special kind of event type that is called “chartevent_click”, let’s mark that and trust the F1 key and we learn that we have “chartevent_KEYDOWN”, “chartevent_MOUSE_MOVE” or in our case “chartevent_click” for clicking on the chart and if our first parameter for the ID equals “chartevent_click” we want to use the built in comment function to output the text: “You pressed the mouse at the following coordinates:” followed by the “x” and the “y” value. The x value will be delivered by the “lparam” and the y value will be delivered by the “dparam”. Please don’t forget the closing brackets here and when you’re done you can click on compile or press F7 on your keyboard; that worked without any errors or warnings so now we can click on the little button here or press F4 to go back to Metatrader. In Metatrader we would usually click on “View/ Strategy Tester” or press CTRL and R and we are still able to pick the “SimpleMouseEvent.ex5” file here and start a test but when we click on the chart we don’t get any output, so let’s stop the test here and simply drag the Expert Advisor with the name: “SimpleMouseEvent” on your chart, let’s confirm the question if we really want to attach the “SimpleMouseEvent” on to our chart, so now you know how to create an Expert Advisor to get the coordinates for the “x” and the “y” values for any point on the chart and you have created it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE MOUSE CLICK EVENT appeared first on MQL5 Tutorial.
Welcome to our new documentation series on creating your own Algo Trading System Farm. We use automated voices and technologies to help you improve your results faster and with less effort. In this part, we will look at the basic installation of MX Linux. First of all you have to find out how to change the startup settings on your computer so that the installation works later on. This varies depending on the type of computer but most of the time you can get into the configuration by pressing a certain key like Escape or F1. There you can make a setting that allows us to start from a USB stick. But first we have to create this USB stick. There are different programs for this and depending on the operating system it is quite different. Most people watching these videos will probably start from a Windows operating system and there is a very good and easy way to create a USB stick from our downloaded ISO file. In the last part we said that we want to download the 64 bit version for Fluxbox. But in fact MX Linux offers the possibility to download a 32 bit version. So even 15 year old computers can be used with the latest software. In our example we use a device from 2010. In fact, I also have some netbooks that only work with 32 bit operating systems. They run MX Linux smoothly even with only one gigabyte of memory. However, these devices are not really suitable for building an algo trading server farm. Instead, we use a Tecra A11 notebook from 2010. This device is no longer a high-performance computer, but the RAM can be upgraded to 8GB. That was quite expensive in the last few years, but meanwhile the technology has developed so much that the RAM for such outdated devices has become very cheap again. Now to create our boot medium on the USB stick we need an appropriate program. Therefore we first download the portable version of the software Rufus for our Windows PC. Rufus is a software that is able to create a boot medium within a few minutes even without installation on your Windows PC. The portable version can be started after the download with a mouse click and here we will get the corresponding ISO image of the version we downloaded for MX Linux. We also need a USB stick that is capable of actually functioning as a boot medium. Most current USB sticks should be able to do this without any problems. We have a 32 gigabyte one here, but if you have an old USB stick lying around that has 8 GB or more then it will do. Before you can write the ISO file to the USB stick, please make sure twice that you have selected the correct setting for the target drive. In case of doubt, please remove all external USB devices like hard drives or SD cards in case of notebooks. This will help to avoid confusion. After you have made all the settings accordingly click on the appropriate button to create the USB stick. This should be done within five to ten minutes. Once that is successfully completed, we insert our newly created USB stick into our target computer for the start of MX Linux. Don’t worry, nothing will be installed yet. Before starting the installation process, MX Linux will first run in test mode on the target computer. This gives you the opportunity to make sure everything works before overwriting your other operating system. If you want to backup your former Windows system before overwriting it with MX Linux, there is a very good and free solution from a company called Lazesoft. It is the so-called Recovery Suite. With it, you can restore the installation from your Windows machine via a USB device as well, if needed. By the way, the Recovery Suite is also capable of backing up even large Windows installations to an external hard drive via a USB port. Okay, that’s it so far with the preparations for the installation of our first server for our Algo Trading System Farm. If you want to run your own Algo Trading System, just subscribe to our Youtube channel. If you need better results faster, then take a look at the premium course on our website. If you have any questions or suggestions about the content in this video, just send us an email. We always reply ourselves and usually within 24 hours. For now, we say thank you for your attention and see you in the next video.
Not sure what to do? Click on the automated trading assistant below
The post LEARN MQL5 TUTORIAL BASICS – LEVEL 1C BUILD YOUR OWN ALGO TRADING SYSTEM FARM appeared first on MQL5 Tutorial.
Welcome to our new documentation series on creating your own Algo Trading System Farm. We use automated voices and technologies to help you improve your results faster and with less effort. Okay, let’s get started! Today we will start building our infrastructure so that by the end of this course we will have an automated trading system farm. Until then it will take some time, because I will not be able to contribute information on this topic every day. There are different reasons for this. The first reason is the current rather tense political situation here in my area. The second problem is that we have some health issues to deal with. For example, we are in a situation right now where my father is dealing with a stroke and hemiplegia and has been institutionalized. The third problem concerns economic aspects. Of course, as an economically oriented company, we have to do certain things in a certain order so that the bottom line can cover net needs and costs. In plain language, this means that this project will be completed bit by bit, but at the moment we can’t say how fast or slow the upgrade will be due to the circumstances mentioned above. Most viewers will probably already have an operating system that they want to continue using. In our case, however, we will be using a 10 year old netbook and installing the software that we currently think is the best solution for those who have not yet chosen an operating system as their only option. This software is a Linux distribution based on Debian called MX Linux. MX Linux has managed to grab the first place on the list of the most popular Linux distributions within the last few months. And the reason for this is quite simple, with this software you can do many things that are very difficult to do with other Linux distributions. Many things work already after the first installation, the hardware is recognized very well, even if the devices are more than 10 years old. In addition, MX Linux is able to run a very modern and up to date version of Linux with very few resources without having to deal with any command line commands all day. In plain language this means for all who want to use MX Linux that you can combine the advantages of several worlds and still be able to use a performant and easy to use operating system without having to pay license fees. We have tried several different Linux flavors for our own company over the last few years and most of the time you hit a limit at some point that doesn’t allow you to continue. In this case it’s relatively easy to implement, you don’t need any special knowledge. And for MX Linux there are so many helpful documents on the web that even beginners should be able to handle it better than with Windows. The interface and the appearance can be completely adapted to your own wishes, so that even as a MacBook user you could be of the opinion that you are using an up-to-date system from Apple. But that’s not really that important for us. For us it’s much more important that pretty much all hardware that has come out in the last ten years is supported and that includes the now 12 year old netbook that we use for it. You should be able to follow every single step easily. So this documentation series might be a bit long for some people if they are already familiar with Linux. But many people have not had any contact with Linux until now and may have been willing to pay the license fees for a single operating system in the past. We did that too, but Linux offers us a decisive advantage for our server farm. This advantage is that we are able to use modern technology to cost-effectively run even old hardware without having to pay additional license fees, even if we want to expand our server farm to 50 or 100 servers. This may not be very interesting to some viewers now, but I can promise you that in the next few years you will see that exactly such systems will make the difference between good and bad results in trading. In the past, technology that gave you a decisive advantage was not affordable. Today you can change that for yourself and your own Algo Trading System Farm. Therefore, please download the latest version of MX Linux for 64 bit with the desktop solution Fluxbox now. Okay, that’s it for today. If you are thinking about building your own Algo Trading Server Farm, please subscribe to our Youtube channel. If you need faster and better results, then why not check out the premium course on our website. If you have any questions or suggestions about the content in this video, just send us an email. We always reply personally and usually within 24 hours. For now, we say thanks for watching and see you in the next video!
Not sure what to do? Click on the automated trading assistant below
The post LEARN MQL5 TUTORIAL BASICS – LEVEL 1B BUILD YOUR OWN ALGO TRADING SYSTEM FARM appeared first on MQL5 Tutorial.
Welcome to our new documentation series on creating your own Algo Trading System Farm. We use automated voices and technologies to help you improve your results faster and with less effort. This is a new project that has been on my mind for a while and in the last weeks I have been asked from time to time if and in which form something new from me on the topic of Algo Trading will be released. In fact I spent some months with another project about automatic customer acquisition and this project is finished since this week. So I thought about what one thing I would like to do now and decided to tackle the topic Algo Trading System Farm here as a documentation. The goal of this documentation should be to create an infrastructure with a few minutes effort every day. This solution should enable you to run several Algo Trading Systems for Metatrader on any operating system, which are able to trade independently 24 hours around the clock on up to 22 charts fully automatically. No matter if you want to do this on a Windows PC, on a Linux computer or on a MacBook. And no matter if you want to trade with MetaTrader 4 or MetaTrader 5. For all these solutions there will be a possibility here that also works on your own computer. We will use a variant that consumes very few resources and even runs on a 10 year old netbook. This means that you can now go to the basement and revive your old PC from 10 years ago and use it for your own automated trading system with Metatrader. We will go step by step and use the possibilities that modern technology offers today. This also includes that I use technologies for this content here that allow me to dub the created videos in multiple languages and also fully automated. For the English MQL5 channel I will use my own voice but for other languages and the MQL4 channel I will use automatic solutions. Okay, that’s it for today. If you have any questions or suggestions about the content in this video, feel free to send me an email. I always reply personally to emails and usually within 24 hours. If you simply want to improve your results with automatic trading, then subscribe to our YouTube channel. If you need faster and better results, then check out the premium course on our website. For now, I say thank you for your attention and I’ll see you in the next video!
Not sure what to do? Click on the automated trading assistant below
The post LEARN MQL5 TUTORIAL BASICS – LEVEL 1A BUILD YOUR OWN ALGO TRADING SYSTEM FARM appeared first on MQL5 Tutorial.
In this video we are going to create a sell trailing stop that is triggered by the Average True Range indicator. So let’s find out how to do that with MQL 5. To get started please click on the little button here or Press F4 on your keyboard. Now you should see the Meta Editor window until 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 remove the two comment lines here. We start with an Include statement to include the file trade mqh. This one contains the class Ctrade and we are going to use an instance called Trade. Let’s set a basic variable for the stop loss points. We also need to calculate the stop point value and we use a global declaration for the bid price. And inside of the Ontick function we want to have a string variable for our signal. Now we are going to calculate the bid price. That is done by using symbol info double. For the current symbol on the chart we use symbol underscore bid. And with normalize double and underscore digits we can automatically calculate the right number of digits behind the dot depending on the currency pair. Now let’s create a price array. This is a double array and let’s define the Average True range here. That is done by using the IATR function that is included in MQL5. It uses a few parameters. The first one is for the current symbol on the chart, the second is for the selected period on that chart and we will calculate the result based on 14 candles. Now we use array set as series to sort our price array from the current candle downwards. And with copy buffer we fill our price array according to the definition that we have created here for buffer zero starting from the current candle zero and we want to copy the data for three candles and store them in the array. Now we can get the Average True Range value for the current candle by looking at candle zero in our price array. I use Normalize Double and Five to cut off five digits. Because that is how we see the Average True range indicator is shown on the chart. I also want to declare a static variable for the old value because I want to know if the current value is below the old value and if that is the case, we want to set our signal to sell and now we use trade sell. And if the signal equals Sell and positions total is below one, we have no open positions but a sell signal and that’s when we use Trade sell to sell it 10 microlot. This is a test position. We do it on a demo account because to trigger a sell trailing stop we need to have a position. And now we want to get the calculated stop point value by calling a user defined function called Check ATR Sell trailing stop. We pass the average true range value that we have calculated as a parameter. Now let’s add a chart output by using the comment statement. This will output the current signal, the average true range value, and the calculated stop point value. Afterwards we assign the average true range value to the old value for the next time. And that’s it for the main function. But this function doesn’t exist, so we need to create it right now. Our user defined function will have the name Check ATR Sell trailing stop. It gets the average true range value as a parameter here. We use this little formula to calculate the stop point value by using the defined basic stop point value and we will add this multiplication here. Now we are able to calculate the stop loss price. That is the current bid price plus the calculated stop point value times the point value. With the for loop we go through all the open positions to get the symbol of the current position we use Position get symbol for the current counter value. And if the current symbol on the chart equals the position symbol we want to continue. So let’s get the position ticket by using position get integer and the parameters we use is position underscore ticket. To get the current stop loss we use Position get double and we use the parameter position underscore SL. And if the current stop loss is greater than the calculated stop loss price or the current stop loss equals zero, that would be the case the very first time we run the Expert Advisor. That’s when we use Trade dot position modify for the current position ticket. To modify the calculated stoploss price. The last parameter would be the take profit value, but we want to leave that unchanged. All we need to do now is to close the loops, return the calculated stop point value to the main function, and close our function. That’s about it. 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 former basic videos, or maybe even the premium course might be interesting for you. If that is the case, you can find it on our website where we also have a link to the shop where you can download source codes. If you don’t want to type everything yourself, let’s remove the additional bracket here and click on the compile button or Press F 7. You shouldn’t get any errors here, and if that is the case, you can click on a little button here or Press F4 to go back to MetaTrader.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 125 SIMPLE ATR SELL TRAILING STOP appeared first on MQL5 Tutorial.
In this video we are going to create an Expert Advisor to calculate the closing time for already closed positions. So let’s find out how to do that with MQL 5. To get started, please, 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 Close Time. Click on Continue, continue and finish. Now you can delete everything above the on tick function and let’s also delete the two comment lines here. We start with an Include statement to include the file Trade.Mqh. This contains the class Ctrade and we are going to create an instance called Trade. Inside of the On Tick function we want to calculate the Ask price and the Bid price. That can be done by using Symbol Info Double for the current symbol on the chart. We either use symbol Ask or symbol Bid. And with normalize double and underscore digits we make sure to calculate the right number of digits behind the dot. As we want to calculate the time for Order closing, we obviously need to open a few positions. We use Trade Buy or Trade Sell to open a test position for ten microlot. You wouldn’t do that on a real account, but that’s what demo accounts are good for. And obviously we need positions or we wouldn’t be able to calculate any close times. And to do that we want to call a user defined function called Get Closetime. This function doesn’t exist so far, so we need to create it now. So let’s go on. The name of the user defined function is Get close Time. We use Void here because we don’t need to return any values. We need to declare a few variables. You may not need all of them, but I have used them in another video. And this one is the most important thing for us. We want to calculate the time when a position was closed. So let’s get started and use History select, starting from the current time. We want to go through all the closed orders and positions in our case and for each entry we want to get the ticket number. That can be done by using History Deal Get ticket for the current counter value. And if that is greater than zero we start to read out the position properties. For example, the order profit will be calculated by using History Deal Get double for the current ticket number. And we use Deal underscore Profit here. The order type can be calculated by using History Deal Get integer for the current ticket number. And this time we use Deal underscore type. Let’s continue and calculate the current symbol by using history deal get string for the ticket number and we use Deal underscore Symbol. The next item is the entry type. The Deal entry will be calculated by using history deal get integer for the current ticket number and we use deal underscore entry. And now comes the interesting part because we want to get the deal time. That is done by using history deal get integer for the current ticket number and this time we use deal under score time. But as you see we will receive an integer value that is not very good to read for humans. So the closing time in our case needs to be reformatted by using time to string for the deal time that we have calculated here. And we use time underscore date and time underscore seconds to make it more readable. And if the current symbol for the deal fits and is equal to the symbol on the chart, we want to find out if it is a buy or a sell order because we don’t want to calculate anything for pending orders. And we also want to know if the order was actually closed. That would be the case when the deal entry value equals one. And if all conditions apply, we will calculate our result. This is a string value that we will print out in our Journal. It contains the values for the profit, the ticket number and the closing time. So let’s use the print statement to print it out to the Journal tab. Finally, we need to close the loops 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 might want to consider to become a premium member. You can find the premium course on our website and this actually was a suggestion of a premium course member. So if you are a premium member and have an idea for a video like this one, please let me know. So let’s remove the empty lines here, press the compile button or Press F seven on your keyboard. And if everything went well, you shouldn’t get any errors here. And if that is the case, you can click on this little button or press a four to go back to Meta trader. And in Metatrader please pick the new ex5 file that we have created here. Mark the option for the visible mode and start your test. Okay, this is the Expert Advisor running. Let’s speed that up a little bit. So far we have no order that has been closed. So we clear the Journal here and once we hit a take profit or a stop loss we should see the ticket items appear here. Let’s speed it up again. So here we are. Now you can see all the information that you need including the closing time. So our little expert advisor works as designed. And in this little video you have learned
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 124 SIMPLE ORDER CLOSE TIME appeared first on MQL5 Tutorial.
In this video we are going to check the Journal for error codes and find courses for errors. So let’s find out how to do that with MQL 5. This should be a trailing stop. Actually it’s a sell trailing stop but it doesn’t work. The stop doesn’t move. Now we need to find the cause. If we look at the history, we see that there are no stop loss modifications. There’s nothing that we can find. But when we click on the Journal tab we should see that we have modification errors here. You see the red marks and this is when we see errors during the execution. But this is only a small part of the journal and you might look at a time when no error is occuring. And when you look at it you might not see any errors because they maybe happen only once a day. So let’s stop the test here. My journal is still running. It might take a few seconds before all the entries are written. That happened right now. So we can now right click onto one of the entries and select open. This will open the logs directory here. This is the current log file from today. You can see that it contains the date and when you point your mouse cursor over the file you will see that it is a very large file. In my case it’s 479 megabytes. That’s almost half a gigabyte. Now we can right click on the file and can Select Open. But when we do that it will probably crash because Notepad as it is delivered with Windows is not a good tool to open files of this size. In my case, I’m going to use Notepad Plus Plus. This is a free software that you can download from Chip or any other websites. And this editor is able to open very big files. When we scroll down, we can see that this file has thousands and thousands of lines. We could now manually scroll through the file, but this could take hours. But one of the best things in Notepad Plus Plus is that we have a very good search function. Let’s change the language here to English. That might be better for you. Now I can click on Search and Find and I can look for certain terms. Here we have the term log in. And what I can do is I can type in or copy and paste the term I’m looking for and click on this button “Find all in current document”. And it will now show me the lines that contain my search term and I can click on these lines here. And it will jump to the search results. In our case we know that we wanted to move a stop loss. So I’m going to click on Search, Find. And I will look for the term failed. Click on Find all in current document. Well this might take a little while because it’s a very large file. And here is my search result. So this is a very fast and easy way to find errors in big log files. In this case it’s easy to see what is causing the error. So let’s go to Google and look for MQL 5 error codes. This is the first entry and this table will show you the different error codes that can happen. And the cause of the error, like in my case the invalid stops. So if your expert advisor is not doing what it is supposed to do, you now know how to find the errors in the journal. Because in this video you have learned how to find error codes even in big journal files and you have done it yourself in a few minutes.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 123 HOW TO FIND ERRORS IN BIG JOURNAL FILES appeared first on MQL5 Tutorial.
In this video we are going to use the average true range indicator to open buy trades and to set a trailing stop value for buy trades. So let’s find out how to do that with MQL 5. 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 Average True Range Buy 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 start with an include statement to include the file trade.Mqh. This will allow us to use the class Ctrade. We are using an instance of Ctrade called Trade here. Let’s define a few global variables. Global variables are defined outside of other functions. They are accessible for each of the functions. The first one is an int variable for the basic stop point value, we will start with 100 points. The second one will be the calculated stop point value. The third one is for the ask price. Inside of the on tick function we start by creating a string variable for the signal. We don’t assign a value here because that’s what we are going to calculate later on. Let’s continue and calculate the Ask price. That is done by using symbol info double for the current symbol on the chart. We use symbol underscore Ask, all in capital letters here and with normalize double and underscore digits, we make sure to calculate the right number of digits behind the dot. Now we need to create a price array, that is a double array so it can hold floating type values. We are going to use the included IATR function to define the average true range parameters here, for the current symbol on the chart and the currently selected period on the chart. We want to calculate values for 14 candles to sort the array from the current candle downwards. We can use the array set as series function for our price array. With copy buffer we can fill our price array with data according to the definition that we have created here, we are going to copy values for buffer zero starting from the current candle zero, for three candles and store the result in our price array. That makes it possible to calculate the average true range value for the current candle. We just have to look at the value of candle zero in our price array, and I use normalize double and five again to get five digits behind the dot, like it is shown here. Let’s add another static double variable. Static means that the value for this variable will be inside of the computer memory for as long as our computer program is running. Now we can check if we have a buy signal. That would be the case if the current average true range value is bigger than the old value. If that is the case, we will set our signal to buy and that’s when we use trade buy to buy ten microlot. We check if the signal equals buy and if positions total is below one, that would mean we have no open trades. And that is when we use trade buy to buy ten micro lot. This is a test position. You wouldn’t do that on a real account. And to calculate the stop point value, we are now going to call a function that is called Check ATR Buy trailing stop and pass the average true range value that we have calculated as a parameter. To see what’s going on, I would like to have a command output that will show us the signal, the average true range value and the calculated stop point value on our chart. It would be better to read when we do it this way. It makes no difference for the compiler, but it’s better to read for humans. After all the calculation is done. We will now assign the average true range value from now as old value for the next time we call the function that’s it with the main function, but we need to create this one. It is a user defined function and we will call it check atrby trailing stop. It will take this 1 /meter for the average true range value. And here we want to calculate the stop point value by just adding the basic stop point value to the result of this multiplication. Here afterwards we can calculate the stop loss price that will be the ask price minus the calculated stop point value multiplied with the point value for the current currency pair. Now we go through all the open positions by using a for loop for each position. We need to calculate the position symbol by using position get symbol for the current counter value. And if the position symbol and the symbol on the chart are equal, we use Position get integer for the position ticket to get the current position ticket. Then we use Position get double for position underscore SL to calculate the current stop loss for the position. And if the current stop loss is below the calculated stop loss price, we will use Trade dot position modify for the current position ticket and modify the stop loss with the calculated stop loss price. Finally, we need to close the loops and return the calculated stop point value to our main module by using the return function and that’s about it. If this was too fast for you or if you have no idea what’s going on, maybe you want to watch one of the other basic videos first, or maybe even
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 122 SIMPLE AVERAGE TRUE RANGE BUY STOP appeared first on MQL5 Tutorial.
In this video we are going to create an expert advisor that is able to open a sell trade when the RSI Oscillator is above 70 and to close the trade when it reaches a value below 30. So let’s find out how to do that with MQL five. To get started, please click on the 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 the two comment lines here. We start with an include statement to include the file Trade.Mqh. This one comes with MQL 5 and we use it to create an instance of the class C trade that will be called trade, and we are going to use it to open a test position. Inside of the on tick function we need to calculate the ask and the bid price. That can be done by using symbol info double for the current symbol on the chart. We use either symbol ask or symbol bid, and with normalize double and underscore digits, we calculate the number of digits behind the dot. Let’s continue and create an RSI array. We use array set as series to sort our array from the current candle downwards and with the built in function Irsi we can calculate the RSI value for the current symbol on the chart and the currently select period on that chart. We want to calculate it for 14 candles based on the close price and with copy buffer, we can fill our RSI array for the current buffer zero starting from the current candle zero and store the values for free candles in our array according to the RSI definition that we have created here. That makes it possible to calculate the current RSI value by looking into candle zero for our RSI array, I used normalize double and two to create an output with two digits because that is what the RSI looks like. And to have a demo position, we want to know if positions total equals zero. And if the RSI value is greater than 70. If both conditions apply, we use Trade sell to open a sell trade for ten microlot. Afterwards we want to check the RSI sell stop. That is a function that doesn’t exist so far, so we need to create it in a few seconds and we will pass the RSI value as a parameter here. But before we do that, let’s create a chart output by using the comment statement to output the RSI value on the chart. Now let’s continue with the user defined function that is called Check RSI Selll stop. We pass a double parameter for the RSI value here. Now we use a for loop to go through all the open orders. We want to check if the current position symbol equals the position symbol for the current counter value in the for loop. We use position get integer to get the position ticket and we also use position get integer to get the position type. Now let’s check if the position type equals position underscore type underscore sell. If that is true, we have a sell trade and that’s when we want to check if the RSI is below 30. That is done with this if statement. And if this is true, we use trade position close to close the current position ticket. Now let’s close the if 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 is good for, you maybe want to watch one of the other videos first, or maybe you even want to consider to become a premium member. You can find the premium course on our website. For now, please click on the compile button or press F seven. I have an error here. I need to remove the additional bracket. Now let’s recompile the code and this time it works without any errors. And if that is the case, you can click on a little button here or press F four to go back to Meta Trader and in Meta Trader, please click on View, Strategy Tester or Press Control and R. Now we want to pick the new file. Simple RSI sellstop EX five. Mark the option for the visible mode here and start a test. Okay, the expert advisor is running. I will speed this one up a little bit, and now we have an open trade that should be closed when the blue line is below the lower dotted line. That should happen in a few seconds. Yes, our little 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 trade and to close it based on the RSI value. And you have coded it yourself with a few lines of MQL five code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 121 SIMPLE RSI SELL STOP LOSS appeared first on MQL5 Tutorial.
In this video we are going to create an Expert Advisor that is able to use the RSI indicator to open a position when the value is below 30 and to close it when the value is above 70. So let’s find out how to do that with MQL5. To get started, please click on the 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 the two comment lines here. We start with an include statement to include the FILE TRADE.MQH. This is an included trade library and it makes it possible to use a few simple trade functions. To do that, we create an instance of the class Ctrade that will be called trade. Inside of the on tick function we need to calculate 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 ask or symbol bid, and with normalize double and underscore digits, we can automatically calculate the right number of digits behind the dot. Let’s continue and create an RSI array. Afterwards we want to sort the RSI array with array set as series, that will sort the array from the current candle downwards and the included function Irsi will make it possible to calculate the current value for the current symbol on the chart and the currently selected period on our chart. We will do that for 14 candles and the calculation should be done based on the close price. With copy buffer we can now fill our RSI array with data according to the definition that we have created here. We do it for buffer zero. We start with the current candle zero and we want to copy the values for three candles and store them in the RSI array. And that makes it possible to calculate the current RSI value by using normalize double for candle zero in our RSI array. I would like to have two digits behind the dot because that is also how the RSI will show up on our chart, and if we have no open position, that would mean that the return value for positions total equals zero, and if the RSI is below 30, that would mean we have a buy signal. We use trade buy to open a test position for ten microlot. Afterwards we want to call a function that is called Check RSI buy stop and pass the current RSI value as a parameter. Let’s add a comment statement to show the RSI value and the calculated value on our chart. This is the end of the main function, but this function doesn’t exist, so we need to create it now. The name of our user defined function will be check RSI buy stop, here we will get the parameter RSI value that we need to calculate if we want to close the position. Now we use a for loop to go through all the open orders and for each counter value, we want to get the position symbol. That is done by using position get symbol for the current counter value. Let’s remove this German comment here. We also want to get the position ticket, that is done by using position get integer and as a parameter we use position underscore ticket here. Finally, we want to know the position type. And we can do that by using position get integer and the parameter this time is position type, because that will make it possible to check if the current position type equals position type buy. That would mean that we have a buy trade. And if that is the case, we want to check if the RSI value is bigger than 70. And if that is true, we use trade position close to close the current position ticket. Finally, please close the if statement and the user defined function here 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, maybe you want to watch one of the beginner videos, or maybe even the Premium course on our website might be interesting for you. That’s where you also can find some links to download source codes from our shop. And if you are a member of the Premium course and have an idea for a video like this one, just send me an email, but for now please click on the compile button or Press F seven on your keyboard. You shouldn’t get 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, we want to click on View, Strategy Tester or Press Control and R. Please pick the new file simple RSI buystop ex five. Mark the option for the visual mode here and start your test. Here we are, now we need to fast forward until the RSI is below 30, so it will open our buy position. That may take a little while and here is the test position. So let’s speed that up and see if it is closed when the RSI is above 70. It seems to take a while. So let’s stop this test. I will pick another date and the 1 minute chart and restart the test. This is much faster. Here we have an open position and as soon as the RSI reaches the dotted line above, it should be closed and it looks like it could happen in a few seconds. Yes.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 120 SIMPLE RSI BUY STOP appeared first on MQL5 Tutorial.
In this video we are going to create an Expert Advisor that is going to use the Bollinger Bands as an entry signal and it will also use the Volumes Indicator as a filter. Only if the filter is positive and we have a buy or sell signal we want to open a new position. This is going to be a standalone version and it contains three separate modules. In this video we will talk about the filter function. Now how can we create a filter that is using the Volumes Indicator? To do that please click on the little button here or press F4 in your Metatrader, now you should see the Metaeditor window, this is the main module, it will include the Bollinger Bands Entry (CheckEntry_Bollinger) and the Check Filter module (CheckFilter_Volumes) for the Volumes Indicator. If you don’t know what the rest of the code does please have a look at the other videos in this channel. The “OnTick” function is called whenever the price changes and here we will use the “CheckEntry” function to get the signal, this is the Check Entry Module (CheckEntry_Bollinger) that will give us the signal for the Bollinger Bands but in this video we are going to talk about how to get the filter value. To do that we need a new file, this one, it is called: “CheckFilter_Volumes” and we are including it here using the “include” statement. Inside of the function we first need to create a variable for the filter that will be called: “filter” and we don’t assign a value here. Afterwards we are going to create an array for the prices that will be called: “myPriceArray” and now we define the filter by using the “iVolumes” function that is included in MQL5, we use “_Symbol” for the first parameter to get the currency pair, that’s for the selected time period on the chart and parameter 3 is “VOLUME_TICK” all in capital letters. We use “ArraySetAsSeries” to sort the prices from the current candle downwards for our price array (myPriceArray) and now we use “CopyBuffer” to fill the array with data. We are going to use the volumes definition (VolumesDefinition) that we have created here to fill the array (myPriceArray) for buffer 0 (zero) from the current candle 0 (zero) for 3 candles and store the values in our price array (myPriceArray). Let’s calculate the value for the current candle that is done by looking into candle 0 (zero) of our price array (myPriceArray) and we are going to store the value in the variable: “CurrentVolumesValue“ and now we do the same for the candle before – that is candle 1– and we will store that value in the variable: “LastVolumesValue“ and in the case that the current volumes value (CurrentVolumesValue) is bigger than the last volumes value (LastVolumesValue), with other words; we have a rising volume like here, that’s when we want to assign the word: “positive” to our filter. In the other case if the current volumes value (CurrentVolumesValue) is below the last volumes value (LastVolumesValue) that would be the case here, the current candle has a volume value of 14 and the volumes value of the candle before was 37 and in that case we want to set the filter value to negative so we assign the word: “negative” to our filter and last but not least we are going to use the return statement to return the filter value to our main module. So that’s done all by calling this function here and when the trading signal equals buy and the filter is positive and “PositionsTotal” equals 0 (zero) – that means we don’t have any open position – that’s when we use “trade.Buy” to buy 10 micro lot. In the other case if the trading signal equal sell and the filter is positive (remember we only want to use increasing volumes because in theory an increasing volume means that the trend is going to continue) and we only want to open a new position when we don’t already have an open position and in that case we use “trade.Sell” to sell 10 micro lot. Here is the final chart output that will output the words: “Trading signal:” followed by the calculated value for the entry signal and in a new line the word: “Filter:” followed by the “filter” that we have just calculated in our new module. So let’s compile the main module here, that worked without any errors and now we can click on a little button here or press F4 to go back to Metatrader and in Metatrader we click on: “View/ Strategy Tester” and here I pick the main module where I import my filter I have called that: “SimpleVolumesFilter” and now I start a test. …and here is how it looks like, currently we have a negative filter because the value for the last candle is lower, this one is positive because the current value is higher. You need to slow down the Expert Advisor to control if everything is okay because the output might be a little slower than the Indicator is calculated but now you know how to create a filter for an Expert Advisor that is only allowing to trade when the filter is positive and you have coded the Filter Module for the Volumes Indicator with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – SIMPLE VOLUMES FILTER appeared first on MQL5 Tutorial.
In this video we are going to import the MyFxBook Expert Advisor so we can publish our statistics on a website. So let’s find out how to do that with MetaTrader 5. This is MyFxBook. It’s a website that provides advanced statistics for automated trading systems. These are a few of my systems and you can see that they have been updated. And this website here, MyFxBook dot com, provides some advanced statistics. This is a system that I have closed on February 4th and it says it stopped updating and I should download the latest MyFxBook Expert Advisor. Actually, I closed this one manually, but for this video, we are going to click on this link here. This is the MyFxBook EA, here we see the download. This is the download file and when we open it, you will see that it contains some files and a version TXT. So let’s actually start the installer process by double clicking it. And now it says that some additional applications need to be downloaded. This is the Dot net framework for Windows, so let’s click on download and install. This might take a little while. This framework data is actually the reason why some Linux distributions have problems to update the Expert Advisor for MyFxBook, but on a Windows machine you should have no problems. The download should be finished in a few seconds. Now we’ll see that the installation is started and afterwards we see the dialogue that the DotNet framework was installed. So let’s close that window. Now we need to restart the installation process. This time we will see a different window. We can pick one of the installations. Actually, I have downloaded the wrong Expert Advisor installer. This one is for MetaTrader 4. So let’s cancel that. And as often we will have more success when we do a Google search. The third entry in the Google search is the Metatrader 5 Expert Advisor Connection Wizard. So let’s click on this link and this one says that the EA installer MT5. So it’s for Metatrader 5. You can drag and drop the MetaTrader 5 icon into this window. Here is mine. So let’s drop it here and it says the access was denied. So let’s click on Browse. You should find it on your hard drive, mine is located on the C drive, programs MetaTrader 5 and now it says that we have an authorization problem. So let’s right click this file and select run as administrator, repeat the browsing process. Pick the file Terminal ICO. Click on Open and this time the installation worked. It says it was installed successfully. Now we can click on Finish and exit the installer window. If your Metatrader window is open, please right click on Expert Advisors and select refresh. Afterwards you should see the MyFxBook Expert Advisor entry down here. Now let’s drag it onto the chart. Click on the Dependencies tab here. We need to allow DLL imports. Now please click on the inputs tab, type in your email address and your MyFxBook password and click on OK. In this case, it says that it has not published anything. Status is 502. That’s because I used the wrong password. If you have that issue, please press F7 and correct your credentials. Afterwards the 502 error is gone. This icon here should be green. If it isn’t, please click on tools, options, Expert Advisor, allow algorithmic trading and DLL imports. Now please click on okay, I will now close and restart Metatrader. Now let’s repeat the process. I have to retype my credentials. It says last publish is never and it might take a little while. Let’s try to switch to a different time frame. You can also check your journal for errors, but it says that the Expert Advisor was loaded successfully. So let’s give it a few minutes and now it says it’s uploading the statement. Once again, we have a status error. It looks like we have a problem with this file. Ms. Core DLL but when you scroll down on the MyFxBook site, you will see that they actually provide their own MyFxBook DLL and the MyFxBook Ex5 file. So let’s download those two files and try the manual way. The MyFxBook.ex5 file needs to be placed inside of the Experts folder. I will replace the current one. The DLL file needs to be inside of the libraries folder. I need to remove the Expert Advisor from the chart so I can delete the old one and replace it. And now I need to repeat the whole thing. It says uploading statement, statement uploaded successfully. So actually, we didn’t have a problem with this ms core DLL dependency here. It rather looks like we had a problem with the MyFxBook Expert Advisor installation files. And in this little video, you have learned how to install and troubleshoot the MyFxBook Expert Advisor that is able to connect you to the service from MyFxBook.com. And you have done it yourself in a few minutes.
Not sure what to do? Click on the automated trading assistant below
The post LEARN MQL5 TUTORIAL BASICS – 119 MYFXBOOK EXPERT ADVISOR INSTALLATION appeared first on MQL5 Tutorial.
In this video we are going to create an expert advisor that is able to get the last order type. I hope I can get it done before the building noise around the house starts, 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 last order type. Click on Continue, continue and finish. Now you can remove everything above the Ontick function and the two comment lines here. We start with an include statement to include the file Trade.mqh. And that includes the class C trade. We’re going to use an instance of Ctrade that is called Trade. Inside of the Ontick function we need to calculate 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 either symbol underscore ask or symbol underscore bid. And with normalize double and underscore digits, we’ll make sure to automatically calculate the right number of digits behind the dot. Now we want to open test positions. If we have no positions, that would be the case when positions total is below one. We are going to use Trade Buy and Trade Sell to open test positions on a test demo account. This would make no sense on a real account, but obviously we need to have some positions to find out the position direction of the last one. And to get the position direction we want to call a function that is called Get Last order type and assign the result to a string variable called My last order type. And we use a comment statement to output the text my last position was and the result of the function that we are going to create now. So let’s start. The name of the new function will be Get Last order type and it will return a string variable. We need to define a few variables that are required to get the proper history result. Now we use History Select. We can pass two time stamps from date and to date. We want to start from the beginning until the current time. Now we use a for loop to go through the total number of deals. Afterwards we check if the ticket number for the current history deal ticket of the counter value is above zero. That would mean we have a real ticket, and in that case we would like to get some data. First we want to calculate the order profit. That is done by using History deal get double for the current ticket number and we use Deal underscore profit. If you mark that and press F1, you will see that we have so called deal properties. And this is the one we use to get the profit. Let’s continue and get the order type. That is done by using History deal get integer for the current ticket number. And this time we use Deal underscore type. Let’s continue with the current symbol. We use History deal, get string for the current ticket number to get the deal symbol, and then we continue and use History deal get integer for the current ticket number to get the deal entry. Let’s check if the current symbol on the chart equals the symbol of the deal. And of course, if the deal entry is one, that would mean that the order was closed. And if the close type was order type buy, the original position direction was a sell trade. Otherwise, if the close type was order type sell, the original position direction was a buy trade, let’s assign the code profit, the ticket number and the position direction to our string variable called my result. Now we close the loops and finally we return our result to the main module. So far, so good. 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 former starter videos, or maybe even the premium course on our website might be interesting for you. This once again was 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, just let me know. For now please click on the compile button or Press F7 on your keyboard. I didn’t get any errors here, and if that is the case, you can click on a little button here or press F4 to go back to Meter Trader. And in MetaTrader, you want to click on View, Strategy TestER or Press Control and R. Please pick the new file simple last order type dot ex5, mark the option for the visual mode here and start your test. Here we are. We have outputs for buy and sell trades. Now let’s stop that. So let’s go back to MetaTrader and restart the test. This time we will make a slow version. Here is our first result. It says that the ticket is number four. The closing type was buy, the profit is minus $5.40 and you can see on the chart that the sell position was closed. Now let’s speed that up a little bit and you see our expert advisor is working. It shows the direction of the last position and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 118 SIMPLE LAST ORDER TYPE appeared first on MQL5 Tutorial.
In this video we are going to create an expert advisor that is able to identify trends on different charts. So let’s find out how that can be done for 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 multi chart trend. 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. We want to start by creating an array for the price information, that can be done by using MQL rates. The name of the array will be priceinfo. Afterwards we use Array set as series to sort our price information array from the current candle downwards, and now we use copyrates to file it for the current symbol on the chart and the currently selected period on that chart, starting with the current candle zero and we will store the values for three candles in our price info array. Now we want to create two variables. One is called chart signal and the other one is called Euro USD signal. We don’t assign any values here. Let’s continue and create two arrays. One is called EMa 20 array. The other one is EMA Euro US Dollar 20 array. And now we can use the integrated IMA function that comes with MQL5 for the current symbol on the chart and the currently selected period on that chart. To calculate the exponential moving average for 20 candles, we don’t use a shift value here. This parameter is called Mode EMA, that stands for exponential moving average, and the result should be calculated based on the close price. Let’s continue and this time we are doing it in a similar way, but the first parameter is hard coded for the Euro US dollar. If you click on the symbol in the market watch, you will see a name, that might be a different name depending on your broker and your account type. So please make sure that you pick the right one. Everything else is similar. So now we can use array set as series for both arrays to sort them from the current candle downwards. And now we use copy buffer for both arrays, the one for the current symbol on the chart and the other one for the Euro US dollar to fill them for buffer zero, starting from the current candle zero for three candles. And now we can check the trend. We want to check if the current candle zero is bigger than candle two for the EMA 20 array. If that is the case, the signal for a current chart is buy. Otherwise, if the value for candle zero is below the one for candle two, that would be a sell signal for the current chart, and this part is basically the same, but for the hard coded Euro US dollar. Finally, we add a comment statement to output the values for the EMA 20 for the current symbol, the EMA 20 for the Euro US dollar, the trend for the current symbol and the trend for the Euro US dollar, 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 videos, or maybe even the premium course on our website might be interesting for you. There you can also find some links for source code downloads like this one and a shop link. For now we are done. Please click on compile or Press F7 on your keyboard. You shouldn’t get any errors, and if that is the case, you can click on the little button here or press F4 to go back to Metatrader. And in MetaTrader, please pick an empty chart. Go to the Navigator and pick the simple multi chart Trend Expert Advisor and drag it on to the chart. I will allow the modification of signal settings, but it will not actually trade. It will just show us trends and when the next tick comes in, you should see that the current trend for the Canadian dollar against the Swiss franc is a buy trend. Now please click on insert Indicators, trend, select Moving Average. Pick a period of 20 candles for the exponential moving average. We don’t have a shift value and the EMA should be drawn for the close price. Now please click on okay, here we are and we can see we have an uptrend that is correct. Now you can right click onto the chart. Select templates and save the template. I will save it as default TPL in this case and override the current one because default TPL is what you see when you open the next chart. Now let’s do this and open another one for Euro USD. And now you should see the exact same values for both calculations. And that is the way to check out if it really works. And in this little video you have learned how to create a simple expert advisor that is able to calculate trends for different charts and show them on the chart that you have picked, and you have coded it yourself with a few lines of MQL five code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 117 SIMPLE MULTIPLE CHART TREND appeared first on MQL5 Tutorial.
In this video we are going to create an expert advisor that is able to adjust a sell trailing stop according to the upper band of the envelopes indicator. So let’s find out how to do that with MQL5. 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. I will call this file Simple Envelopes Sell Trailing Stop. 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.mqh. This file is part of MQL5 and it will help us to open a test position. To do that, we need to create an instance of the class Ctrade and that will be called trade. We need to define a static double variable called Last Stop envelopes value. This will hold the last stop loss value for each time we call the function. We also need to calculate the ask price and the bid price. That can be done by using symbol info double for the current symbol on the chart. We either use symbol underscore ask or symbol underscore bid and with normalize double and underscore digits, we make sure that we automatically calculate the right number of digits behind the dot. To test a trailing stop, we need to open a test position. Therefore, we check if positions total is below one. If that is true, we want to reset the last value for the stop loss and set it to zero and then we use Trade.sell to sell ten micro lot. You wouldn’t do that on a real account, but that’s what demo accounts are good for. Let’s continue and create two arrays for the upper and the lower band array. We use Array set as series for both arrays to sort them from the current candle downwards. And now we can use the included function Ienvelopes for the current symbol on the chart and the currently selected period on that chart to calculate the envelopes indicator for 14 candles. We don’t use a shift value here. The next parameter is mode underscore SMA, that stands for Simple Moving Average. The result should be calculated based on the close price and this last parameter here is for the deviation, that’s the standard value. If you pick an empty chart window and click on insert, indicators, trend, envelopes, you will also see this value as a deviation value. Here are the 14 candles. Now please click on OK, rightclick into the chart. Select Templates, save template and save this one as tester.tpl. You can override the current value. Tester.tpl is the view that we will see when we start the strategy tester. But back to coding. We continue by using copy buffer to copy data according to the envelopes definition that we have created here, either for buffer zero or for buffer one, for candle zero. That’s the current candle and we want to copy the values for three candles and store them in the upper or in the lower band array. It’s now possible to get the current value for candle zero. I have out commented it in this version, because I’m more interested in the values for the candle before. That’s candle one. To get the last upper band value or the last lower band value, I will look into our array at candle one and with normalize double and comma six, I make sure that the value is using six digits behind the dot. Because that’s also what the original envelopes indicator will show. Now we can call a custom function called CheckEnvelopesSelltrailingStop and pass the last upper band value as a parameter. This function doesn’t exist, so we need to create it in a few seconds. The last thing in the Ontick function is to assign the last upper band value to the last stop envelopes value here, because we need that the next time we call the function. Now let’s actually create the check envelopes sell trailing stop. It will get the last upper band value as a parameter here. The type is void because we don’t return any values. We use a for loop to go through all the open positions and we use position get symbol for the current counter value to get the position symbol, because we only want to continue if the current symbol on the chart and the position symbol are equal. If that is the case, we use position get integer and use position underscore ticket to get the current position ticket number. And with position get double, position underscore SL, we can get the current stop loss for the current position. And now we want to check if the current stop loss for this position is bigger than the last upper band value, or if the current stop loss is zero. If one of those cases is true, we use trade dot position modify for the current position ticket and adjust the stop loss value to the last upper band value here. The last parameter here is for the take profit. We leave that unchanged. Finally, we need to close the loops and the function here 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, maybe you want to watch one of the other videos of the basic series, or maybe even the Premium course on our website might be interesting for you. We also offer some source codes, if you need more we also have a shop. But for now please click on the compile button or Press F seven on your keyboard. You shouldn’t get any errors
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 116 SIMPLE ENVELOPES SELL TRAILING STOP appeared first on MQL5 Tutorial.
In this video, we are going to create a buy trailing stop that is based on the envelopes indicator. 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 envelopes buy trailing. Stop, 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 and we’ll include the file Trade.mqh. This one comes with MQL5 and we can create an instance of the included Class Ctrade. That instance will be called trade and we are going to use it to open a position later on. Inside of the ontick function, we start with a static variable. This is a double variable for the last value of the Stop Loss. Afterwards, we need to calculate the Ask price and the Bid price. That can be done by using Symbolinfodouble for the current symbol on the chart, we use either symbol underscore ask or we use symbol underscore bid and with normalize double and underscore digits, we make sure that we calculate the right number of digits behind the dot, because there are currency pairs with three digits and others have five digits. For our Stop Loss, we need to open a test position. That wouldn’t be done on a real account. But if we have no open positions and that would be true of PositionsTotal is below one, we want to open a test position on our demo account. So we use trade.Buy to buy 10 Microlot and we want to reset the last value for the Stop Loss. Because with the new position we need to set a new Stop Loss value. Now let’s continue with two arrays, one for the upper band and one for the lower end of the envelopes indicator. With arrays set as series we sort the upper and lower band array from the current candle downwards. And now we can use the included Ienvelopes function for the current symbol on the chart and the currently selected period on that chart. We want to calculate the values for 14 candles, the next value here is a shift value. We don’t need that. So we set it to zero. We use MODE SMA for simple moving average. The result should be based on the close price and this last value here is what you see when you open a new chart and click on insert, indicators, trend, Envelopes. It’s the so-called deviation. We are going with the standard values here. Click on OK. Here is the indicator, and now we want to right click into the chart, save the template as tester.tpl, you can override the current value because the Tester.tpl template is what we will see in the strategy tester. Now, let’s add some data. We use Copybuffer according to the envelopes definition that we have created here. To fill our array for the buffer zero and the buffer one. Buffer zero is for the upper Band and buffer one is for the lower band. We want to copy data from the current Candle zero for three candles and store those values in our arrays. To calculate the upper band array for the current candle, we only need to look at Candle zero in our upper band array. I use Normalize double and six to cut it to six digits behind the dot. And we repeat that for the lower band value. Let’s repeat that, everything is equal, but this time we are doing it for candle one. That’s the candle before the current candle. And of course, the variable names are different. This time, we use my last upper band value and my last lower band value. So let’s check for the conditions for the buy trailing stop. The first condition would be that the last lower band value is below the current Bid price. The second condition is we want to check if the last lower band value is bigger than the last stop envelopes value. If both conditions are true, we want to call a function that is called check envelopes buy trailing stop and we want to pass the last lower bands value as a parameter here. This function doesn’t exist so far, so we need to create it in a few minutes. And once we have adjusted the Stop Loss, we assign the last lower band value to the variable last stop envelopes value. That’s it for the Ontick function. Let’s continue with the trailing stop function. It will get the last lower band value as a parameter. Now we need to use a for loop to go through all the open positions. We use position get symbol for the current counter value to get the symbol. And if the current currency pair on the chart equals our position symbol, we are going to continue. We need to get the position ticket. That can be done by using position get integer and the parameter here is position underscore ticket. Let’s also get the current Stop Loss for this position. That can be done by using position get double and the parameter here is buy position underscore SL. And if the current Stop Loss is below the last lower band value, we are going to use trade position modify to move the Stop Loss to the last lower band value that we have calculated. Now let’s end the loops here 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 videos in the basic video
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 115 SIMPLE ENVELOPESBUY TRAILING STOP appeared first on MQL5 Tutorial.
In this video, we are going to find out how to trade pure price data. This is a so-called line chart and we are using the shifted price data to make, buy and sell decisions. 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 shifted price EA, click on Continue, continue and finish. Now you can delete everything above the ontick function. We also want to remove the Comment lines here. Let’s start with an include statement to include the file Trade.mqh. It contains the class Ctrade. And we create an instance and call it trade. Afterwards, we need to calculate the Ask price and the Bid price, that can be done by using Symbolinfodouble 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 that we automatically calculate the right number of digits behind the dot. Let’s continue and create a string variable called signal, but we are not going to assign a value right now. With MQLRates we create an array for the price information. Let’s use arraysetasseries to sort our price information array from the current candle downwards. And now we can use CopyRates to fill the array with data for the current symbol on the chart and the currently selected period on that chart. We start with the current Candle zero and copy the price data for three candles to store it in the price information array. The next step is to create an array for the moving average values. We use the integrated function IMA for the current symbol on the chart and the currently selected period on the chart. We want to calculate the simple moving average for one candle and we want the shifted moving average to be drawn twenty candles into the future. We use ModeSMA for simple moving average and the result should be calculated based on the close price. With array set as series we also sort the moving average array from the current candle downwards. Now we can use copybuffer according to the definition that we have created here. We are going to copy data for buffer zero from current Candle zero. We copy price data for three candles. To calculate the current value for the moving average we just need to look into Candle zero of our moving average array and if the moving average value is below the close price for the current Candle zero, that would be a Buy signal and that’s when we assign the word buy to our signal. Otherwise, if the moving average value is above the close price for Candle zero, that would be a Sell signal. And now we would assign the word sell to our signal. And when our signal equals sell and PositionsTotal is below one, we use trade.Sell to sell 10 Microlot. Otherwise, if the signal equals buy and we have no open positions, we use trade.Buy and buy 10 Microlot. Finally, I would like to add a comment statement that will output “The current signal is now”, followed by the calculated signal 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 videos. Or maybe even the Premium Course on our website might be interesting for you. If you need source codes for videos like this one, you can find a shop link on our website. But for now, please click on the compile button here. Or press F7 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 F4 to go back to Metatrader. And in Metatrader, please pick an empty chart. Change the view to line chart here. Right, click into the chart and select template, save template. Please save it as tester.tpl because this is the view that we are going to see in the strategy tester, you can override the current one. Now please click on View, Strategy tester or Control and R. Please pick the new file simple shifted price ea.ex5, mark the option for the visual mode here and start your test. Here we are. We already have the first sell position and as soon as the current price crosses the shifted price data here, this should switch to a buy signal, which happened right now. So in this little video, you have learned how to create an Expert Advisor that can use shifted price data for a line chart. And you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 114 SIMPLE SHIFTED PRICE EA appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor for Sell positions, that is able to close positions when a defined risk percentage value has been reached. So let’s find out how to do that with MQL5. To get started, 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 percentage risk. 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 trade Library. This is the file Trade.mqh. It is part of MQL5 and it will help us to use some functions to open trades. Therefore, we create an instance of the class Ctrade that is called Ctrade, our goal for this Expert Advisor is to create an input variable for the user that will be called percentage risk value. This is the start value and it can be changed by the user without Recompilation. Because if you mark input and press F1, you will see that values of input variables can be changed by the user in the properties window of the Expert Advisor. Now let’s add another variable called Max Position Loss. This is the max loss that we are going to accept. Inside of the ontick function we start by calculating the Bid price. That is done by using Symbolinfodouble for the current symbol on the chart. We are using symbol underscore Bid and with normalize double and underscore digits, we can automatically calculate the right number of digits behind the dot. The second thing I want to calculate is the balance. That can be done by using account info double and we are going to use account underscore balance in this case. If you mark that and press F1, you will see that you can get all kinds of information about your account. And as we want to close sell position, we need to have a test position. So we check if PositionsTotal is less than one, that would mean we have no open positions and now we can use trade.Sell to open a 10 Microlot position. You wouldn’t do that on a real account, but that’s what demo accounts are for. And without a position, we cannot close anything. On a real account we could have more than one position, so we would use a for loop to go through all the open positions. We use buy position getticket for the current counter value to get the ticket number for the position. Afterwards, we use position get double to get the position profit, because if we have the position profit, we also know the position loss and now we can calculate the max position loss. We are going to divide the balance by 100 to get one percent. That will be multiplied with the percentage risk value. And if you wonder what that part is for, we need to have a negative value because a position loss as a negative value. Let’s add two print outputs, so we can see what’s going on in the journal. And if the position profit is below the max position loss that we have defined, or in other words, if the position loss is bigger than the accepted loss, we use trade position close for the current ticket to close the current position. Let’s end the for loop here and to see what’s going on, I would like to add a comment statement that will output the balance, the max position loss and the percentage risk value directly on our chart. 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 videos in the basic video series or maybe even the Premium Course on our website might be interesting for you. That’s also the place where you can find offers to download source codes like this one. But for now, please click on View, Toolbar. Now click on the Compile button or press F7 on your keyboard. You shouldn’t see any errors. And if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And inside of Metatrader we want to click on View, Strategy tester or Press Control and R. Please pick the new file. Simple percentage risk.ex5, mark the option for the Visual mode and test start your test. Here we have a sell position, it’s currently in the profit, but as soon as the loss is getting too big, we should see that the position will be closed. So let’s speed that up a little bit here. Now we have a bigger loss and now the position was closed. Let’s click onto the journal tab, here we see the current position profit and the max position loss. So our little Expert Advisor works as expected. And in this little video, you have learned how to set a user defined percentage value to close positions when they have reached a user defined loss. And you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 113 SIMPLE SELL PERCENTAGE RISK appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor that is able to close positions based on a risk percentage value. 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 buy percentage risk. Click on continue. Continue and finish, now you can delete everything above the Ontick function and the two Comment lines here. We start with and include statement to include the file Trade.mqh. That will make it possible to create an instance of the class Ctrade, that is called trade. We also want to create an input variable that is a user changeable variable for the percentage risk. In our case, we have set a percentage of zero point five percent based on the balance and we also need to define a max position, loss variable. So let’s continue with the calculation. First, we need to calculate the Ask price. That is done by using Symbolinfodouble for the current symbol on the chart, we use simple underscore ask. And with normalize double and Underscore digits, we make sure to automatically calculate the right number of digits behind the dot. We also need to calculate the current account balance. We can do that by using account info double. And we use the parameter account underscore balance here. Now we need to open a test position. Of course we only do this on a demo account for testing purposes. So when we have no open positions, we want to open one buy position. Let’s change that to 10 Microlot here so it will work on most accounts. Some brokers do not support one Microlot position sizes. And this will be our test position and we want to close it as soon as the loss is higher than the percentage value that we have defined here. So let’s create a for loop that will go through all the open positions until we have no positions left. We use position get ticket for the current counter value of the For loop to get the position ticket number, and afterwards we will calculate the position profit. That can be done by using position get double and we use position underscore profit here. If you mark that and press F1 you will see that it says it will give you the current profit. That is not really the profit because you might also want to include position swap in the calculation if you hold positions for longer than one day. But for this simple example, it’s good enough. Now let’s calculate the maximum position loss. We use the current balance. One percent of the balance would be balance divided by one hundred. And we multiply it with the percentage risk value that we have defined here. In our case, it’s zero point five percent. And if you wonder about this part here, well we need to calculate the negative value for this variable, because a loss is actually a negative value. Now, let’s add to print statements. That will output the position profit and the max position loss each time a new tick comes in. And if the position profit is below the max position loss, that would mean that we have a greater minus value here than the negative value for the max position loss. That’s when we use trade position close for the current ticket number. Please don’t forget to close the For loop and to see what’s going on, I would like to add a comment statement to output the balance, the max position loss and the percentage risk value that we have defined. 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, maybe you want to watch one of the other basic videos or maybe even the Premium Course on our website might be interesting for you. This actually was a suggestion of a German Premium Course member. And if you are a Premium Course member and have an idea for a video like this one, please just let me know. On our website we have also offers for source codes like this one. I will send the source code for this video to the requester as soon as this video is finished. So for now, please click on View, toolbar and click on the Compile button here. Or press F7 on your keyboard. You shouldn’t get any errors here. And if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader, please click on View, Strategy tester or press Control and R. Please pick the new file simple by percentage risk, mark the option for the visual mode here and start your test. Here we are. We see that trades have been opened and closed. We have a very low balance here, so let’s change that. I will use one thousand US dollars and on the inputs tab I will pick one percent. Now let’s restart the test. Here we are. We have one position. If we click into the journal, we can see that the position profit changes with each tick. Now, let’s speed that up a little bit, and as soon as the loss is higher than 10 dollars here, we should see that the position is closed automatically. In this case, it doesn’t seem to work because it takes forever. Let’s speed that up a little more. Look into the Ctrade history. And here is our position close, we can see the position profit in the journal, and whenever the loss is bigger than the percentage value that we have
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 112 SIMPLE BUY PERCENTAGE RISK appeared first on MQL5 Tutorial.
In this video, we are going to calculate the standard deviation value for two hundred candles, 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 standard deviation. 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. We start with an include statement to include the file Trade.mqh. This one comes with some simplified trading functions. And we create an instance of the class Ctrade and call it trade. Inside of the ontick function, we want to create a variable for the signal. But we are not going to assign any value, because we are going to calculate that later. Afterwards, we want to calculate the Ask price and the Bid price, that is done by using Symbolinfodouble for the current symbol on the chart, we use either symbol underscore, ask or underscore bid. And with normalize double and underscore digits, we make sure that we calculate the right number of digits behind the dot. Let’s continue and create an array for the standard deviation Expert Advisor. We can use the integrated function iSTDDEV for the current symbol on the chart and the currently selected period on that chart. We want to calculate the results for twenty candles, without any shift for a simple moving average. That is why we use ModeUnderscoreSMA and the result should be calculated based on the close price. Now we use arrays set as series to sort our array from the current candle downwards. And with copybuffer we fill our standard deviation array according to the definition that we have created here for buffer zero. We start with the current candle zero and we will copy the values for two hundred candles. So let’s actually write that in the comment. That makes it possible to now calculate the highest candle number by using array maximum. Array maximum will give us the largest element in our array and actually that is the candle number, not the value. We want to search in the standard deviation array starting from Candle zero and we want to search in the whole array. Let’s also do that for the lowest candle number, that can be calculated by using array minimum. The rest is the same and we need one more thing, and that is the standard deviation value for the current candle. We get that one by using Normalize double for the standard deviation array. We want the value for candle zero with six digits behind the dot. Now we can check if the lowest candle number equals zero. That would mean that the deviation value for candle zero is the lowest of two hundred candles. If that is the case we consider that to be a buy signal. So we assign the word buy to our signal. Otherwise, if the value for candle zero is the highest, that would mean we have a sell signal and now we assign the word sell to our signal. And if we have a sell signal and the return value for PositionsTotal is below one, that would mean that we have no open positions and a sell signal. And now we use trade.Sell to sell 10 Microlot. In the other case, if the signal equals buy and we also have no open positions, that’s when we use trade.Buy and by 10 Microlot. Finally we add a comment statement that will output the current deviation value, the number of the highest and the lowest candle and the calculated signal. That’s about it, 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 videos in the basic video series. Or maybe even the Premium Course might be interesting for you. You can find that one on our website. And that’s also where we now have some offers for source codes for the basic videos like this one. For now, please click on View, toolbar and press the compile button or press F7 on your keyboard. You shouldn’t get any errors here. And if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader we click on View, Strategy tester or Control and R. Please pick the new file simple standard deviation.ex5, mark the option for the Visual mode here and start your test. Here we are, the Expert Advisor is running. And as soon as one of those values here is for candle zero, we should see our first trade. That happened right now. So our little Expert Advisor is working as expected. And in this little video you have learned how to calculate the standard deviation value with MQL5. And you have coded it yourself with a few lines of code in the Metaeditor.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS 111 – SIMPLE STANDARD DEVIATION EA appeared first on MQL5 Tutorial.
In this video, we are going to create a list of predefined values that can be picked by the user to pick an entry. 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 until you want to click on file. New file, Expert Advisor from template, continue. I will call this file simple multiple input. 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, we start by creating a list. This is an enumeration, as you can see. The keyword here is Enum. And if you mark it and press F1, you will see that enumerations are a limited set of data that is predefined. For example, you could use it for 12 months and it is created like this. We have several items and we can also assign a value here. The items are comma separated and now we are going to use this collection of data to create an instance. The trick is to use the input modifier because this will make our complete choice list available for the user input. The instance is called choice and we assign a default value here called random for random entries. I also would like to have a readable version, a string variable called entry. And inside of the ontick function, we can now check if the value for our choice is zero. If that is the case, we have picked a random entry, so we assign the word random to our entry for the other entries. It is very similar and that’s how we check for the value. Let’s add a comment statement that will output the entry and the choice so that we see something on our chart. Usually we would create some functions here, right now, we can pick entries, but nothing is happening as this video is just about how to make the enumeration available for the user input. So that’s basically it. If this was too fast for you or if you have no idea what all the code here does, you may be one to watch one of the other videos and the basic video series, or maybe even the Premium Course on our website might be interesting for you. That’s also where you can find some offers for those source code files, in case you don’t want to type everything. For now, please click on View toolbar and click on the Compile button or press F7 on your keyboard. You shouldn’t get any errors here. And if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader we want to pick an empty chart. Please navigate to the simple multiple input file and drag it on the chart and here comes the user input. Now you can pick a choice. Let’s pick the EMA and click on, OK? And when the next tick comes in, we should see that we have chosen the EMA, the value for choice, this one, if you press F7, you can change the value. So now let’s pick the ADX and click on, OK? And now the entry is ADX. The value for choice is three. By the way, this once again was an idea of a Premium Course member, and if you are a Premium Course member and have an idea for a video like this one, just send me an email. For now, you have learned how to create an Expert Advisor that is able to use an enumeration for user defined input variables that can be changed without the need to recompile the code, and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 110 SIMPLE MULTIPLE INPUT appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor that is able to calculate this indicator here, it’s the fractals indicator. So let’s find out how to do that with MQL five. 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 fractals Ea. Click on Continue, continue and finish. Now you can delete everything above the ontick function and let’s also remove the two comment lines. We will start with and include statement that will include the file Trade.mqh. This one is part of MQL five and it will allow us to create an instance of the class Ctrade, that is called trade, and we are going to use it to open some positions later. Inside of the ontick function we need to calculate the Ask price and the Bid price, that is done by using Symbolinfodouble for the current symbol on the chart, we use either symbol ask or symbol bid, and with normalize double and underscore digits, we can automatically calculate the right number of digits behind the dot for each currency pair. The next thing we need is a variable for the signal. This will also be called signal, but we don’t assign a value here. Afterwards, we use MQLRates to create a price array and with arraysetasseries, we sort our price array from the current candle downwards. And now we can fill the array with price data, that is done by using CopyRates for the current symbol on the chart and the currently selected period on that chart, copy the data for three candles and store them in the price array. But let’s use the underscore. It doesn’t really matter because when you mark that and press F1, you will see that it is interchangeable. We need two more arrays, one for the upper fractals and one for the lower fractals. The definition is very easy. We use the function I fractals for the current symbol on the chart and the current period on that chart. Our two fractal arrays need to be sorted by using arrays set as series as we did here. Now we can fill in some data, that is done by using copybuffer for the fractals definition that we have created here. The first one is for the upper line, we are starting with candle one for three candles and store the values in the upper fractals array, for the lower fractals array it’s very similar, but this time we are using lower underscore line and store the values in the lower fractals array. Here comes something that is very uncommon, because if the upper fractals value is equal to empty underscore value, we will assign the value zero to our upper fractals value. And we do the same thing here for the lower fractals value. If you missed that part, you might see some strange exponential values on your chart. So let’s don’t forget that. Now we can check the entry conditions. Because if the lower fractals value is not zero, and if the lower fractals value is below the lowest price for candle one in our price array, we would consider that to be a buy signal. Therefore, we assign the word buy to our signal. Otherwise, if the upper fractals value is not zero and if the upper fractals value is higher than the highest price for candle one in our price array, that would be a sell signal. And now we assign the word sell to our signal. And when we have a sell signal and PositionsTotal is less than one, that is equal to we have no open positions. That’s when we want to sell. And that’s when we use trade.Sell to sell 10 Microlot. In the other case, if the signal equals buy and we have no open positions, that is when we use trade.Buy to buy 10 Microlot. Finally, we want to add a comment statement on our chart, that will output the signal, the upper and lower value for the fractals indicator, 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, maybe you want to watch one of the other videos in the basic video series or maybe even the Premium Course might be interesting for you. That can be found on our website, where we also have a link for source codes for this basic video stuff here, but for now, please click on View, Toolbar. And press the Compile button or F7 on your keyboard, I have made a mistake here, it looks like I have forgotten to calculate the values for the last candle. The upper fractals value can be calculated by looking at the value for candle one in our upper fractals array. The lower fractals value is calculated by looking at candle one in the lower fractals array. Now let’s recompile the code and this time it worked. And if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader you want to click on View, Strategy tester or press Control and R. Please pick the new file Simple FractalsEA.ex5 mark the option for the visual mode and start your test. Here we are. The Expert Advisor is running. We see the fractals on the screen. We see buy and sell signals and the values are calculated. So our little Expert Advisor is working as expected. And in this little video you have learned how to calculate the fractals indicator and you have done it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 109 SIMPLE FRACTALS EA appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor that is able to open buy and sell trades based on minimal or maximal values of this oscillator here. So let’s find out how to do 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 IOBVEA, 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. We start with an include statement to include the file Trade.mqh. This one comes with some simplified trading functions and it makes it possible to create an instance of the class Ctrade. That is called trade and we are going to use it to open positions. Inside of the ontick function we want to create a string variable called signal, but we don’t assign a value here. Now we want to calculate the Ask price and the Bid price. That is done by using Symbolinfodouble for the current symbol on the chart. We use either symbol underscore ask or symbol underscore bid. And with symbolinfodouble and underscore digits, we make sure that we automatically calculate the right number of digits behind the dot. Let’s create an array for the price data and we use ArraySetAsSeries to sort it from the current candle downwards. And now we use IOBV for the current symbol on the chart and the currently selected period on that chart. The third parameter is volume tick. And this function will give us the onbalance volume indicator, that is an oscillator. We use copybuffer to copy data into our array according to the definition that we have created here. We want to do it for buffer zero. We start with the current Candle zero and copy the data for 100 candles to store them in our array. Now we can calculate the current value by simply looking into candle zero of the array. Let’s calculate the number of the candle that contains the highest value. That is done by using array maximum and array maximum will deliver the number of the candle in the current array, starting from candle zero for the whole array that contains the highest value. There is a similar function that is called array minimum. That will do the same and calculate the number of the candle with the minimum value. And to actually get the value, we need to get the value for the candle number that we have just calculated. Let’s repeat that for the minimum value so that we can define the signal. Because if the current value is bigger or equal the max value, we consider that to be a buy signal. So we assign the word buy to our signal. Otherwise, if the current value is below or equal to the minimum value, we consider that to be a sell signal and now we assign the word sell to our signal. So if our signal equals sell and the return value for PositionsTotal is below one, that would mean we have no open Orders and a Sell signal. And that’s when we use trade.Sell to sell 10 Microlot. Otherwise, if the signal equals buy and we have no open positions, that’s when we use trade.Buy to buy 10 Microlot. Finally, we want to use the comment statement to output the current the max and the MIN values directly on our chart. So this is 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 videos in the basic video series. Or maybe even the Premium Course on our website might be interesting for you. That’s where you also can find a link for courses that contain the source codes here. For now, let’s click on View, toolbar and click on compile or press F7. That should work without any errors, and if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader, we use a little trick and click on insert, indicators, volumes, on balance volume. We will go with the default values. Click on OK, and here’s our oscillator. Now, let’s right click into the Chart, select templates, safe template. And save it as tester.tpl . You can override the current one, because tester.tpl is what we will see in the next strategy test, so let’s do that. And click on View Strategy tester or press Control and R. Please pick the new file, simple, IOBVA .ex5, scroll a little bit down and enable the Visual mode here. And start your test. Here we are, our Expert Advisor is running. You see that I have two on balance volume oscillators here, that is because I have overwritten the Tester.tpl template and in this little video you have learned how to calculate the highest and the lowest value for 100 candles of an oscillator. And you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 108 SIMPLE IOBVEA OSCILLATOR appeared first on MQL5 Tutorial.
In this video, we are going to find out how we can pass a whole array as a parameter to a different function, this is possible. So let’s find out how to do that with an 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 array reference. Click on continue. Continue and finish. Now you can delete everything above the Ontick function and the two comment lines here. We start by creating a simple small array for integer values, because this is just a simple example to show the concept. And it makes a lot of sense to create small programs like this one to find out how things work. So now we assign values to our array. Please remember the first value can be found when you access index zero. All the array values are whole numbers. We want to use those numbers for a simple calculation. So we want to pass the whole array to a function that is called addvalues. And please remember, usually we are going to pass parameters, but this is a whole array and the returned result should be shown on the chart. So let’s add a comment statement here that will show us the text. The returned result is followed by the result that we have calculated. But this function doesn’t exist, so we need to create it now. And here is where we need to add this little symbol here. It’s the ampersand symbol inside of our user defined function. We want to add the values for the array for index zero, one and two. And afterwards we are going to return the results to our main function, and that’s about it. If you have no idea what all the code here does, all of this was too fast for you, you probably want to watch one of the other videos in the basic video series first. By the way, on our website, we have a link for additional courses where you can get the source codes for this basic video stuff. That’s also where you can find the link for the Premium Course. This was a suggestion of a 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, let’s click on View toolbar and press the Compile button. Or you could also press F7 on your keyboard. You shouldn’t get any errors. And if that is the case, you can click on a little icon here or press F4 to go back to Metatrader. And in Metatrader you want to click on View Strategy tester or Press Control and R. Please pick the new file simple array reference dot .ex5. Mark, the option for the Visual mode, if you can’t see that, you might need to drag this little bar upwards. So now please click on start. And here is our returned result. It is fifty six. We have added the first three values here. That is eight plus 16. So this would be twenty four. And when we add this value, this will be fifty six. So let’s add actually another value here. Recompile the code and when we stop the test and start a new one, you should see a new value that is returned. This time it is one hundred and twenty. So our little Expert Advisor works as expected. And in this little video you have learned how to pass an array to a user defined function and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 107 SIMPLE ARRAY REFERENCE appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor that is able to calculate the values for this indicator. It is called the Ichi Moku Kinko Hyo. So let’s find out how to do that with MQL5. To get started, 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 Ichi Moku Kinko Hyo. He or 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 import statement that will import the file Trend.mqh. This one comes with MQL5 and it provides a few additional trend help classes. One of those classes is this one. It is called C I Ichi Moku. Here is the declaration and some additional information. We have methods that have been inherited from other classes. Here is the class hierarchy. Basically, it’s an object and we want to create an instance that is called I ichi Moku. This is actually not a mistake. Please don’t forget to use this asterisk. Now, we are going to continue with the on init function. We want to create the I ichi Moku only once that is done by using new C I ichi Moku. Here comes the actual creation. We create an instance for the current symbol on the chart and the currently selected period on that chart, followed by three values: nine, twenty six and fifty two. And you will see the same values when you click on insert indicators, trend, Ichimoku Kinko Hyo. The Tenkasen value is nine. The Kijunsen value is twenty six and the value for Sekuspan B is fifty two. And that’s exactly what we are going to use here. So now we have created our indicator object. We want to use Ichimoku.Refresh. That is one of the inherited methods from C Indicator and they say it updates the indicator data and it is recommended to call this method before we get the data. Now let’s calculate the values. The Tenkansen value is calculated by using Ichimoku.Tenkansen for candle zero. The Kijunsen value is calculated by using Ichimoku.Kijunsen for the current candle. The Senkouspan A value is calculated by using Ichimoku.Senkouspan A four minus twenty six candles. And that might look a little bit confusing. But if you take a closer look, you will see that this cloud here is calculated ahead of the current candle. Therefore we need to use this negative value here. Otherwise, it would be calculated for the current candle and that would be wrong. That can be really confusing, especially in the beginning, because you would get wrong values. Let’s continue with the Sekuspan B value. That’s basically the same. This one is also calculated for minus twenty six candles, and the last one is the Chinkospan value. To calculate this, you use Ichimoku.Chinkospan and this time we are going to use twenty six candles because this Chinkospan value is calculated for twenty six candles in the past.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 106 SIMPLE ICHIMOKU KINKO HYO appeared first on MQL5 Tutorial.
In this video, we are going to create a sell grid system that will open a sell position when the next sell price is reached. So let’s speed that up a little bit and you see that we have several positions. So let’s find out how to create something like this with MQL5. To do that, 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 sell Grid System. Click on Continue, continue and finish. Now you can delete everything above the Ontick function. And let’s also remove the two comment lines. We start with an include function to include the file Trade.mqh. This one will enable us to create an instance of the class Ctrade. It gives us simplified trading functions and it will be called trade. We also want to create an array for the price data, that is called price info and it is created by using MQLRates. And let’s create a string variable for the signal, that is also called signal, but we don’t assign a value here because we are going to calculate that later. Inside of the ontick function we want to start by creating a static double variable for the next sell price. Static is a modifier that will remain the value for as long as the Expert Advisor is running, even if we leave the function. Now let’s calculate the Bid price. That is done by using Symbolinfodouble for the current symbol on the chart, we are using symbol underscore bid and with normalize double and underscore digits, we make sure that we automatically calculate the right number of digits behind the dot. Because some currency pairs have five digits behind the dot and the other ones have three digits behind the dot. Now let’s use arraysetasseries for the price and for array to sort the current array from the current candidate downwards. And with CopyRates, we can now fill the array with data for the current symbol on the chart and the currently selected period on that chart, starting from candle zero for three candles. We store the data and the price info array, and we can also use underscores here like we did in this line. Now, if we have no open positions, that would be true when PositionsTotal has a value of zero, we want to set our next sell price to zero. That is a reset. Afterwards, we want to check our entry signal, by calling a function that is called check entry signal. That function doesn’t exist so far, so we need to create it in a few minutes, but before we do that, we want to check if the Bid price currently is below the next sell price or if the next sell price equals zero. If that is the case, we want to open a sell position, that is done by using trade.Sell for 10 Microlot. And right after we have done that, we want to set the next sell price 50 points below the current sell price level. Let’s also add a comment statement to create an output for the Bid price and for the next sell price right on our chart. So far, so good. That’s the ontick function. But now we need to create this function here. It is called check entry signal and it will return a string value. Because when the close price for the last candle in our price info array is above the open price for candle one in our price info array, we consider that to be a buy signal. So now we assign the word buy to our signal. Otherwise, when the close price for candle one in our price info array is bigger than the open price for candle one in our price info array that would be a sell signal. And now we assign the word sell to our signal. Finally, we want to return our signal to the main module and close this 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 in this video series. And on our website, you can now find a link for all these videos, including the source codes in our shop. For now, let’s enable the toolbar and click on compile or press F7. You shouldn’t get any errors. And if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader you want to click on View, Strategy tester or press Control and R. Please pick the new file. Simple Sell Grid System.ex5, mark the option for the visual mode. If you don’t see that it, is below here and start a test. Now you should see the first sell trade is opened. Here is the second one and every 50 points we will see a new sell trade. So our little sell grid system works as expected and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 105 SIMPLE SELL GRID SYSTEM appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor for a simple moving average crossover Sell Stop Loss. So let’s find out how to do that with MQL5. To get started 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 cross over Stop Loss. 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.mqh. This one is part of MQL5 and it will help us to use some simplified trading functions. Therefore, we create an instance of the class Ctrade and call it trade. Inside of the ontick function we start by calculating the Ask price. That can be done by using symbolinfodouble for the current symbol on the chart, we are using symbol underscore ask and with normalize double and underscore digits we automatically calculate the right number of digits behind the dot. Now let’s repeat that for the Bid price. This is very similar. But to calculate the Bid price, we are going to use Simbol underscore bid. For the signal, we use a string variable. This is called signal, but we don’t assign any values here because we are going to calculate that later. Now, let’s create two arrays, one for the small moving average array and one for the big moving average array. The small moving average is defined by using the IMA function for the current symbol on a chart and the currently selected period on that chart. We are going to calculate it for twenty candles. The shift value is zero. We use ModeUnderscore SMA for simple moving average and the result should be calculated based on the close price. Let’s repeat that for the big moving average, this time we are going to use the same function, but for 50 candles, everything else is similar. And with Copybuffer, we now can fill the small moving average array according to the definition that we have created here for buffer zero, starting from the current candle zero, we copy the values for three candles and store them in the small moving average array. Now let’s do the same for the big moving average array. Once we have done that, we can now find out if the big moving average array for candle one is below the small moving average array for candle one. If that is the case, we consider that to be a buy signal, so we assign the word buy to our signal. In the other case, if the big moving average array for candle one is bigger than the small moving average array for candle one, that would be sell signal. And now we assign the word sell to our signal. And if our signal equals buy and we have open positions, we are going to use a function that is called close all sell position this pair. Otherwise, if the signal equals sell and the return value for PositionsTotal equals zero, that would mean that we have no open position. So now we need to open a test position, that is done by using trade.Sell. We are opening a position for 10 Microlot. Please remember, this is just a test position. You wouldn’t do that on a real account. And to see what’s going on, I would like to add a comment statement that will output the text the signal is now followed by the signal. That’s it for the main part, but to use this function, we need to create it. Now, the name of the function is close all sell position this power we are using void because we don’t need to return value. Now we need to use a For loop for all the positions and go through each and every position to get some details. The first detail is the ticket number. We can get that by using position get ticket for the current counter value of the For loop. And we also need to get the currency pair for the position. That is done by using position get symbol for the current counter value. And as we only want to close sell position, we need to find out the position direction, that is done by using position get integer for the position type. So let’s check if the position direction equals position type sell. That would mean we have a sell position. We also want to know if the current symbol on the chart is equal to the currency pair of the position. And if both conditions are true, we are going to close the current position. That is done by using trade dot buy position close for the current ticket number. Finally, we need to 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, maybe you want to watch one of the other videos in this basic video series or maybe even the Premium Course on our website might be interesting for you. There you will also find a new link for source codes for this basic video stuff. But for now, please click on the Compile button or press F7 on your keyboard. I have made a mistake and I need to remove the additional bracket here. Now let’s recompile the code. This time we have no errors. And if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader you want to click on View, Strategy tester or press Control and R. Please pick the new file Simple
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 104 SIMPLE SELL CROSSOVER STOP LOSS appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor for a simple buy grid system, it will open buy trades every 50 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 filem, Expert Advisor from Template, continue. I will call this file simple buy grid system. 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 fire Trade.mqh. This is part of MQL5, and now we can create an instance of the class Ctrade that is called trade. We also want to create an array for the price info data that is done by using MQLRates. And we want to declare a global variable for the signal. This is a string variable, but we don’t assign any values here. Inside of the ontick function we declare a static variable. Static variables will hold their values inside of the function for as long as the Expert Advisor is running. It’s a double variable so it can hold floating types. And the name is next buy price. Now let’s calculate the Ask price, that can be done by using Symbolinfodouble for the current symbol on the chart. We use simple underscore ask and with normalize double and underscore digits, we automatically calculate the right number of digits behind the dot. Let’s continue and use ArraySetAsSeries to sort the price array from the current candle downwards. And now we want to use CopyRates for the current symbol on the chart and the currently selected period on that chart to fill the price array with data starting from candle zero for three candles. Let’s actually use an underscore here. So if we have no open positions, that would be true when PositionsTotal delivers a return value of zero, the next buy price is also zero because we have no level. Now let’s check for the entry signal. We do that by calling a function that is called check entry signal here, we need to code that later on and the return value will be assigned to our signal. And one of the entry conditions is that we only want to buy if the Ask price is above or equal to the next buy price. And if that is true, we also want to check if the signal equals buy. In that case, we want to use trade.Buy to open a buy trade for 10 Microlot and now we set the level for the next buy price 50 points above the current Ask price. Finally, we want to create a comment statement to output the Ask price and the next buy price on our chart. That’s it for the Ontick function. But to use this function, we need to create it now. Our function is called check entry signal. I’m using a very simplified version and check if the last candle is bullish. That is true when the close price is above the open price. And in that case we assign the word buy to our signal. In the other case, if the close price is below the open price, that would mean that the candle is bearish. And now we assign the word sell to our signal. Finally, we return the signal to our main module 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 become a Premium Course member. You can find the Premium Course on our website. This actually was the suggestion of a current Premium Course member. And if you are already a premium member and have an idea for a video like this one, just sent me an email. For now, please click on the Compile button or press F7 on your keyboard. I have an additional bracket here, so let’s remove that. Recompile the code. And this time we have no errors and no warnings, and in that case, you can click on a little icon here or press F4 to go back to Metatrader. And in Metatrader, you want to click on View, Strategy tester or press Control and R, please pick the new file. Simple buy grid system.ex5 mark the option for the visual mode here and start your test. Here we are. Our first position has been opened. The next buy price currently is set to zero and as soon as we have a bullish candle we see that it is adjusted. And here we see the next position is opened, so our little Expert Advisor is working as expected. And in this little video you have learned how to create a simple buy grid system and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 103 SIMPLE BUY GRID SYSTEM appeared first on MQL5 Tutorial.
In this video, we are going to open some test positions, buy positions, and those positions will be closed when the crossover of these two moving averages happens. So let’s find out how to do that with MQL5. 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. I will call this file simple by cross over Stop Loss. 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. We start by including the file Trade.mqh and we want to create an instance of the class Ctrade that is called trade and will provide some simplified trading functions. We first need to calculate the Ask price. That is done by using Symbolinfodouble for the current symbol on the chart, we want to use symbol, underscore, ask and with Normalize double and underscore digits we automatically calculate the right number of digits behind the dot. Let’s also repeat that for the Bit price. And now we create a string variable for the signal for a crossover. We need two arrays, one for the small and one for the big moving average. The small moving average definition is created by using the IMA function for the current symbol on the chart and the currently selected period on that chart, we are going to use twenty candles. No shift value in this case. I’m using ModeUnderscoreSMA for simple moving average. But you also could use ModeUnderscoreEMA for exponential moving average and the calculation should be done based on the close price. The definition for the big moving average is very similar, but in this case we are using 50 candles. Now we use copybuffer to fill our array for the small and for the big moving average. According to the two definitions that we have created. We do that for buffer zero from Candle zero. That’s the current candle, and we copy the price data for three candles and store them in the arrays for the small and for the big moving average. And whenever the big moving average array for candle one has a higher value than the small moving average array for candle one, we consider that to be a buy signal. In the other case, if the big moving average array for candle one is bigger than the small moving average array for candle one, that would be a sell signal. The idea is to close all buy positions for the current currency pair. When we have a sell signal and when the return value for PositionsTotal is bigger than zero. That means we have open buy positions and want to close them, but we need to have something to close. So I’m going to open test positions when the signal equals buy and when we have no open positions, that’s when we are going to use trade.Buy to buy 10 Microlot. In our case, we are using Stop Loss value of 200 points and a Take Profit value of one hundred and fifty points. Please remember, this is just a test position, you wouldn’t do that on a real account and to see what’s going on, I would like to have a comment statement that will output the text. The current signal is now followed by the signal. Well, this function does not exist, so we need to create it now. The name of the function is close all buy positions this pair. We use void because we don’t require a return value. Inside of the position we are going to use a for loop to count down until there are no positions left. We need to get the ticket number, that is done by using position get ticket. We want to identify the current currency pair. That can be done by position, get symbol. In both cases we are using the current counter for the current position. Now let’s get the position direction. That is done by using position, get integer and the parameter here is position underscore type. And if the position direction equals position type buy, we have a buy position. Now we want to check if the current symbol on the chart equals the position symbol. You could use symbol with an underscore, that stands for my current currency pair. And if this is equal to the currency pair for the position that we have identified, we want to use Ctrade dot position close, to close the current position. Now, let’s close the For loop and the function. And this is basically 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 videos in the basic video series or maybe even the Premium Course on our website might be interesting for you. For now, please click on the Compile button or press F7. Oh, I have an additional bracket that I need to remove here. Now, let’s recompile the code. This time we have no errors, and if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader, we want to click on View Strategy tester or Press Control and R, please pick the new file simple buy cross over Stop Loss.ex5 mark the option for the visual mode here and start a test. Here we are. We have a buy position and as soon as we see a cross over this position should be closed. And that should happen right now. So our little Expert Advisor is working as expected, and in this little video, you have learned how to use a moving average crossover to close open buy positions, and you
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 102 SIMPLE BUY CROSSOVER STOP LOSS appeared first on MQL5 Tutorial.
In this video, I would like to talk about a question that I get from time to time, and that is the question what kind of hardware can I use to work with Metatrader4 or Metatrader5? So let’s go through all the different solutions that I use. This system here currently is running on a so-called virtual machine, I’m actually using the same virtual machine right now to record this video. This is the new version for the crowd algo trading system that I’ve created on January the 27th. And I would like to do a live trading experiment in February. So I have coded this system on this virtual device. The virtual machine is running on a software that is called Virtualbox. This kind of software can be downloaded from the Internet and it will actually help you to run one operating system as a window inside of a host operating system. In my case, I’m using Linux as my main operating system and Windows is running in a virtual device. If you prefer to not use virtual devices, but real ones, you can use a software like this one. This is VNC Connection Viewer. I can use it to connect to different PCs. I have a lot of those devices. This one is a Windows eight device. It’s running with two gigabytes of Ram. The Metatrader is running smoothly. I can move the machine around and it’s also possible to remote control everything. This, by the way, is the MQL4 version of the crowd algo trading system, and today we have two thousand two hundred seventy three dollars of gross profit. If you are interested, you can watch the videos that I have made for this MQL4 version. By the way, the Windows four version is running on such a stick device. They call it computer sticks. Those sticks are a little bit bigger than an average USB stick. They don’t need much room and you can use them on screens or TVs because they come with an HDMI port. A device like this one is around 100 dollars. But for the new system, I decided to buy one of these mini pcs here. This is a little bit bigger than cigarette box. You see the pen here, the whole thing, including the keyboard would fit into a pocket. And this hardware is a little bit better and it’s newer. We have, I think, four gigabyte of RAM and it’s very affordable. You might be able to find it for around 100 dollars online. The really cool version would be to use devices like these mini notebooks. Maybe you remember that kind of device from about 20 years ago when we all used pocket PCs. These pocket notebooks have been very popular. But back then they only had Windows Mobile or the Symbian operating system. But these two machines here run with Windows 10 and eight gigabyte of RAM. That is more than enough to run Metatrader. And you can do a lot of other cool stuff. For example, mobile programming. If you don’t want to spend that kind of money, you could run Metatrader on an old netbook. This device is about 10 years old. It’s running with MX Linux. And when you use software like play on Linux and wine, it’s also able to run Metatrader. Used devices like this one would maybe cost between 50 and 100 dollars. And when I started out to use automated systems, I had over half a dozen of these devices on my desk. But today I really prefer to run Linux on a desktop PC, Virtualbox in the background running Microsoft Windows. And when you are not at home, you could use this mobile version of Metatrader to at least see what’s going on with your account. I think it’s available for Apple devices, too. This one is from the Android store. You can see all the numbers, but it’s not possible to do automated trading on mobile devices right now. And basically, that’s it. So now you know what kind of hardware you need to run Metatrader. That’s all for today. And thank you for listening.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – 101 WHAT HARDWARE FOR ALGORITHMIC TRADING appeared first on MQL5 Tutorial.
In this video, we are going to create a triangle object on the chart, you see the little yellow triangle here. This is actually an object. So let’s find out how to create it with MQL5. To do that, 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 Triangle, click on Continue, continue and finish. Now you can delete everything above the ontick function and let’s also delete the two comment lines here. We start by creating two variables for the highest and for the lowest candle. Afterwards, we want to create two arrays. Those are called high and low. And now we need to use ArraySetAsSeries to sort out arrays from the current downwards, we do that for the high array and of course, we also need to do it for the low array. Now we want to use CopyHigh, because that will give us the highest bar prices for the current symbol on the chart and the currently selected period, starting from Candle zero for 30 candles. And it will copy the values into our high array. And you might have guessed it. Now we can do the same with CopyLow to copy the lowest values into our low array. And once we have those values, we can calculate the highest candle by using ArrayMaximum. That will give us the largest element in our array. In this case, in the high array, starting from Candle zero for 30 candles and for the Iowest candle, we can use ArrayMinimum, that will look into the low array starting from Candle zero for 30 candles. And this will give us the lowest candle. Afterwards, we use MQLRates to create another array for price information. This one also needs to be sorted downward from the current candle downwards. Now we use CopyRates for the current symbol on the chart and the currently selected period on that chart, starting from Candle zero. This expression here will give us all the available price information for the bars on the chart and the result will be stored in our price information array. Before we want to create a new object we use object delete for the current symbol on the chart to delete any former objects that might have the name triangle. And after we have done that, we can create a new object, that is done by using object create. For the current symbol on the Chart ID, the object name will be triangle, the object type is OBJ underscore triangle, all in capital letters please. It will be created in our main window at the point in time where we see candle 30 for the close price from candle thirty. That’s our anchor point. And we draw it to the point in time for the Iowest candle to the lowest price of the lowest candle. And the other side will be the point in time for the highest candle and the highest price for the highest candle. Remember, this is all for the last 30 candles. Now let’s change a few properties. That is done by using ObjectSetInteger. The first value is for the Chart ID. And zero means that we are going to do it on the current chart for the object that is called Triangle. We want to change the property that is called OBJ Prop_Color, and we want to change it to yellow. Finally, we want to repeat that this time we do it for the property object property fill and use yellow to fill the background. So far, that’s 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 videos in this basic video series or maybe even the Premium Course on our website might be interesting for you. For now please click on the Compile button or F7 on your keyboard. I need to remove this additional bracket here. Now, let’s recompile the code, and this time we have no errors, and if this is true, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader, you want to click on View Strategy tester or Control and R, please pick the new file. Simple triangle dot .ex5 mark the option for the Visual mode. If you don’t see that, you might need to drag the lower part until this box becomes available. Now let’s click on Start to start your test and now we see our triangle object is created. And it changes with every new candle because and this little video, you have learned how to create a dynamic triangle object and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS 100 – SIMPLE TRIANGLE OBJECT appeared first on MQL5 Tutorial.
In this video, I would like to talk about a new system that I have released on January the 1st, 2021. It’s an automated algo trading system. I have also published it on the website, MyFxbook. I also need to mention that this is not an MQL5 system for Metatrader5, but it is an MQL4 system made for Metatrader4. This is my statistics page on MyFxbook, and as you can see, the system started to grow very quickly. But after a few days, the balance curve started to get flat and therefore I asked myself if it would be a good idea to close all open trades, including the open losses, because I have seen this kind of behavior before. Therefore, I have coded a function to show a message box, when I click on the chart in the upper left corner and it says, Would you like to close all positions? I will not do that right now. But I did it yesterday. And after I did that, I have a net and a gross profit of one point five one percent for twelve days. So that translates to 15 percent and one hundred and twenty days and as a year has three hundred and sixty five days, we could expect forty five percent profit. But actually I don’t think that we will do that much. But you can see yourself. I have called this system crowd algo trading system because my company name is Crowd Company and if you take that term and google for it, you should be able to already see a lot of results for it. For example, this is the YouTube channel. This is yesterday’s video. It’s automated content because I have to do one of those videos each day. Here is the link to the Web page. And if you click on that and click on one of the current posts, you will see the same video content. And below that, we have the download for the Metatrader setup file. This is the download for the demo system that will work on Metaquotes, original demo accounts. And here is the download for the statistics. When I click that and open the page, I see a timestamp for January the 12th. That’s actually the current day. So far we have made four hundred and fifty dollars profit and I expect this system to be a good choice because actually it is a clone from this system. I have traded this one in 2020 with good results. You’ll see this drawdown here in March. That was the time of the first Lockton here in Germany. And I have tried other systems that have not performed that well. As I’m happy with the results of this one, I took it as the foundation for the new one. This MyFxbook Expert Advisor will upload the current statement every five minutes. Currently we have January the 12th and when you see this video sometime later, you should still be able to get the current statistics when you click on this link, it works without any credentials. Here is the official system page, currently we have made 59 trades, but this will increase in the future. And if you’re interested to learn what is working and why it is working, you can analyze each and every of these positions here. So for now, that’s it. If you have any questions or suggestions about the system set up, just send me an email. For now, I will let this system do its job. And I would like to say thank you for listening.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – 99 NEW LIVE CROWD ALGO TRADING SYSTEM appeared first on MQL5 Tutorial.
In this video, I would like to talk about how to clone an existing Metatrader5 installation and create a portable version that also can run from an USB stick. To do that you first need to have a pre configured installation like I have here. This is on a Windows machine. And when you click on file open data folder, you will see that the setup has created a folder inside of the user’s folder. That’s usually something like this one. And inside you see several files and directories, but not all of what we need. But it’s possible to create a portable version. Actually, I have done that by using play on Linux and MX Linux. I have just copied my complete folder. This is a brand new Windows 10 machine. This is my USB stick. I have created a version for Metatrader4 and this one is the one for Metatrader5. I can now copy the whole directory and paste it anywhere here in the file system without any installation, that might take a few seconds. It’s also moving my history files here. So let’s wait until this is finished. OK, now it is finished. I have no search results for any installation, but inside of this directory I can now click on the terminal64.exe file and you should see that Metatrader is started in the background. This can take some time at the first start up, but here it is. Now I need to connect my account. So let’s click on Continue. This is my existing real cent account 5245388. So let’s type that in. And I also need to type in my password. Click on Finish. And now I’m connected. Here is my Expert Advisor. Let’s click on file, open data folder. Now it has created the user directory here is the experts folder. It copied everything, including the zip file. Here is my source code, my .ex5 file and folder for the library. My account stats. Let’s try a strategy test. It’s downloading history data. And here’s the Strategy tester. We have the first trade here. So it’s actually running. And in this little video, you have learned how to create a portable version of your existing Metatrader5 installation, including the Expert Advisor settings. You have done it yourself in a few minutes. And if you have any questions or suggestions about this kind of setup, please let me know.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS 98 – HOW TO CLONE YOUR MQL5 SYSTEM appeared first on MQL5 Tutorial.
In this video, we are going to create an Expert Advisor that is able to change the course direction for every trade. 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 reverse position. Click on continue, continue and finish. Now you can remove everything above the Ontick function and the two comment lines here. We start with an include statement to include the file Trade.mqh. This one comes with simplified trading functions for MQL5 to use it, we now need to create an instance of the Class Ctrade. We will call it trade. Let let’s also create some variables here. The first one is a string variable for the direction, the initial value will be buy for this simple example, the next variable is called take profit points. This one has a modifier that is called input. And this input modifier will make it possible to change the variable settings without the need to recompile the code. We can do it from the Expert Advisor settings. Now let’s create another one. This one is called Stop Loss Points. We will set this one to thirty points. Inside of the ontick function we need to calculate the ask price, that is done by using symbolinfodouble for the current symbol on the chart. We use symbol underscore ask as we want to calculate the ask price and I like to use normalize double and underscore digits to automatically calculate the right number of digits behind the dot. Now we will repeat the whole thing for the bid price. This is almost the same, except that we are going to use symbol underscore bit in this case. Now let’s check if we have no open position, that can be done by using positions total and if the return value is zero, we have no open position. And we also want to check if the current direction to trade is set to buy and if both conditions are true, we use trade.Buy to buy 10 microlot, for the current symbol. Let’s actually say that. We want to buy for the current ask price. The next expression here is the stop loss. That will be set to the value that we have defined here, followed by the parameters for the take profit. That’s the value here. And the last variable here could be a comment. We don’t need that. So we sell it to Null. And as we want the next trade to go into the other direction, we will now change the direction to sell. That’s it for the buying part, the selling part is very similar. First, we need to check if we have any open positions and if we don’t have, we want to check if the direction is set to sell and if both conditions are true, we use trade.Sell to sell 10 microlot for the current symbol on the chart. To sell, we need to use the bid price and of course, when we sell, we need to set the stop loss points to a value above the current price, and the take profit value will be below the current price. Afterwards, we change the direction to buy. Now, you might ask yourself, why would anybody do something like this? Well, it’s a good idea to test other components in your system. And actually, if you do this exercise and change the values for take profit and stop loss, you will probably learn something that you didn’t expect. I would like to see the current direction. So I’m going to add a comment statement here that will output the text: “the current direction is”, followed by the direction. OK, 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 videos in our basic video series or maybe even the Premium Course on our website might be interesting for you. Actually we currently also have the starter course on the website for just one dollar. But for now, please click on the Compile button or press F7 on your keyboard, you shouldn’t get any errors here. And if that is the case, you can click on the little button here or press F4 to go back to Metatrader. And in Metatrader, you want to click on View Strategy Tester or Press Control and R. Please pick the file simplereverseposition.ex5 mark the option for the visual mode. If you can’t see it, you might need to move the lower panel a little bit. Here is the option, so please mark it, click on start to start your test and now we see the first trades here. That direction is changing from buy to sell, and we can see that the stop loss is a little bit bigger than the take profit value here. So let’s stop the Expert Advisor, click on inputs. Now, we can change the value for the stop loss or for the take profit points. I have set those values to 30 here. Let’s restart the test, and this time we can see that both values are equal. So our little Expert Advisor works as designed. And in this little video, you have learned how to create an Expert Advisor that is able to change the trading direction for each position. And you have created yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS 97 – SIMPLE REVERSE POSITION appeared first on MQL5 Tutorial.
In this video, we are going to create such a moving text object, it will output the current low price for the current candle. 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 and here you want to click on file, new file, Expert Advisor from Template, continue. I will call this file simple moving text object. 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, we start by using MQL rates to create an array for the price info. MQLRates is a structure that stores information about the price, the volumes and the spread, and it will also store some time information. Now we are going to use ArraySetAsSeries to sort the array from the current candle downwards. And with CopyRates we can fill the array for the current symbol on the chart and the currently selected period on that chart. And we want to copy the values for three candles and store them in the price info array. But let’s actually do it this way. Basically, it’s the same. If you mark that and press F1, you will see that you can exchange this function and use underscore period instead, these two values will automatically calculate the right symbol on the chart and the currently selected period on that chart. Now let’s move on and create an object. That is done by using object create for the current symbol on the chart. The object name will be moving text. This is the object type. If you mark that and press F1, you will see that there are lots of different object types that you can use and we are going to use this one. It is able to output values and text. The last three parameters here are set to zero. Those are for the current subwindow. In case we use window zero, it will be the window where we draw the candles. And the next parameters are for the date, time and the price. I didn’t provide this information here because we are going to use object_move later on to move our moving text to the point in time and the price that we want to use. But before we do that, we want to change a few properties. In this case, we use ObjectSetInteger for the Chart ID zero and the object that is called moving text. We want to change the object property font size and set it to eight. Let’s repeat that, this time for the font color. The first two parameters are the same. This time we want to change object property color and set it to CLR red. If you mark that one and press F1, you will see that you can have a lot of different colors for several objects and to shift the form to vertical alignment, we are going to use ObjectSetDouble this time for object property angle and we will set that value to ninety degrees. And of course we need to set that text value that is done by using object set string for the object property text and the text will be low followed by a colon. And this expression here will give us the low price for the current candle. Now our object is finished, so let’s move it. And to do that we use object move. The first parameters are the same. The third parameter is for the alignment, or I think they call it the anchor point. We are going to move our object to the point in time where we print candle zero and we want to align it to the low price of candle zero. That’s the current candle and that’s basically it. If you have no idea what all the code here does or if this was too fast for you, maybe you would like to become a Premium Course member. You can do that on our website. And this was another suggestion from a Premium Course member. So if you are a Premium Course member and have any ideas for a video like this one, please let me know. Let’s click on View Toolbar. And press the compile button, or you can also use F7, we don’t have any errors, and in that case, we can click on a little button here or press F4 to go back to Metatrader. And in Metatrader, you want to click on View Strategy, Test or Press Control and R. Please pick the new file simple moving text object.ex5, mark the option for the visual mode. You might need to drag the strategy tester panel a little bit to see all the options. Here is the Visual mode, now let’s click on Start to start your test. Here we are. This is our little text object, it is moving and you can see that it changes the values while it’s moving. And then this little video, you have learned how to create a moving text object and you have coded it yourself with a few lines of MQL5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 96 SIMPLE MOVING TEXT OBJECT appeared first on MQL5 Tutorial.
in this video we are going to create this kind of object this is a low gann fan object and we want to find out ho w to create one with mql5. to do that please click on the 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 object simple lowgann fan. click on continue, continue and finish. now you can delete everything above the ontick function and the two comment lines here. the first thing we need to do is to calculate the number of candles on the chart, that can be done by using chart get integer for the chart id 0. we use chart first visible bar, all in capital letters and the last parameter is for the sub window, subwindow 0 is the one with the candles. now let’s create a variable for the lowest candle, we also need to create an array. i have called it low. with array set as series we are going to sort our low array from the current candle downwards and now we can use a function called copy low that will give us the minimal bar prices for the current symbol on the chart and the currently selected period. we start with candle 0 for all the candles on the chart and copy the values into our low array. now we can calculate the lowest candle by using this function that is called array minimum that will give us the lowest element in our array and that’s inside of the low array. we start with the first candle that’s candle 0 and we will go through all the candles on the chart and store the number for the lowest candle in this variable here. let’s continue with mql rates, that will create a price information array for our prices but mql rates also will give us the time point for the candle. let’s use array set as series for this one to also sort it from the current candle downwards and now we can use copyrates for the current symbol on the chart and the currently selected period on that chart. we start with candle 0 for all the candles on the chart and store the candle values in our price information array. before we can create a new object we want to use object delete to delete old objects for the current symbol. i want to delete the objects that are called simple lowgann fan and afterwards we are going to use object create to create a new one. so let’s go through the parameters here. the first parameter 0 stands for the current chart. the second one is the object name. i have called my object simple lowgann fan. parameter 3 is for the object type, i’m going to use obg underscore gannfan here. if you mark that and press f1, you will see that there are lots of different objects. this is the one that we are going to use. the next parameter is for the main window, that’s windows 0 and we want to draw our object for the point in time where we have the lowest candle in our price information array. we want to start with the lowest price of the lowest candle. the second reference point is the point in time for the current candle 0 and as the last parameter we are going to pass the low price for the current candle in our price information array. that’s it for the object create part. let’s set a few properties. the first property is for the object color. we are using object set integer for the chart id 0 and the object with the name simple lowgann fan. we want to change the object property color and set it to red. now let’s set the trend direction. the first part is similar but this time we are going to use object property direction and we are going to use gann uptrend. let’s continue and set the scale. that is done by using object property scale and my value here is 2. and finally we want to set the property object property rayright to true because that will give us a kind of object prediction and draw the lines right into the future. so far so good. if you have no idea what all the code here does or if this was too fast for you, maybe you want to watch one of the other videos in the basic video series. or maybe even the premium course on our website might be interesting for you. for now please click on view toolbar and click the little button here or press f7 on your keyboard. i need to remove this bracket here. now recompile the code and this time i don’t have any errors and if this is the case you can click on a little button here or press f4 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 lowgonfan.ex5 mark the option for the visual mode here and start your test. here we are our little expert advisor is working as expected we see that the gann fan object is drawn from the lowest candle on the chart and in this little video you have learned how to create a lowgann fan object on your chart. and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 95 SIMPLE LOW GANN FAN OBJECT appeared first on MQL5 Tutorial.
In this video, we are going to write price data into a spreadsheet like this one right out of MQL5. So let’s find out how to do that. To get started, please click on the little icon 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, SimpleSpreadsheetWriter, click on Continue, Continue and Finish. Now you can delete everything above the OnTick function and the two comment lines here. We start by creating static variables for the last high and the last low. A static variable will remember the value inside of this function for as long as our Expert Advisor is running. Afterwards, we use MqlRates to create a price info array. Because MqlRates is a structure that stores the information about prices, volumes, and spread. Afterwards, we use ArraySetAsSerries to solve the price info array from the current candle downwards. And now we can fill the array by using CopyRates. For the current symbol on the chart and the currently selected period on that chart, we want to start with candle zero and copy the price data for three candles into our price info array. Now let’s check if we have a new candle, and that would be the case if the value for last high is different than the high value for candle one in our price info array. And we also want to check if the last low value is different than the low value for candle one in our price array. Now we can start to write our file, and to do that we first need to define a name for the file. I will call this file, spreadsheet.csv, CSV is a file extension that is recognized by most spreadsheet calculation programs like Excel or LibreOffice. I think it stands for Comma Separated Values. Now that we have defined the name we want to open the file. That can be done by using FileOpen. And FileOpen will try to open the file and if it doesn’t exist, it will create one for the name of our spreadsheet that we have defined here, and we need to pass a few parameters, FILE_READ and FILE_WRITE will open the file for read and write access. This is the file mode, it is called FILE_CSV, and we are going to use the ANSI mode to write the file. Now, when you mark that and press F1, you will learn that we can use ANSI mode or Unicode mode. Unicode would be necessary for special characters like German Umlauts. But as we are going to use simple texts and a few numbers , ANSI is okay, we are going to write a CSV file, but you could also create a text file. And if we have been able to open the file, we now need to go to the end of the file, that can be done by using FileSeek. For our file handle that we have created here, we start with the first entry that’s index zero, and we want to seek the end of the file, seek end will do that and will take us to the last character in the file. I want to do that because I want to append the values and not delete the former content of the file. And that can be done by using FILE_WRITE. For the spreadsheet file handle, we are using commas. I’m going to write a descriptive text followed by the value for the candle one in our price info array. And the first one is the time. This will create a time stamp, followed by the description high for the high price of candle one in our price info array, and afterwards the low for candle one, you could append further values if you are interested. For example, for the open and the close price. After we have written the content, we want to use FileClose to close our spreadsheet until the next candle comes up. And to find out if the candle has changed, we are now going to assign the high price for candle one in our price info array to the variable last high, and the low price for candle one in our price info array to the last low, because the current values for candle one will be the last values the next time this function is called. Let’s add a comment statement here for the last high and the last low. So we have a chart output while the Expert Advisor is running, and that’s basically 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, or maybe even the premium course on our website might be interesting for you. For now, we want to click on View, ToolBar and click on Compile or press F7. That should work without any errors and if that is the case, you can click on the button here or press F4 to go back to MetaTrader. And in MetaTrader you’ll want to click on View Strategy Tester or press control and R. Please pick the new file, SimpleSpreadsheetWriter.ex5, mark the option for the visual mode and start your test. Now our StrategyTester is running and we see that we have two, three candles so far. So let’s speed that up a little bit. Stop the test, and here is my spreadsheet.csv file. It’s located in my user folder. It depends on your operating system, but in my case, it’s below AppData, Roaming, MetaQuotes, Tester, inside of a folder that is called MQL5 Files. You could also specify a file path if this kind of folder is too long for you. Now let’s double click on the file, and here we see that the
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 94 SIMPLE SPREADSHEET FILE WRITER appeared first on MQL5 Tutorial.
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, and I would like to change it to orange. Another property is called object property direction. The first part is the same, but this time we want to change this property and I have used Gann Down Trend here, that stands for a line corresponding to the downward trend. Let’s modify another property, this one is called object property scale, and I have used the value of two. And finally, the last one, this is called object property ray right. I have set it to true, and it will be used to draw the line to the current candle and into the future. So far so good, 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 videos in this basic video series, or maybe even the premium course on our website might be interesting for you. For now, I want to click on view, toolbar, and click on the compile button, or press F7. This should work without any errors, and if that is the case you can click on the little button here, or press F4 to go back to MetaTrader. In MetaTrader, we want to click on view, strategy tester, please pick the new file, SimpleHighGannFan.ex5, mark the option for the visual mode here and start a test. Here we are, our object is drawn on the chart, we can zoom in or out, and the lines will be adjusted. So our little expert advisor works as designed, and in
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 93 SIMPLE HIGH GANN FAN appeared first on MQL5 Tutorial.
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 in time, and these are values. As a value, I would like to add the lowest candle and the lowest price of that candle. That’s the first point. The second point is the time where candle zero is drawn. Candle zero is the current candle on the chart. And again, I will pass the lowest candle and the lowest price here. The next parameter is for the second line. I would like to have that drawn for all the candles on the chart. But this time I would like to pass the highest candle and the highest price for a reference point. Let’s close that, and that was ObjectCreate. You can play around and use other parameters here, but for this simple example, this is good enough. Now, let’s change a few properties. The first one will be changed by using ObjectSetInteger for the chart ID zero. I would like to change the property for the object that is called SimpleChannelObject. The property is called Object Property_color. I would like to have a yellow color. Now let’s continue and change the deviation. Everything is similar, but this time we are using ObjectSetDouble, and the property we want to change is called ObjectPropertyDeviation. I have chosen the value two here. Let’s set another property. This time it is called ObjectPropertyWidth. I have set it to one. Last but not least, we want to change the ObjectPropertyRayRight, and set it to true because that will draw our channel right into the future. Okay, that’s about it. If you have no idea what all the code here does, or if
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 92 SIMPLE DEVIATION CHANNEL OBJECT appeared first on MQL5 Tutorial.
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, you can call it whatever you want as long as you use the same name everywhere, parameter three is called obj channel in our case and if you mark that and press F1 you will see that we have lots of different object types even different channel types, in this case, we are using this one and we want to draw the first line for the lowest candle and this is the point in time where we want to start, in this case, it would be this candle because here we have the date time values and the line should be drawn for the lowest price of the lowest candle. I want it to be drawn up to the current candle, this is the second time point and here I repeat the parameter that I have used here that will make it a horizontal line, the second line should start at the time that the highest candle was drawn. In this example, it would be here, this candle. And I want the second line to be drawn for the highest price of the highest candle that was the object creation. Now let’s change a few properties for our object! That is done by using object set integer for the chart id zero and the object that is called simple channel object, I want to change the object property color and set it to yellow. Now we repeat that and change
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 91 SIMPLE CHANNEL OBJECT appeared first on MQL5 Tutorial.
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. And the last parameter that we are going to change is called obj property ray right and that is used if you want to draw the line into the future, so 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 videos in the basic video series or maybe even the premium course on our website might be interesting for you, for now, we want to click on view, toolbar and click on the compile button or press F7. I made a mistake, it says I missed a semicolon here, now let’s recompile the code and this time it works. This is a good example because when you see a dozen errors below that doesn’t really mean that you made a dozen mistakes, just by removing the one semicolon I can produce fourteen errors here, so please keep that in mind, from just one little thing. Now let’s compile it again and press the little button here or press F4 to go back to Metatrader. And in Metatrader we want to click on view, strategy tester or press control and r, now let’s pick the new file, simple low price line dot ex5, mark the option for the visual mode here and start a test. Here is
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 90 SIMPLE LOW PRICE TREND LINE appeared first on MQL5 Tutorial.
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 this is a value-based scale, so let’s start with the time for the highest candle and in the next parameter we will pass the value for the highest price of the highest candle, this is where the line should start. Now let’s define our second point, this is the time for candle zero or the current time for the current candle and we want the line to be drawn through the highest price of the current candle. That’s it for the object creation. Now let’s change some properties! To change the object color we are going to use object set integer for the current chart and the object that is called simple high line trend, we want to change the object property color, I have used red because I want to see a red line. In the next step, we repeat that and use object set integer for the current chart and the object called simple high line trend but this time we are going to use object property style to change the style for the line to solid, if you mark that and press F1 you will see that we can have solid lines, dotted lines and a few other styles. Let’s change another property, this time it is object property width, I want a thin line, so I choose one and here comes an interesting property, this one is called
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 89 SIMPLE HIGH PRICE TREND LINE appeared first on MQL5 Tutorial.
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 the alligator jaw, the alligator teeth, and the alligator lips values on our chart. This one belongs to the end of the source code and basically, that’s it. Well, 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 videos in the basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on view, toolbar and click on the compile button or press F7. I don’t have any errors and if that is the case you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader you need to open a new chart, click on insert, indicators, Bill Williams, alligator, we want to calculate the indicator for thirteen candles for the jaws, eight candles for the teeth and five candles for the lips, please set the shift values to zero, in my case the method is simple and we want to calculate the values based on the close price. Afterwards, please click on okay. Now you should see the indicator on the chart, now right-click, select templates, save template and save it as tester dot tpl because this is the template that we are going to see in the strategy tester. You can override the current one. Now let’s click on view, strategy tester or press
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 88 SIMPLE ALLIGATOR INDICATOR appeared first on MQL5 Tutorial.
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, this one is the interesting parameter because we can use it to check the name of the object but before we do that we want to know if the id for the event is equal to chart event underscore object underscore click. That would be a mouse click for an object, if you mark that and press F1 you will see that we have lots of different event types, for example, chart event click would also be a mouse click but this one is not for the button, so we use chart event object click here, so now we know that the object was clicked and we want to get the name for the clicked object and this is what we can get when we check the sparam. And if the sparam equals sell button, we know that we have clicked on the right button and that’s when we want to use the comment statement to output the name of the button followed by the text, was pressed and then we are going to use trade dot sell to sell ten micro lot. Let’s move the comment here, close the if statement 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 maybe you want to watch one of the other videos in this basic video series or maybe even the premium course on our website might be interesting
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 87 SIMPLE SELL BUTTON OBJECT appeared first on MQL5 Tutorial.
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. Now let’s close the if 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 videos in the basic video series or maybe even the premium course on our website might be interesting for you, this was once again a question from a premium course member and if you are already a premium course member and have some ideas for a video like this one just let me know. For now, we click on view, toolbar and press the compile button or you can also press F7 on your keyboard… I have messed up something… And that’s this bracket here, it caused all the following errors here. Now I have removed it and I recompile the code and this time it worked. And if this is the case you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader, please open an empty chart, now go to expert advisors and look for the new file, simple buy button, please make sure that you are on a demo account, we need to use a real chart here because it will not work in the strategy tester, so let’s drag it on the chart and click on okay. Now the buy button should appear on your chart,
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 86 SIMPLE BUY BUTTON OBJECT appeared first on MQL5 Tutorial.
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.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL – THE ONE THING YOU NEED FOR PROFITS appeared first on MQL5 Tutorial.
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 what all the code here does maybe you want to watch one of the other videos in this basic video series or maybe even the premium course on our website might be interesting for you.
This once again was a question that was asked by a premium course member and if you are already a premium course member and have a question like this one please let me know, for now, let’s enable the toolbar and now you can click on the compile button or press F7, I made a mistake, I’m using a variable here that wasn’t declared, so let’s fix that, it is going to be a string variable called signal and we don’t assign a value here. Now let’s recompile the code and this time it worked without any errors and if that is the case you can click on a little button here or press F4 to go back to Metatrader.
And in Metatrader please click on view, strategy tester or press control and r, please pick the new file, simple profit point test dot ex5, mark the option for the visual mode here and start a test but before you do that please click on the inputs tab and change the user-defined value to two hundred ninety-nine, now let’s start the test.
And here we are! Currently, we see that the user profit point value is two hundred and ninety-nine points, now you can speed up the whole process and get a result, I prefer to do it for at least one year and the next step would be to repeat the whole process and change the value and in this little video you have learned how to create a simple expert advisor to find the optimal user profit point value and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 85 SIMPLE TAKE PROFIT POINT TEST appeared first on MQL5 Tutorial.
In this video we are going to create an expert advisor that is able to move a sell trailing stop for the upper bollinger band, 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 bollinger bands sell trailing stop, 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 will give us some simple trading functions, it contains the class ctrade and we are going to create an instance of ctrade that will be called trade.
Inside of the ontick function, we want to create a static double variable, called last stop bollinger bands value. We are going to use it later to move our trailing stop and compare the current value with the last value. We also need to calculate 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 ask or symbol underscore bid and with normalize double and underscore digits we automatically calculate the right number of digits behind the dot depending on the currency pair that might be three digits or five digits.
And to move our sell trailing stop we need to have a test position so if positions total is less than one we use trade dot sell to sell ten micro lot and now I will set the last stop bollinger bands value to an unrealistic high value of one thousand, we also could set it to zero here but we would need to add another condition later on and for this simple example it is good enough.
Now let’s create an upper band array and a lower band array. Actually, we have a middle band but we don’t need it, so let’s use array set as series for the upper and the lower band to sort both arrays from the current candle downwards.
Now we can define the bollinger bands by using the included ibands function for the current symbol on the chart and the currently selected period on that chart, we want to calculate it for twenty candles, don’t use a shift value, the deviation value is two and we are going to calculate the results based on the close price.
With copy buffer we can now fill our array according to the bollinger bands definition that we have created here, we will do it for buffer one and buffer two. Buffer one is for the upper bend array, we start with candle zero and we want to copy the values for three candles and store them in the upper band array or in this case store them in the lower band array and that makes it possible to calculate the last upper band value and the last lower band value by just looking at candle one in the upper and in the lower band array.
Let’s continue with the conditions because if my last upper band value is above the ask price and if my last upper band value is below the last stop bollinger bands value that is when it’s time to check the bollinger sell trailing stop, we are passing the parameter my last upper bands value here and afterwards, we assign the last upper band value to the variable last stop bollinger bands value because the next time we call the function the current value will be the last one.
Now let’s continue with the user-defined function, we are using void because we don’t need a return value, the name is check bollinger sell trailing stop, this is the parameter that we have passed and now we use a for loop to go through all the open positions. Position get symbol will give us the currency pair for the current position.
Now we need to check if the current symbol on the chart is the same symbol as the position symbol and maybe we should close the ontick function here, so let’s continue with the position ticket, we will get that by using position get integer and the parameter is position underscore ticket. Let’s repeat that for the current stop loss! To get the current stop loss we use position get double and the parameter is position underscore sl and if the current stop loss is bigger than the my last upper bands value or if we have no stop loss at all – in that case, the current stop loss would be zero – that is when we want to use trade dot position modify for the current position ticket and set the stop loss to the my last upper band value, the take profit value will not be changed and please don’t forget this or condition here because when you don’t set a stop loss it can never be bigger than this value and if you forget to check this condition the stop loss will never be moved.
Now let’s close the loops here and close the function, and that’s it.
If you have no idea what all the code here does or this was too fast for you you might want to watch the other videos in this basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button or press F7 on your keyboard…
I messed up the parentheses, we have closed one if loop here but there is another one! So let’s fix that! Here we are! Let’s recompile the code and this time it worked without any errors and if that is the case you can click on a little button here or press F4 to go back to Metatrader.
And in Metatrader please click on view, strategy tester or press control and r, now let’s pick the file, simple bollinger bands sell trailing stop dot ex5, mark the option for the visual mode here and start a test.
Here we are! This is our sell trailing stop and its trailing, so our little expert advisor works as designed and in this little video you have learned how to create a sell trailing stop for the bollinger band indicator and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 84 SIMPLE BOLLINGER BANDS SELL TRAILING STOP appeared first on MQL5 Tutorial.
In this video we are going to create an expert advisor that is able to calculate a buy trailing stop for the bollinger bands indicator, 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 bollinger bands buy trailing stop, 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, this one comes with mql5 and it contains the class ctrade and we are going to create an instance from ctrade that is called trade.
Inside of the ontick function, we want to create a static double variable, called last stop bollinger bands value.
Afterwards, we want to calculate the ask price and the bid price by using symbol info double for the current symbol on the chart, we use symbol ask or symbol bid and we use normalize double and underscore digits to automatically calculate the right number of digits behind the dot.
For a trailing stop we need to have an open position, so let’s create a test position, whenever positions total is below one we use trade dot buy to buy ten micro lot and we set the value for the last stop bollinger bands value to zero.
Now let’s create an array for the upper band array and for the lower band array. Actually, the bollinger bands have three arrays for the upper, the middle, and the lower band but in this case, we only need the two extremes. Let’s use array set as series to sort both arrays from the current candle downwards.
Now we can define the bollinger bands by using the integrated ibands function for the current symbol on the chart and the currently selected period, we want to calculate the result for twenty candles, we use no shift value, the deviation value is two and we want to calculate the results based on the close price.
Now we use copy buffer to copy the data according to the bollinger bands definition that we have created here, we use buffer one for the upper bend array and buffer two for the lower band array starting from the current candle zero and we want to copy the values for three candles and store them in the array.
And now we can calculate the last candle by looking into candle one of our upper band array or our lower band array, this really depends on if you are looking for a buy or a sell trade.
For a buy trade, we want to check if the last lower band value was below the current bid price and we also want to know if the current value is above the last bollinger bands value, and if this is true we want to call a function called, check bollinger buy trailing stop and we pass the value my last lower band value.
Afterwards, we are going to assign the last lower band value to the last stop bollinger band value.
So far so good but this function doesn’t exist so far, so let’s create that now!
We are using void because we have no return value, the name of the function is check bollinger buy trailing stop and we pass the last lower band value here.
Now we use a for loop to go through all the open positions, with position get symbol for the current counter value we will get the position symbol and that makes it possible to check if the current symbol on the chart equals the position symbol, if that is true, we use position get integer, position underscore ticket to get the current position ticket number and with position get double for the current stop loss – the parameter is called position underscore sl – we get the current stop loss and only if the current stop loss is below the last lower band value we use trade dot position modify for the current position ticket to move the current stop loss to the last lower band value, this parameter is for the take profit and we will leave that one unchanged.
Finally, we want to close the if loop, 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 videos in the basic video series or maybe even the premium course on our website might be interesting for you, for now, let’s enable the toolbar here and click on compile or press F7, I have no errors here and if this is the case you can click on a little button here or press F4 to go back to Metatrader.
And in Metatrader you want to click on view, strategy tester or press control and r, please pick the new file, simple bollinger bands buy trailing stop dot ex5, mark the option for the visual mode here and start a test.
Here we are! We have a first position and a stop loss and when the lower bollinger band is rising, the stop loss is adjusted, so our little expert advisor works as designed and in this little video you have learned how to create a buy trailing stop for the lower bollinger band and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 83 SIMPLE BOLLINGER BANDS TRAILING STOP appeared first on MQL5 Tutorial.
In this video we are going to create an expat advisor for a simple moving average sell trailing stop, 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 sma sell trailing stop, 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, this one comes with mql5 and it provides trading functions, it also contains the class ctrade, so we are going to create an instance of that class called trade.
We start by creating a static variable for the last stop moving average value, now we want to calculate 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 ask or symbol bid and with normalize double and underscore digits we make sure that we calculate the right number of digits behind the dot.
To use a stop loss we need to open a test position, we are going to use trade dot sell to do that and the condition is whenever positions total is below one – that means we have no open positions – and that’s when we want to sell ten micro lot.
We also want to set the last stop moving average value to a very high value, actually, you could also set it to zero but you would need to add another condition because usually, we are going to check if the current value is lower than the last stop moving average value and that one will never be below zero so let’s go with the high value for now.
In the next step, we are going to create an array for the moving average. With array set as series, we are going to sort the array from the current candle downwards and now we can use the integrated ima function for the current symbol on the chart and the currently selected period on that chart to create a simple moving average for five hundred candles, we don’t use a shift value here, we are going to use mode underscore sma as it stands for simple moving average and we want to calculate the results based on the close price.
Let’s continue with copy buffer, this one is used to fill the array according to the moving average definition that we have created here, we will grab the values for buffer zero that’s the moving average signal line here, we will start with candle zero – that’s the current candle – and we will copy the values for three candles and store them in the array. And now that we have done that we can calculate the stop moving average value by looking into candle one of our moving average array.
The first condition we want to check to move a sell stop loss is if the current stop moving average array is above the ask price otherwise we would not be able to change it.
We also want to know if the current stop moving average value is below the last stop moving average value, and if this is true we are going to use a function called check sma sell trailing stop and pass the bid price and the stop moving average value as a parameter. This function doesn’t exist so far, so we need to create it now and please don’t forget to set the last stop moving average value and assign the current stop moving average value because the current one will be the last one the next time we call this function.
Our trailing stop function will use void because we don’t need to return anything, the name is check sma sell trailing stop and we pass the bid price and the stop moving average value as parameters here.
Now we use a for loop to go through all the open positions, we will count down until there are no other positions left, afterwards we use position get symbol for the current counter of the for loop to get the currency pair symbol for the current position and only if the symbol on the chart matches the currency pair symbol we are going to continue. With position get integer and parameter position underscore ticket, we can now get the current position ticket and to find out the current stop loss we are using position get double and pass the parameter position underscore sl that will allow us to check if the current stop loss is above the stop moving average value and we also need to find out if the current stop loss equals zero, this is the case when you don’t set a stop loss when you open a position, so we also need to check this one and afterwards, we use trade position modify for the current position ticket to set the desired stop moving average value, the last parameter here is for the take profit, we won’t change that one.
Finally, we need to close the if loop, 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 maybe you want to watch one of the other videos in this basic video series first or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button, I need to set the toolbar to visible, here is the compile button and you could also press F7 on your keyboard, I don’t have any errors and if that is the case you can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader we want to click on view, strategy tester or press control and r, please pick the new file, simple sma sell trailing stop dot ex5, mark the option for the visual mode here and start a test.
Here is the first position, we need to zoom into the chart to see if the sell trailing stop works, this is the simple moving average and we see that it is actually creating a trailing stop for our sell position, so our little expert advisor works as expected and in this little video you have learned how to create an expert advisor that is able to create a trailing stop for a simple moving average and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 82 SIMPLE SMA SELL TRAILING STOP appeared first on MQL5 Tutorial.
In this video, we are going to create an expert advisor that is able to create a a simple buy trailing stop that is based on a simple moving average value, 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 sma buy trailing stop, 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, this one comes with mql5 and provides simplified trading functions afterwards we create an instance of the class ctrade and call it trade.
Inside of the ontick function we start with a static double variable called last stop moving average value, we continue by calculating the ask price and the bid price that can be done by using normalize double, symbol info double for the current symbol on the chart and the second parameter is symbol underscore ask or underscore bid, with normalize double and underscore digits we make sure to calculate the right number of digits behind the dot.
To have something that we can use for the trailing stop we need to open a test position, so whenever positions total is smaller than one or in other words when we have no open position we use trade dot buy to buy ten micro lot. That will open a new position and that’s when we set the last stop moving average value to zero because for each position we need a new value.
Let’s go on and create an array for the moving average, now we want to sort the array from the current candle downwards that is done by using array set as series for our moving average array that we have created here.
Now let’s define the properties, we want to use the ima function for the current symbol on the chart and the currently selected period on that chart, we want to use it for five hundred candles starting from the current candle zero, we don’t use a shift value and we use mode underscore sma because this stands for simple moving average and the calculation should be done based on the close price.
Afterwards, we use copy buffer to fill our moving average array according to the definition that we have created here for buffer zero, we start with candle zero – that’s the current candle – and we copy the values for three candles and store them in the array.
And to get the value that we need we simply have a look at the value for candle one in our moving average array and we assign the value to stop moving average value.
Now that we have done that we can check if the stop moving average value is below the current bid price and the second condition will be if the stop moving average value is bigger than the last stop moving average value and if that is the case we want to call a function that is called check sma buy trailing stop, we will pass the ask price and the stop moving average array value as parameters here and afterwards we want to assign the current value for the next function call, so we store the value for stop moving average value in the variable called last stop moving average value. Please remember this was a static variable so it will keep the values inside of this function, well this function doesn’t exist so far, so we need to create it now, the name of the function will be check sma buy trailing stop, we use void because we don’t use a return value here and we pass the ask price and the stop moving average value as parameters.
Now let’s use a for loop to go through all the open positions, we use position get symbol to get the symbol for the current position because we need to check if the current symbol on the chart is equal to the position symbol and if this is true we get the position ticket by using the function position get integer position underscore ticket.
To get the current stop loss we use position get double and the parameter is position underscore sl and if the current stop loss is below the stop moving average value we want to change it that is done by using trade position modify for the current position ticket and we pass the stop moving average value as the second parameter. The third parameter would be used when we would like to change the take profit value but this is not the case.
Finally, please close all the loops and also close the function that we have created and this is it.
Well, 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 videos in this basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button here or press F7 on your keyboard, you shouldn’t get any errors and if this is the case you can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader we click on view, strategy tester or press control and r, please pick the new file, simple sma buy trailing stop dot ex5, mark the option for the visual mode and start a test.
Here we are! We need to zoom into the chart because that’s when we see that the moving average is far below the current price, we also see that the stop loss is modified, if you click on the journal tab you will see that it will not be modified each time, you could change all the conditions to avoid the errors but for this simple example it is good enough and in this little video you have learned how to create an expert advisor that is able to create a buy trailing stop that is based on a simple moving average and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 81 SIMPLE SMA BUY TRAILING STOP appeared first on MQL5 Tutorial.
In this video, we are going to create an expert advisor that can calculate the highest and the lowest spread for a certain number of candles in a currency pair, so let’s find out how to do that with mql5.
To get started please click on the 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 spread checker, 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 input value for the candles to count, in my case I want to use five candles and find the highest and the lowest spread for those five candles, this input modifier here will allow us to change the value without recompilation by changing the expert properties.
Inside of the ontick function we start with a double variable called lowest spread value and in this case, I’m going to set the initial value to one hundred thousand, this is definitely not the lowest spread value that you will see but we are going to calculate that later.
Let’s create another variable, this time for the highest spread value, I will set the initial value to zero and this is also not the highest spread value that you will see.
Afterwards, we use mql rates to create an array for price information.
Mql rates stores the information about prices, volumes and spread and spread is what is interesting for us. Afterwards, we use array set as series to sort the array from the current candle downwards and now we fill the price array with data by using copy rates, in my case for the current symbol on the chart and the currently selected period on that chart, I’m going to start with the current candle zero and I will copy the data for two hundred candles and store it in the price information array.
Now we can use a for loop to go through all the candles that are interesting, the current candle number will be the number of candles to count that we have defined here, in our case five and for as long as the current candle number is bigger or equal to zero we will go through the for loop and count down the number of candles until this condition is no longer true, and to get the current candle spread we look inside of the price information array for the current candle number and we want to know the spread, so we use dot spread.
To make it easy to check if the values are correct we want to add a print statement that will output the current value for the candle, the candle number we are processing right now and the current candle spread in our journal and if the current candle spread is lower than the lowest spread value, we want to save it as the lowest spread value.
In the other case if the current candle spread is higher than the highest spread value that’s when we want to save the current candle spread as highest spread value.
Finally, we want to create a chart output by using the comment statement, this will show us the lowest and the highest spread on the chart and finally, we want to end the for loop and close the ontick function. 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 videos in this basic video series or maybe even the premium course on our website might be interesting for you, this was another question from a premium course member and if you are already a premium course member and have an idea for a video like this one please send me an email.
So far so good! Please click on the compile button or press F7 on your keyboard, I don’t have any errors and if this is the case you can click on a little button here or press F4 to go back to Metatrader.
And in Metatrader we want to click on view, strategy tester or press ctrl and r, please pick the new file, simple spread checker dot ex5, mark the option for the visual mode and start your test.
And here we are! We see that the spreads are changing, I have chosen a currency pair with a very high spread value and you see that it’s changing all the time, let’s actually stop, click on the inputs tab and this time I would like to do it for four candles, now restart the test with the new settings, let’s lower the speed here, it says that the highest value was one thousand three hundred and sixty, this is true for candle two and the lowest spread value was one thousand three hundred and twenty, this is true for candle four, so it looks like our expert advisor is working as expected and in this little video you have learned how to create an expert advisor that is able to calculate the highest and the lowest spread for a certain number of candles and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 80 SIMPLE SPREAD CHECKER appeared first on MQL5 Tutorial.
In this video, we are going to create an expert advisor that is able to change the colors for several objects 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 the F4 key 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 color changer, click on continue, continue and finish.
Now you can delete everything above the ontick function and the two comment lines here.
We start by creating an array, we will use mql rates to get the price information because mql rates is a structure that stores the information about price, volumes and spread.
Afterwards, we use array set as series to sort our price information array from the current candle downwards and with copy data, we can fill our price information array with data for the current symbol on the chart, we are going to use the currently selected period on that chart and we will copy the data starting from candle zero for three candles and store it in our price information array.
Now that we have done this we are able to calculate the close price for candle one that is done by looking into the value for candle one in the price information array. We are interested in the close price, so if you cut that out and press the period button on your keyboard you will see that you can get close, high, low or open prices, we will go with the close price. Afterwards, we do the same for the close price of candle two. Everything else is similar but this time we are going to look for the close price of candle two in our price information array and if the close price for candle two is below the close price of candle one we want to change the colors on the chart that is done by using chartsetinteger. You probably would expect something like chartsetcolor, so this is a little strange. We will do that for the current chart and the property we are going to use change first is chart color candle bull, I will set it to green, so I use clr green here and if you mark that and press F1 you will see that we can use a lot of different predefined colors here and this will change the body color for the bull candles.
Let’s do the same thing here for the bear candles. Everything is pretty much the same except for the property that we are going to change, this time is chart color candle bear and now we use chartsetinteger to change the property for chart color chart up. This is for the outer color of the bull candles and I’ll also change this one to green and repeat the whole thing and do it for the bear candles by using chart color chart down.
The next one is for the chart mode and here we can pick one of three values. Chart mode will change the type, we can have candlesticks, bars or line chart, we can pick one of these values and I decided to go with a bar chart. I want to have a grid on the chart, so I use chartsetinteger to set the property for chart show grid to true.
Let’s change the foreground color for the data by using chart color foreground and I will set it to yellow here and finally, I would like to set the background color, so I use chart color background and set it to black.
In the other case when the close price for candle two is above the close price for candle one I would like to see other colors. This is basically the same stuff so I will use copy and paste here, this time we will see the color red for the candles, that’s also what I use for the chart mode, I would like to see candles on the chart, I don’t want to see the grid, so I set the property to false.
The chart color foreground should be magenta and the chart color background should be white. But you can not only set values for the chart properties it’s also possible to read values.
In our case we will read the max price and the min price, that is done by using chart get double for the current chart and the properties are chart price max and chart price min.
Finally, we want to add a comment statement to get an output on the chart that will show us the close price for candle one and candle two, the max price and the min price 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 maybe you want to watch one of the other videos in this basic video series first or maybe even the premium course on our website might be interesting for you.
This was another suggestion that was made by a premium course member and if you are already a premium course member and have an idea for a video like this one please send me an email.
For now, please click on the compile button or press F7 on your keyboard, you shouldn’t get any errors here and if this is the case you can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader, we want to click on view, strategy tester. Please pick the file, simple color changer dot ex5 here, enable the visual mode and start a test.
Here we are! Based on the current prices we see that the chart colors are changing, so our little expert advisor works as designed and in this little video you have learned how to create an expert advisor in mql5 that is able to change the chart colors for different objects based on the current price and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 79 SIMPLE COLOR CHANGER appeared first on MQL5 Tutorial.
In this video, we are going to create an expert advisor that is able to allow or forbid trading based on the current spread, 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 spread filter, 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 comes with mql5 and it provides simplified trading functions. Afterwards, we use the class ctrade to create an instance called trade and we are going to use that one later to open new positions.
And we would like to create a user-defined input variable for the max allowed spread, that value can be changed later on without recompiling the code.
Inside of the on tick function we want to calculate 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 ask or symbol bid based on what we want to calculate and with normalize double and underscore digits we make sure that we calculate the right number of digits behind the dot.
For the trading entry, we want to create a string variable, this one is called signal but we don’t assign a value here because we are going to calculate that later on. We need some price data therefore we use mql rates to create a price array.
With array set as series, we are going to sort our price array from the current candle downwards and afterwards, we use copy rates to fill our price array with data for the current symbol on the chart and the currently selected period, we start with candle zero and we want to copy the values for three candles.
Now let’s calculate the current spread, this is done by using symbol info integer for the current symbol on the chart and we use symbol underscore spread to calculate the current spread.
Let’s create another string variable called spread filter, this is going to be used for our filter and if the current spread is bigger or equal the max spread that we have allowed the spread filter will get the value, trading is not allowed because the spread is too high.
Otherwise, if the current spread is below or equal to the max value that we have allowed that’s when we assign the value, trading is allowed to our spread filter.
Now let’s create some simple entry conditions, in this case, I’ll check if the close price for candle one is bigger than the close price for candle two, in that case, I want to buy so we assign the value buy to our signal. Otherwise, if the close price for candle one is below the close price for candle two that’s when we want to sell so now we assign the word sell to our signal but before we allow any positions we make it a precondition that the spread filter has the value, trading is allowed and only if that is the case we check the entry conditions. If the signal equals sell and positions total returns the value below one that would mean we have no open positions but a sell signal and that’s when we use trade dot sell to sell ten micro lot. In the other case if the signal equals buy and we have no open positions that’s when we use trade dot buy to buy ten micro lot but we only do that if the spread filter equals trading is allowed.
Finally, we want to use the comment statement to create an output for the current spread, the max spread that we have allowed and the spread filter. 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 videos in this basic video series or maybe even the premium course on our website might be interesting for you. Actually, this was a suggestion from another 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 F7 on your keyboard, you shouldn’t get any errors and if this is the case you can click on a little button here or press F4 to go back to Metatrader.
And in Metatrader we want to click on view, strategy tester or press control and r, please pick the new file, simple spread filter dot ex5, mark the visual mode option here and state your test.
Here we are! The expert advisor is saying that trading is not allowed so let’s fast-forward that and here is the first trade, the value here changed for a second also, let’s stop the test, click on inputs and now we change the value to ten and restart the test and we shouldn’t see any trades until the current spread is below ten. This is the case so our little expert advisor is working as expected and in this little video you have learned how to create an expert advisor that is able to allow or forbid trading based on the current spread and the max value that you have defined and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 73 SIMPLE SPREAD FILTER appeared first on MQL5 Tutorial.
In this video we are going to code an expert advisor for this triple exponential moving average, so let’s find out how to do that with mql5.
To get started 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 triple ema, 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 comes with mql5 and now we use the class ctrade and create an instance called trade that we are going to use later on to open positions.
We want to calculate the ask price for buy positions that is done by using symbol info double for the current symbol on the chart, we use symbol underscore ask and with normalize double and underscore digits we automatically calculate the right number of digits behind the dot.
Let’s repeat that for the bid price. Everything is identical except for the variable name and this time we are going to use symbol underscore bid as the second parameter.
Afterwards, we use the function mql rates to create an array called price info and with array set as series, we are going to sort the array downwards from the current candle and finally, we can use copy rates to fill the array for the current symbol on the chart and the currently selected period on that chart. We start with candle zero – that’s the current candle – and copy the price data for three candles to store it inside of our price info array.
Let’s create a string variable called signal for our signal but we are not going to assign any value here because this is what we want to calculate now, therefore we create three arrays for each of the exponential moving average values.
This one is for ten candles, the second one is for fifty candles and the third one is for one hundred candles. The integrated ima function that comes with mql5 can be used to create an exponential moving average for the current symbol on the chart, we use underscore period to calculate it for the current period. In this example I have done it for ten candles, we don’t use a shift value here and we want to create an exponential moving average, therefore we use mode underscore ema and the result should be calculated based on the close price.
Now let’s repeat the whole thing for the other two exponential moving averages.
Everything is identical except for the name for the variable and the number of candles. This is the last one for one hundred candles. Those arrays also need to be sorted from the current candle downwards so let’s repeat that for all the three arrays and as you might have guessed we use copy buffer to fill each array with data according to the definition that we have created. We do that for buffer zero – that’s the signal line – starting from candle zero and in this case, we do it for ten candles. Please make sure that you use different names for the ema and for the ema arrays here.
And now we can calculate if we have a buy signal and that would be the case if the exponential moving average for ten candles is bigger than the one for fifty candles and if the exponential moving average array for fifty candles is bigger than the one for one hundred candles if that is the case we have a buy signal and that’s when we want to assign the word buy to our signal.
In the other case, if we have a moving average for ten candles that is below the one for fifty candles and if the one for fifty candles is also below the one for one hundred candles, that’s when we want to sell, so now we assign the word sell to our signal and if our signal equals sell and the return value for positions total is below one – that would mean we have no open positions but a sell signal and that’s when we use trade dot sell to sell ten micro lot.
In the other case, if the signal equals buy and we also have no open positions that’s when we use trade dot buy and buy ten micro lot.
Finally, we use the comment statement to create an output on our chart. We want to see the current signal is followed by the calculated signal.
Okay, 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 videos in this basic video series or maybe even the premium course on our website might be interesting for you.
For now, please click on the compile button or press F7, you shouldn’t get any errors and if this is the case you can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader we click on view, strategy tester or press control and r, please pick the new file simple triple ema dot ex5, mark the option for the visual mode here and start a test.
Here we are! The expert advisor is running, this is our first position and we see a sell signal on the chart, now we have a crossover and in a few seconds we should get a buy signal, that happened now so our expert advisor is working as expected and in this little video you have learned how to create an expert advisor for triple exponential moving average and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 72 SIMPLE TRIPPLE EMA appeared first on MQL5 Tutorial.
In this video we are going to draw symbols on our chart, you see that we have different symbols appearing here, so let’s find out how to do that with mql5.
To get started please click on a little symbol 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 arrow symbols, 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 calculate the ask price this is done by using symbol info double for the current symbol on the chart, we use symbol underscore ask and with normalize double and underscore digits we calculate the right number of digits behind dot.
Let’s also repeat that for the bid price, it’s almost the same except for the variable name and we are going to use symbol underscore bid in this. I would like to place the object in the middle so let’s calculate that one. We get the medium price when we add up the two values and divide them by two.
Now let’s use the random generator to draw random symbols for the initialization I use mathsrand and gettickcount, when you mark mathsrand and press F1 you will see that it is generating a series of pseudorandom integer values and when we use gettickcount we get the number of milliseconds since we started the system so in this combination we will get a unique value and we will use that value to now use mathrand that will return another integer value, in our case, we will calculate a number within that range and to draw our symbol we now use object create for the current currency pair on the chart, this is the name of the object, it’s called my object and I would like to have an arrow so I use the object type obj underscore arrow here, now let’s press F1 and you will see that arrows are just one of many available types but we can have several shapes, the next parameter is used to define if the arrow should be drawn in the upper or the lower window. This would be window zero but if you use oscillators you could have a second window below the candles, we don’t need that.
Time current is used for the last known server time, in our case, the object will be drawn here because that’s the current time and the anchor point for the object should be the medium price, so let’s set the value on the main chart for the object with the name my object, I would like to set the value for the object property arrowcode and that is where we use the random arrow code that we have generated here.
Objectsetinteger is a way to set several values, for example, I can also set the object property width, in my case I would like to use the value twenty for bigger objects and each time when the tick comes in I would like to use objectmove to move our existing object to the current point in time.
Finally, let’s create a chart output for the ask price, the bid price, the medium price and that’s about it.
Well, if you don’t understand what all the code here does or if this was too fast for you maybe you want to watch one of the other videos in this basic video series or maybe even the premium course on our website might be interesting for you. If you are a premium course member and have ideas for a video like this one please let me know.
This was a suggestion that I have received this week, for now, please click on the compile button or press F7 and if we don’t have any errors here we can click on the little button here or F4 to go back to Metatrader.
Inside of Metatrader please click on view, strategy tester or press control and r. Here we want to pick the new file, simple arrow symbols dot ex5, please also mark the option for the visual mode here and start a test.
Here we are! You can see that we have different symbols each time, not every return value will have a valid symbol code but in this video, you have learned how to create an expert advisor that is able to draw symbols directly on the chart and you have coded it yourself with a few lines of mql5 code.
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 71 SIMPLE ARROW SYMBOLS appeared first on MQL5 Tutorial.
In this video we are going to create an expert advisor for the Bill Williams Market Facilitation indicator, that’s the oscillator here, 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 ea, 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 because it contains the class ctrade and we create an instance called trade that we are going to use to open and close positions.
Inside of the ontick function, we start by creating a variable called signal. This is a string variable but we don’t assign a value so far because we are going to calculate that later.
First, we need to calculate the ask price that is done by using symbol info double for the current symbol on the chart, we use symbol underscore ask – all in capital letters – and with normalize double and underscore digits we calculate the number of digits behind the dot.
Let’s repeat that for the bid price, it’s almost the same except for the variable name and of course this time we are going to use symbol underscore bid.
Afterwards, we create an array for the Bill Williams Market Facilitation Index and now we use array set as series to sort the array from the current candle downwards.
So far so good! The bwmfi can be calculated with an included function. We need to pass a few parameters, the first one is for the current symbol on the chart, the second one is for the selected period on that chart and the third one is for the volume, we have two values that we can use, either volume tick for the tick volume or volume real for the real trade volume.
In our case, we will use the tick volume and now we use copy buffer to fill our according to the definition that we have created here. We do that for buffer zero starting from the current candle zero and we will fill the array with three candles and store the results in our array.
Now we can calculate the current value by looking into candle zero in our array. We use normalize double and the value five because the original oscillator also shows five digits behind the dot.
Now let’s repeat that for the value for candle one because that will make it possible for us to compare if we have a higher or a lower value and if the current bwmfi value is bigger than the last bwmfi value we consider that to be a buy signal so we assign buy to our signal.
Otherwise, if current bwmfi value is below the last value we consider that to be a sell signal so now we assign the word sell to our signal.
And if the signal equals sell and the function positions total delivers a return value from below one – that would mean that we have no open orders – and in that case, we use trade dot sell to sell ten micro lot.
Otherwise, if the signal equals buy and positions total is below one we would use trade dot buy and buy ten micro lot.
Finally, we create an output on the chart, we use the comment statement to output the text, the signal is now followed by the calculated signal.
Okay, so far so good!
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 videos in the basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button or press F7, you shouldn’t get any errors and if that is the case you can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader, we click on view, strategy tester or press control and r, please pick the new file, simple bwmfi ea dot ex5, mark the option for the visual mode here and start a test.
And here we see our first trade, the expert advisor is producing buy and sell signals.
Well, usually you would use an oscillator in combination with a trend indicator but in this little video you have learned how to create an expert advisor that is able to calculate buy and sell signals for the bwmfi oscillator and you
Not sure what to do? Click on the automated trading assistant below
The post MQL5 TUTORIAL BASICS – 70 SIMPLE BWMFI OSCILLATOR appeared first on MQL5 Tutorial.