MQL4TUTORIAL.COM

MQL4TUTORIAL.COM

By MQL4TUTORIAL.COMBusinessInvesting
Download on the App Store

MQL4TUTORIAL.COM episodes

  • MQL4 TUTORIAL ENGLISH – SETUP YOUR OWN ADVANCED STATISTICS
    The topic of this video is putting statistics on the Internet. I said a while ago that in a short time I would be offering a four-digit platinum group membership with a brand new trading system. Now, this is one of the early versions, and this is the account number for a Robo Forex Pro account. And FXBlue.Com is now one of my new habits. Because I couldn’t publish the account statistics reliably with MyFxBook on a Linux machine. Because this MetaTrader runs on a device that runs Linux, and I’ve now made my own trading distribution based on Debian. In fact, I was also able to install FX Blue’s Expert Advisor in MetaTrader on the Linux machine.   Everything works here with Play on Linux, and the Expert Advisor is red right now because it is the weekend and there are no new trading signals. But as you can see, the last change was made at 10:26. You can also see the account information. Here, Fx Blue can do different things. One can monitor specific basic values. A chart can be used to show the whole thing. On the Euro-Dollar chart, we have made 279 trades so far. With a profit of 204.11 dollars in total. The total net comes to $89.16. It’s interesting that we have 230 buy trades and 49 sell trades, even though the Euro/Dollar reached its lowest level since the turn of the century just this week.   Here, you can look at all of these details in more depth if you want to. I think the way it’s set up is good. The whole thing is repeated here as a print statement, or you can download it in Excel format. I can’t install Excel on my Linux computer here because it’s a so-called Stick PC. It uses only two gigabytes of memory and runs in the background. It is more than powerful enough to run our Expert Advisor, and we don’t have to worry about Windows updates being installed in the middle of the night, which could cause the computer to restart. So, if you’ve had trouble setting up the advanced statistics of MyFxBook on a Linux PC in the past, you can do it through this live tab map on the FXBlue.Com website.   This is easy to do with MetaTrader 4 and MetaTrader 5, and in the future you will be able to collect such advanced statistics for your own account here. This will help you get better results over time. So far, that’s all for today. Thank you for watching! See you in the next video.
    3 min
  • MQL4 TUTORIAL ENGLISH – POSSIBLE OR PROBABLE?
    Today’s topic is possibilities and probabilities. Because I’ve received another request from a course member. And the question was whether a specific profit expectation could be implemented in practice. My response was that it depends on a variety of factors, one of which is probability. Roy Sullivan is my favorite example on this subject. Roy Sullivan was a park ranger in the United States who was struck by lightning seven times. The chances of something like that happening are minuscule. Nonetheless, for Roy Sullivan, it has become a complete reality. That means that even if the likelihood is extremely low, the consequences could be disastrous. For example, one could consider the statistics for plane crashes and argue that flying is the safest mode of transportation. However, there are always reports of plane crashes, and for those affected by the situation on the plane, it is a nightmare. So the goal of trading is to find something that brings both of those things together in the best way possible.   That means we need to find something that is feasible and has a reasonable chance of producing positive results. Fortunately, in automated trading, this can be determined through a rigorous series of tests. What’s going on in the video’s background is what I spend the majority of my time doing. In reality, programming an automated trading system does not take long. The majority of the time is spent on extensive testing. And the goal is always the same: to increase the likelihood of a good outcome as much as possible while keeping the system as stable as possible. Of course, with the results of this video, many people will argue that the profit expectation is too low and that such a system could yield much more. However, I can argue that I have only been intensively testing this system for three months. That means I’ve already completed numerous 100-test series like this one. I’m doing it right now on three different computers using three different account types. And it’s always about making the system a little bit more stable, rather than extracting a few more dollars in profit expectations.   In fact, with what you see on the screen here, I can trade in different currency pairs from the turn of the millennium to the present day without the system failing. And the goal here is to create a system that is stable enough to ensure stable operations over long periods of time. Beginners are frequently looking for a quick buck. However, professionals such as Ray Dalio understand that the key is to find something that works in the long run and is based on fundamental laws. If you have the time and inclination, you should look into Ray Dalio’s book Principles. It taught me a lot of things. When this system is ready, an exclusive offer will be made to some existing customers who meet the necessary criteria to trade such a system profitably. However, because consulting is included, the cost will be in the four-digit range. However, it will undoubtedly take several months before all of this is ready to go. If this sounds interesting to you, you can pre-register.   I simply wanted to demonstrate what is not only possible, but also likely in this video. Because once you’ve ensured the most stable operation possible, it’s easy to keep optimizing a working system in the long run. That’s all for now. Thank you for watching, and I hope to see you in the next video.
    4 min
  • MQL4 TUTORIAL BASICS – 132 STANDALONE BOLLINGER BANDS RSI EXPERT ADVISOR
    In this video we are going to create an expert advisor that uses the bollinger bands to create a signal. And we also want to use the RSI filter to confirm the signal.   So let’s find out how to do that with MQL4.   To get started, please click on a little button here or press F4 on your keyboard.   Now you should see the Metaeditor.   And here we have a precoded version for this expert advisor. We start by using the Include function.   It will include two modules for the bollinger bands and the RSI that are coded here.   Inside of the ontick function we open a function that is called Check Entry Bollinger to create a trading signal.   And for the filter we open a function that is called Check Entry RSI.   This one is coded in the second module and only if the trading signal equals buy and if the filter also equals buy, we want to check if we have no open positions.   That would be the case when orders total delivers a return value of zero. And if all conditions are true, we use order send for the current symbol on the chart to open a buy trade for ten microlot.   In the other case, if the trading signal equals sell and if the filter also equals sell and we have no open positions, that’s when we want to use order send for the current symbol on the chart to create a sell trade for ten microlot.   At the end of the main module we use the comment statement to output the trading signal for the bollinger bands and the filter signal for the RSI filter.   And that’s it for the main module.   But these two functions here need to be created. So let’s continue with the bollinger bands entry. Our function is called Check Entry Bollinger.   And it will return a string value.   Therefore we create a string variable for the signal.   We don’t assign a value here because we are going to calculate that now. And to do that we need to use the ibands function that comes with MQL4 for the current symbol on the chart and the currently selected period on that chart.   We do it for 20 candles.   The standard deviation is two.   We don’t need a shift value here.   We calculate the results based on the close price. We use mode lower for the lower bollinger band or mode upper for the upper bollinger band. And here we have the candle number one. Now let’s repeat that for the last bollinger bands value.   And here we want to do the whole thing again.   This time we do it for candle two. And when the close price for candle two is below the last lower bollinger band and the close price for candle one is now above the lower bollinger band, that would mean we have a re-entry from outside the bollinger bands from below and that is considered to be a buy signal.   So we assign the word Buy to our signal.   In the other case, if the close price for candle two was above the last upper bollinger band, and if the close price for candle one is now below the upper bollinger band, that would be a sell signal.   And that’s when we assign the word sell to our signal.   Finally, we return our signal to the main module by using the return statement here.   That’s it for the signal.   Now let’s continue with the filter. To get the filter value we use the function checkentry RSI. That is coded in this module. It also returns a string value.   Once again we create a signal variable of the type string.   Now we use Irsi for the current symbol on the chart and the currently selected period on that chart. We calculate the value for 14 candles for the close price and we do it for the current candle.   That’s candle zero.   And if the RSI value is below 30, that would mean we have a buy signal.   And that’s when we assign the word buy to our signal.   In the other case, if the RSI value is above 70, that could be a sell signal.   And that’s when we assign the word sell to our signal.   Finally, we return the signal to our main module by using the return statement.   And now you need to save the include modules and compile the main module.
    9 min
  • MQL4 TUTORIAL – 131 STANDALONE EMA MACD EXPERT ADVISOR
    In this video we are going to create an expert advisor that is able to use two exponential moving averages to create a Buy or a Sell signal. And we are going to use the MACD as a filter. So let’s find out how to do that with MQL4. 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 we have the precoded solution. In my case, I’m doing an include function for the Exponential Moving Average Crossover module and for the MACD module.   Both are separate files and the include function can import the content of those files. And they will be compiled when you compile the main module, which is the one with the Ontick function. And here we create a string variable for the trading signal and another string variable for the filter. And to get the trading signal we are opening a function that is called CheckEntry EMA. And to create a filter signal we open a function that is called Check Entry MACD. And when we have a Buy signal and the filter for the MACD also says that we should buy and if the return value for Orders total equals zero, that would mean all conditions are good for a Buy signal.   And that’s when we use Order Send to open a Buy Trade for ten microlot. Otherwise, when the trading signal equals Sell and when the filter also equals Sell and we have no open positions, that’s when we use Order Send to open a Sell Trade for 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 continue with the trading signal. Here we have a separate module. It’s an MQ4 file in the same directory and the function we use is called Check Entry EMA. Inside of the function, we first need to create a string variable for the signal, but we don’t assign a value here. Now we need to create four exponential moving averages. The first one is for 20 candles for the current candle.   The second one is for 50 candles also for the current candle, we also want to calculate the values for the old moving average for 20 candles. That’s for candle one, and we want to calculate the value for 50 candles for the last candle. That’s what we do here. The number of candles is defined here. If you don’t know what all that here means, you maybe want to watch one of the other videos in our basic video series, or maybe even the premium course might be interesting for you. You can find that one on our website. And if the moving average for 20 candles for the current candle is above the moving average for 50 candles, and if it was below for the candle before, that’s when we have a Buy signal and that’s when we assign the word buy to our signal. Otherwise, if the moving average for 20 candles is below the moving average value for 50 candles and if it was above for the candle before, that’s when we have a sell signal. And now we assign the word sell to our signal. Finally, we use the return statement to return the signal to our main module. That’s it for the signal. Now let’s do the same for the filter.   We want to open a function that is called checkentry MACD. This is the function and inside of the function we create a signal, also a string variable. And the MACD actually has two signals. One is the main signal and the other one is called signal. You can see that when you open the MACD window. We have a red line in this grey area here. To output the values we use the print statement for the main value and for the signal value for the MACD. And if the MACD main is above the MACD signal value, that would be a buy signal for us. In the other case, if the MACD main is below the MACD signal that would mean we have a sell signal.   And finally, we want to return the signal to our main module here. So this is it. Once you have all three modules in place you can click on the compile button. Here we are. And if you don’t have any errors you can click on the little button here or press the F4 button ...
    7 min
  • MQL4 TUTORIAL BASICS – 130 WHY MASSTESTING IS A GAME CHANGER
    In this video, I would like to show you something that I think is very helpful. And right now you see that I’m doing backtests in MetaTrader 5. Because MetaTrader 5 is able to to do that. And it’s very fast because MetaTrader 5 does support multicore processing. Each of my CPU cores can now do 25 tasks, as I am right now doing 101 complete backtests. And when you watch the results here, you will see that we have profits, and each of those tests has a different amount of total trades and a different expected payoff and a different result.   And that’s because I’m doing it with random entries. Now you might ask yourself, why should anybody use a random entry to do tests? Well, actually, this is a good way to find out if your system works, because not the entry is the most important component. It’s rather how you react. And it doesn’t make sense to make decisions based on a handful of open positions.   So you can see in each of these 101 test series, I have about 3000 total trades. I’m running the test for a whole year. I do it often and this one gave us good results. This is the one that I did before. Those results are also okay as we have no losses.   But there are times when you will see spikes like this one. This is a drawdown in the middle of the year. And as I said, in the beginning, you have to define the time span. In my case, it starts on the 1st of January and it ends at the last day of the year. And this drawdown is right in the middle of the year.   So the system has time to recover. But what do you think would happen if I said that the backtest should end on September 16th? Well, I think you would be less satisfied with the results because that would have been a loss. And this is where people actually give up. Because when you see something like this happen on a real account, you will be convinced that all that trading stuff doesn’t work, and you will be sure that the system will never recover again.   And those back tests here, actually, yes, they take time, but they don’t take much work. The only thing I do is to pick the next currency pair here. Click on Start. Now I see that the four cores are going to work. Here is the status, and now we see the first results.   Each green point here represents a profit, but it doesn’t mean that it needs to always be a profit, just with a few changes in the system. For example, here in the risk percentage value, I could easily modify the system in a way that it only produces losses. And that’s why I think that the best idea to invest time is to do mass testing like I do with this system. Metatrader 5 is able to automatically import all the historical data that is needed for a test. And by now we have made 86 out of 101 tests so far. It looks good for this currency pair.   Now this test series is finished. This time we have about two and a half thousand trades for each test. The drawdown looks very good. That isn’t always the case. And if you think that 24% is too high, you might want to adjust the settings for your own needs. It really depends on your risk tolerance and your account type.   My account type is good for up to 70% drawdowns as my broker has low margin requirements. Let’s do another one. I have not modified any settings but you really need to find out if the currency pairs you trade will work and I go with the ones that produce good results and I leave out the ones that produce bad results. I always do backtests for at least one year. And when I’m done with all the currency pairs that I trade I will start right over with the year 2020, do 101 tests for each of these currency pairs. And afterwards I will do the same thing for 2019! And that’s how you can do hundreds and hundreds of tests on a single rainy afternoon if you use meter MetaTrader 5. I have to admit I wasn’t willing to change from MetaTrader 4 to meter MetaTrader 5 for a long time. But this mass testing ability and the fact that historical data is imported automatically really saves a lot of time.
    7 min
  • MQL4 TUTORIAL BASICS – 129 SIMPLE BOLLINGER BANDS EXPERT ADVISOR
    In this video we want to create an automated Expert Advisor that is actually able to trade this Indicator; it’s the Bollinger Bands Indicator for 20 candles, actually it’s producing buy or sell signals directly on the chart. Whenever the candle close below the lower Bollinger Band that would be a buy signal and when we have a breakout on the other side that would be a sell signal. Now let’s find out how to create an Expert Advisor in MQL4 that is actually going to trade. 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/ Expert Advisor (Template)” from template, “Continue”, I will call this file: “SimpleBollingerBandsStandAloneEA”, click on: “Continue”, “Continue” and “Finish”. Now you can remove everything that is above the “OnTick” function and the two comment lines here. First we need to create an empty string for the signal, it will be called: “signal” and we don’t assign a value because we are going to calculate that now. The Bollinger Bands Indicator has 3 different bands, we are interested in the upper band and the lower band, so we use the included “iBands” function for the current symbol and the currently on the chart selected period for 20 candles. If you look at the Bollinger Bands properties you will see that we use 20 candles, a shift value of 0, and the deviation’s value is 2. These are the default values that we are going to use here, the result will be calculated based on the close price. We use “MODE_LOWER” for the lower Bollinger Band (LowerBB) and “MODE_UPPER” for the upper Bollinger Band (UpperBB). The first one will be calculated based on candle 1 and now we do it again for the previous lower Bollinger Band (PrevLowerBB) and the previous upper Bollinger Band (PrevUpperBB) and this time we are going to use the values for candle 2. If the close price of candle 2 was below the lower Bollinger Band, so if close for candle 2 is less than the value for previous lower BB (PrevLowerBB) and if the close price for candle 1 is above the Bollinger Band – that would be the case when close 1 is bigger than lower BB (LowerBB) – that would be a buy signal and we would assign the word: “buy” to our signal. In the other case if the close price for candle 2 was above the upper Bollinger Band, so if close 2 is bigger than previous upper BB (PrevUpperBB) and if the close price for candle 1 is now below the upper Bollinger Band, so if close 1 is less than upper BB (UpperBB) that would be a sell signal and now we would assign the word: “sell” to our signal. And whenever the signal equals buy and ”OrdersTotal” equals 0 (zero) – that would be the case when we have no open trades – we want to send a buy order so we use the “OrderSend” statement and “OP_BUY” to buy 10 micro lot. In the other case if the signal equal sell and we have no open orders we use “OrderSend” to open a sell trade for 10 micro lot and last but not least we create a chart output that is done by using the “Comment” statement, it will output the word: “Signal:” followed by our calculated signal value. Okay. That’s it. Now you can click on the “Compile” button or press F7 on your keyboard, we don’t have any errors here, two minor warnings and if that is the case you can click on the button here or press F4 to go back to Metatrader. In Metatrader we use a little trick, we click on: “Insert/ Indicators/ Trend/ Bollinger Bands” here are our default values, we click on “OK” and now we save the template by right-clicking into the chart and selecting “Template/ Save Template” and please save it as: “tester.tpl” because this is the template that our back tester is going to use. After you have saved the template please click on “View/ Strategy Tester” or press CTRL and R and here you want to select the file: “SimpleBollingerBandsStandAloneEA.ex4”, enable the visual mode here and start a test. …and here is our little Expert Advisor at work,
    6 min
  • MQL4 TUTORIALBASICS – 128 SIMPLE LONG TERM TREND
    In this video we are going to create an Expert Advisor that is able to calculate buy and sell trades based on the long term trend.   So let’s find out how to do that with MQL4. To get started please click on on a 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 Simple Long Term 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 define two moving averages.   The first one is for 950 candles, the second one is for 1000 candles. Inside of the on tick function we want to create a string variable called signal. But we don’t assign a value here.   Because we are going to calculate that now. And to find the long term trend we want to create a moving average. That can be done by using the integrated IMA function for the current symbol on the chart and the currently selected period on the chart. We want to calculate our small SMA for 950 candles. The zero here means we have no shift value. We want to use mode underscore SMA. That stands for Simple Moving Average. And the result should be calculated based on the close price. We want to do that for candle one. Let’s repeat that. Everything is similar, but this time we are doing it for the big moving average.   The only difference is the name of this variable and this parameter here is calculated based on 1000 candles. And now we are able to define the long term trend.   We simply want to check if the big moving average is bigger than the small moving average. And if that is true that would mean that we have a sell signal. So we assign the word sell to our signal. And of course if the big moving average is smaller than the small moving average, that would mean we have a buy signal and in that case we assign the word buy to our signal. And if we have a buy signal and the return value for orders total is zero, that would mean we have no open orders but a buy signal. And that’s when we use Order Send for the current symbol to open ten microlot buy trade. This part here is the value for the stop loss and for the take profit. If you modify these numbers and do a lot of testing, you will find out what really can improve your results. But back to topic. And if our signal equals sell and we also have no open orders, that’s when we use Order Send to send a sell trade for the current symbol. This one is also a ten microlot position and we use 50 points for the Take profit and the Stop loss value 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 or maybe even the premium course on our website might be interesting for you. That’s also where you can find a shop link, if you don’t want to type everything yourself. For now, let’s remove these empty lines here and click on the compile button 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 Meta Trader. And in MetaTrader you want to click on View, Strategy Tester or press Control and R. Please pick the new file simple long term trend ex four.   Mark the option for the visible mode here and start your test. If you don’t see the moving average line appear on your chart, just click on stop, right click into the chart. You should now see it and select template, save template and save the template as tester.tpl, because this is what we see when we start a strategy test. You can override the current value. Now restart the test and now the moving average values should be visible and we already have the first position on our chart. So our little expert advisor is working as expected and in this video you have learned how to calculate the long term trend by using two moving averages and you have co...
    6 min
  • MQL4 TUTORIAL – SIMPLE AVERAGE TRUE RANGE EA
    In this video, you will see an Expert Advisor that is calculating the Average True Range value. When the value is high it will say; “it’s a strong Average True Range value”, and when the value is weak it will also say that here directly on the chart. We can also make it visible by clicking on: “Insert/ Indicators/ Oscillators/ Average True Range”. This Oscillator is calculated, based on 14 candles, and it looks like this: When it’s weak that would be the case when its below 0.00014, it will show the text: “Weak Average True Range Value” and when the value is rising above 0.00024 we have a strong Average True Range value. Now we want to find out how we can create an Expert Advisor that is able to calculate the indicator. To do that please click on the little button here or press F4 in your Metatrader. 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 one: Simple True Range EA. Continue. Continue and finish. Now you want to delete everything above the OnTick function and the two comment lines here. We start with the Average True Range calculation so we create a variable called: AverageTrueRangeValue, it’s a double variable and we create it by using the built-in function: iATR. This function takes four parameters. The first one is: _Symbol, that variable contains the symbol name of the current chart, the second parameter is: _Period, this variable contains the value of the time frame of the current chart, the third parameter is for the number of candles and we can see that the indicator uses 14 candles. Select ATR properties and here you will see the 14 candles. The last parameter would be for the shift to the right or to the left, we don’t need that, so we use 0 here. If the Average True Range Value is above 0.00024 we create a chart output by using the “Comment” function. It will output the text: “STRONG Average True Range Value” followed by the calculated value here. In the other case if the Average True Range Value is below 0.00014 we use the “Comment” function to output the text: “WEAK Average True Range Value” followed by the value and if the value is greater than 0.00014 and below 0.00024 we would just output the text: “Average True Range Value” and the calculated value because now its neither strong nor weak. Please don’t forget the closing bracket here and if you are done you can click on the “Compile” button here or press F7 on your keyboard. You should have no errors and if that is the case please click here or press F4 to go back to Metatrader. In Metatrader you want to click on: “View/ Strategy Tester” or press CTRL and R and in the Strategy Tester please select the SimpleTrueRangeEA.ex4 file and start your test. This is how it works. Let’s switch to the candle view here, click on: “Insert/ Indicators/ Oscillators/ Average True Range” and now you can compare the value here with the calculated value above. Okay. Now you know how to calculate the Average True Range Oscillator value for Metatrader 4 and you have coded it yourself with a few lines of mql4 code.
    6 min
  • MQL4 TUTORIAL BASICS 127 – SIMPLE ELLIPSE OBJECT
    In this video we are going to create such a Ellipse object like this one. It is drawn from the highest to the lowest of the last 30 candles. So let’s find out how to do that with MQL Four. To get started please click on a little icon here or Press F four on your keyboard. Now you should see the Meta-Editor window. And here you want to click on File, New file, Expert Advisor from Template, continue. I will call this file Simple Ellipse Object.   Click on continue, continue and finish. Now you can remove everything above the on tick function and the two comment lines here. We start with this command. It is called Ihigest and it will find the highest candle for the current symbol on the chart and the currently selected period on that chart. We use Mode High to get the high prices for 30 candles starting from the current candle. That is candle zero and we can do the same thing using Ilowest to find the lowest candle.   This is also for the current symbol on the chart and for the currently selected period. This time we use Mode underscore Low also for 30 candles starting from candle zero. And we store the value in the variable called lowest candle. And before we create a new object, we want to use Object delete to delete all objects that are called Ellipse. The very first time we will not have such an object, but every time afterwards we will delete the old one before we create a new one. And to actually draw the object we use object create. The first parameter here is for the chart.   We want to use the current chart with the candles that is index zero. The second parameter is the name of the object. We will call it Ellipse. Parameter three is the object type, we use OBG_Ellipse here.   The next parameter here is the main chart or the sub chart. The one with the candles is Chart zero, but if you use something like an Oscillator, this would be the sub window one for the Oscillator. We don’t have that, so we use chart zero. Now we have to define four points. The first point is the point in time when the lowest of the last 30 candles has been drawn. The second point is the actual lowest price of the lowest candle.   Point three is the time when the highest of the last 30 candles has been drawn. And point four is the highest price of the highest candle. Now let’s set a few object parameters. That can be done by using Object Set integer. If you mark that and Press F one, you will see that there are some options. The first parameter is for the Chart ID. Once again we use Chart ID zero.   The second one is the name of the object, that is called Ellipse. The next parameter is what we actually want to change. In our case, we want to change the property color. If you Mark that one and press F1,  you will see that we have different properties for different objects. So depending on the object that you want to draw, you might have or have not an option available.   In our case we want to change the color. That should be available for all object types. And we want to set it to blue. And now let’s change another property. This time it’s the property object property fill. That’s the background color, we want 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 means, you maybe want to watch one of the other videos or maybe even the premium course on our website might be interesting for you. That’s why you also can find a link to the shop where you can download source codes like this one in case you don’t want to type everything. 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 a little button here or Press F four to go back to MetaTrader. And in MetaTrader you want to click on View, Strategy tester or press control and R. Please pick the new file simple ellipse object ex four. Mark the option for the visible mode here and start your test. Here we are,
    6 min
  • MQL4 TUTORIAL BASICS – 126 SIMPLE RUNNING TIMER
    In this video we are going to create an Expert Advisor that is able to calculate the time in hours, minutes and seconds that has passed since we started the Expert Advisor. So let’s find out how to do that with MQL4. To get started please click on a 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 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 creating a few variables. The first three are date time variables. The type date time will store the time that has passed since the 1 January 1970 and it is stored as number of seconds.   This is not very good to read for humans, so we are going to convert it. In the On Tick function. We first want to check if the start time equals zero. That would mean that the start time has no value and that is the case when we start the Expert Advisor for the very first time. And when it has no value, we will assign the return value for time local. That is the local time of the computer where the client terminal is running, to our start time. This will also work in the strategy tester where you can pick other time spans and to create a readable format we will use Time to string.   That function will get the start time as the first parameter and the second parameter is for the format. And we are going to use the time underscore date and the time underscore seconds value here. Let’s continue to calculate the current time. We will also use time local. This will be calculated each time the Ontick function is called. And please remember that will not be every second, because the On Tick function will only run when there is a price change. So please keep that in mind.   Now let’s calculate the past time in seconds. That is the current time and we subtract the start time here. And to convert that into a readable format we once again use Time to string for the current time. And we pass time underscore date and time underscore seconds as the second parameter. Now let’s create a chart output by using the comment statement to see what’s going on. And this output will contain the start time, the current time, the same values in seconds since the 1 January 1970 and the past time in seconds, in minutes and in hours. 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 also where you can find a link to the store where you can download source codes like this one, in case you don’t want to type everything. 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 Meta-Trader. And in MetaTrader you want to click on View, Strategy tester or press Control and R. Please pick the new file simplerunningtimer Exfour Mark the option for the visual mode here and start your test. Here we are, the Expert advisor is running. It’s calculating the time that has passed. The current time is 19 minutes past zero and you can see that we have started at midnight and it says that 19 minutes are over. So our Expert advisor works as designed. And in this little video you have learned how to calculate the past time since you started an Expert Advisor, in case you want to do anything time related. And you have coded it yourself with a few lines of MQL4 code.
    6 min

About MQL4TUTORIAL.COM

From the publisher's feed

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