MQL4TUTORIAL.COM

MQL4TUTORIAL.COM

By MQL4TUTORIAL.COMBusinessInvesting
Download on the App Store

MQL4TUTORIAL.COM episodes

  • MQL4 TUTORIAL – SIMPLE BULLS POWER EXPERT ADVISOR
    In this video we are going to talk about the Bulls Power Indicator, it is drawn in a separate window below the candles. The Bulls Power Indicator basically can tell us if the bulls are stronger than the bears. Whenever those lines of the histogram are above the zero line we will put out a buy signal here and whenever the direction changes and the histogram is drawn below the zero line that would be a sell signal. Okay. To create the Indicator and the Expert Advisor that is going to trade it you need to 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 file Simple Bulls Power (SimpleBullsPower.ex4) click on “Continue “, “Continue” and” Finish” and now you can remove everything above the “OnTick” function and the two comment lines here. Let’s create a string variable for the signal here – I will also call it signal – it doesn’t contain a value so far because that is what we are going to calculate in this simple Expert Advisor and to do that we can use the “iBullsPower” function that is included in MQL4, that will calculate the Bulls Power Indicator and return its value. Now what is meant by value? If we passed the execution here we will have a value. In this case it’s 0.0006 and that matches the value of the last bar here of the histogram and to calculate it we need to pass a few parameters. The first one is the current symbol on the chart, the second parameters for the selected period on your chart, in my case I’m trading a 1 minute chart, the period could also be something like 5 minutes 15 minutes and so on and “_Period” makes sure that we are calculating the correct period that is the period from the chart you are trading right now. The next parameter has the value 13 and when you click on “Insert/ Indicators/ Oscillators/ Bulls Power” you will see the period has a value of 13 and we calculate the value based on the close price and that’s exactly why the 13 is used here as the third parameter and “PRICE_CLOSE” is parameter number 4. Well this last parameter stands for the shift. What is a shift? Actually you can move the current indicator value to the right or to the left depending on the shift value. We don’t want to do that so we use 0 and if the Bulls Value is above 0 and the histogram is drawn above the line here we consider that to be a buy signal so we assign the word: “buy” to our signal variable. In the other case if the Bulls Value is below 0 or in MQL4 if BullsPowerValue is smaller than 0 we assign the word: “sell” to our signal. Last but not least we create a screen output by using the built in “Comment” function to output the words: “BullsPowerValue:” followed by the calculated value and in a new line we output: “Signal:” followed by the calculated signal. Okay. That’s it. Now you can click on the compile button here or press F7 to compile your code and that should work without any errors and in that case you can click on the button here or press F4 to go back to Metatrader. In Metatrader we will use a little trick, please click on “Insert/ Indicators/ Oscillators/ Bulls Power”, click “OK”. Now the Bulls Power Indicator will be drawn on your chart and now we right click in the chart, select “Template/ Save Template” and save it as: “tester.tpl” because that is the template that is going to be used for your next back-test. To start the Strategy Tester you can click on “View/ Strategy Tester” or press CTRL + R, please select the newly created “SimpleBullsPower.ex4” file and start your test. Now you should see the little Expert Advisor at work, it creates an output for a current Bulls Power Value and below that you see a buy or a sell signal. On a real account you would combine the signal of the Bulls Power Value to something like a trend following indicator and use it as a filter but for now you know how to create an Expert Advisor that is able t...
    7 min
  • MQL4 TUTORIAL – METATRADER4 DOWNLOAD SETUP FILE GONE?
    In this video I wanted to talk about something that I get as a question on a regular basis. That question is: Is Metatrader 4 still a good choice and does it make sense to start with MQL4 today or should I immediately go and switch to MQL5? As you can see I’m still using MQL4 and Metatrader 4 and actually this is my RoboForex-FixCent account, that’s my real money account and if you click on the “About” tab here you will see that I’m using a branded MQL4 for Metatrader 4 version that was built by Admiral Markets. It says: it’s version 4, built 1090 from march 2017 and I used to tell everybody to go to the website metatrader4.com because that’s where it says that Metatrader 4 is the most popular Forex trading platform and actually it still is but if you click on download here you will see the text: “Download Metatrader 4” but the button says: “Download Metatrader 5” the next generation platform. The rest of the page is still talking about Metatrader 4 but here is another button, this one says: “Download Metatrader 4”. Okay, let’s do that. It takes a few seconds, here we have a file that is called: “mt4setup.exe”, let’s open that, click on execute and now an installation assistant comes up and as I am reading the terms and conditions here they are talking about MQL5 and they are talking about the Metatrader 5 trading platform. Believe it or not this button here will download Metatrader 5 and if you don’t pay attention it will install Metatrader 5, so let’s cancel the installation here, let’s try the Metatrader 4 site here and once again we are on the “Download Metatrader 5” site. Obviously we can’t download Metatrader 4 on metatrader4.com. Let’s try the Admiral Markets website, it says: “Metatrader 4 for Windows” and when I click on the download button they want me to register and most of you probably don’t want to do that but you can go to my website: mql4tutorial.com, click on the menu button and here you should find a link that is named: “Metatrader 4 Download” and this time we are getting the right exe file. Let’s execute this setup and this time it says: “its Metatrader 4”. Let’s confirm the installation and it’s talking about the MQL4 language and it says that we are going to install Metatrader 4. If I mark the confirmation option here and click on settings I see that this time it’s a Metatrader 4 client terminal, it would be installed in the Metatrader 4 directory. I will skip that now because I have already an installation in place, so feel free to use my download link here if you can’t get the setup file anywhere else. Metatrader 4 still works you just need to approve the automated update after the installation and I guess that Metatrader 4 and MQL4 will stick around for a while. Let’s go to forexpeacearmy.com, this is the website: Forex Peace Army, they have a lot of broker reviews and today they still list 756 brokers for Metatrader 4, let’s see if we can get a list of Metatrader 5 brokers. Here is a list of Metatrader 5 brokers; today more brokers support Metatrader 5. One or two years ago maybe a dozen brokers supported this. Let’s have a look at the release notes for Metatrader 4; the last new version is from May 2017. I get the impression that Metaquotes is trying to get rid of Metatrader 4 but most traders and brokers still use it. I use both versions so if you click here it will get you to the MQL5 tutorial website (www.mql5tutorial.com) and if you are just starting out and want to answer the question if MQL4 or MQL5 is the best way to go you can join the free email course here and find out for yourself. I like and use both versions and MQL4 is a little bit more easy to learn, MQL5 has a few advantages, for example: this is a back-test in Metatrader 4 and you would need to import historical data in the “History Center” for each and every currency pair here that is very time consuming and you don’t have to do that with Metatrader 5. That’s a big advantage but basically MQL4 is still around,
    7 min
  • MQL4 TUTORIAL – FIND REMOVE AND FIX CORRUPTED BACKTESTING DATA
    In this video, I wanted to talk about back-testing. This is an automated trading system. Its trading the year 2016 right now, lets speed it up a little bit and you can see that we are making progress here. We also would like to back-test the whole year 2017, so you see that the Expert Advisor is running, lets stop the test here and we change the year to 2017 and start another test. It does work somehow and now it’s finished but the first trade started in November 2017! In this case we made a loss of nearly 300 Dollars; here is the complete report; just a single trade and a big loss, something is wrong here, but what? Let’s slow down the speed here and stat a new test, and now you see that we have a strange change from December to November here. Now what is the cause? Actually Metatrader 4 is going to use historical data. When you click on “Tools/ History Center” or press the F2 key you will see that we have data for each and every minute here, now let’s get down here and here is the problem! This is November 2017 and right below we have December 2016! So, obviously we have corrupted historical data here and now we want to fix that. The best way is to mark the first position in the “History Center”, please make sure that you have selected the 1 minute bars, now scroll down all the way, hit the shift key and mark the last entry. Now we have selected all the records and we click on the delete button. This takes a few seconds, we have still two entries here; but these are current entries from today. Let’s change to the 5 minutes data, do the same again, delete this data for 5 minutes and now I am going to do it for each time frame in the “History Center” because I want to avoid gaps that might occur just from corrupted data that might be in any of the other time frames. Sometimes you have to wait a little while or you need to start over. Mark it again, but the higher the time frame the less data you have to mark and delete. Eventually we have reached the monthly data and now we are done. There are a few websites where you can download historical data; I like the histdata.com website because it’s easy and free. Here you will find a “zip” file with the complete year 2017, these are 1 minute bar quotes, so let’s download that file, it’s about 3 Mega Bites and when you open it you will find the “csv” file that contains all the necessary data for the whole year, let’s copy that. This is my folder for history data and in the “History Center” I select 1 minute, click on “import” and now I select the file we have downloaded, click on “open” and here is all the data we need, but please make sure that you don’t mark “Use selected only” because that would prevent you from importing all the data. So, let’s click on “OK”, now we see the complete year 2017 in the “History Center”, so we can close it. When we stop and restart our back-test it now starts in January. We have already several results here, so now you know how to find corrupted history data, where you can download new data, you know how to import it into the “History Center”. MQL4 Tutorial searches:metatrader backtesting data corrupted
    5 min
  • MQL4 TUTORIAL – SIMPLE IADX EXPERT ADVISOR
    In this video, we are going to talk about this Indicator here; it is the Average Directional Movement Index. Basically it’s a trend confirmation oscillator. Whenever the line here is rising that’s a trend confirmation; in our case for a short trend that is developing on the chart here and as soon as the IADX Indicator is falling, you see, the trend is interrupted here, now its rising again and we see an uptrend and when the IADX Indicator starts to decline – like in this case – the uptrend is interrupted. Now how can we create an Expert Advisor that is able can calculate the Average Directional Index in MQL4? 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” (Next). I’ll call this one Simple IADX (SimpleIADX), click on “Continue” (Next) “Continue” (Next), and “Finish”, and now you can delete everything above the “OnTick” function and the two comment lines here. In the first step we want to create a signal, especially a string variable for the signal that will also be called signal and we don’t assign any value because we are going to calculate that later. Let’s calculate the IADX value (IADXValue) by using the function: “iADX” that comes with Metatrader 4. If you mark it and press F1 the reference will tell you that it needs some parameters; the first one is for the symbol on the chart, the second one for the time frame you use on the chart, the third one is for the period for the calculation. If you right-click on the Indicator and select “ADX properties” you will see that the period is 14 and we calculate the values based on the close price so that’s what we use here; 14 and PRICE_CLOSE for the close price. This parameter is for the buffer, so what is a buffer? You see the Indicator produces 3 lines here, let’s hit the pause button and the value for the blue line is 29.93555 – that’s exactly what you see here. The 2 dotted lines have a different value and you could calculate the 2 other values if you exchange buffer 0 with buffer 1 or buffer 2. The last parameter here is the shift value – that’s also 0. We want to calculate the current IADX Indicator for the current value (IADXValue) here and to get the last IADX value (LastIADXValue) we use exactly the same parameters accept we use a 1 to get the last value. If we use a 10 instead we would get the value for 10 candles before. If the IADX value (IADXValue) is higher now so IADX value (IADXValue) is greater than last IADX value (LastIADXValue) we want to output: “IADX is rising” so that’s what we assign to our signal variable. In the other case if the IADX value (IADXValue) is lower now so the current IADX value (IADXValue) is below the last IADX value (LastIADXValue) we assign the text: “IADX is falling” to our signal. Let’s create a screen output by using the “Comment” function. It would output the text; “IADXValue:”, the calculated value and in a new line a text: “Signal:” and the calculated signal we have created here or here. So, that’s basically it, let’s click on “Compile” or press F7 on your keyboard. That worked without any errors so now we can click here or press F4 to go back to Metatrader. In Metatrader we are going to use a little trick; please click on “Insert/ Indicators/ Trend/ Average Directional Movement Index”, click on “OK”, leave the parameters as they are, click on “OK” and now you should see the Average Directional Movement Index in a separate window below the candles and because Wikipedia says: “The ADX does not indicate a trend direction or momentum and is only used to calculate the trend strength” I will insert another Indicator for a trend. Let’s use a Moving Average for 14 candles because the ADX Indicator here is also calculated based on 14 candles, let’s choose an SMA (Simple Moving Average) this is apply to the close price, I use red and click on “OK”.
    7 min
  • MQL4 TUTORIAL – SIMPLE MARKET TIME EXPERT ADVISOR
    In this little Expert Advisor we are going to find out if the market is closed or if it is open, like right now. The Expert Advisor contains some external variables where you can define when the market opening and closing time is for your country. In my case here in Germany the trading hours start at 9:00 am and they end at 5:30 pm – in German notation that is 17:30 so, when we see 9:00 this line here will change to “Market is open” and when it says 17:30 the “Market is closed”. Now how can we create an Expert Advisor that is able to read the local time and generate a signal for the market opening or closing time? Well, to do that please click on the little button here or press F4 on your keyboard. Now you should see the Metaeditor here and here you want to click on “File/ New/ Expert Advisor (template)” from template, continue — I will call this one: ”SimpleTime” — click on continue, continue and finish. Now you can delete everything above the “OnTick” function and the two comment lines here. Above the “OnTick” function we are going to define 2 string variables for the opening and closing time of the market. The modifier “extern” makes it possible that you will be able to modify the variable settings here in the Expert properties. Let’s also define two integer variables; one is for the index of the market opening time and the second one for the index of the market closing time. And I would also like to have a string variable for the market state. We will actually start with a closed market and in the “OnTick” function we need to find out the time with seconds and that can be done by using “TimeToStr” and we use “TimeLocal” we want to have the “TIME_DATE” and the “TIME_SECONDS”. Let’s press F1 and here you can see “TIME_DATE” will give you the year the month and the day and the output for “TIME_SECONDS” is hours minutes and seconds. That will give us the current time on our computer and now we want to find out if the opening time is in the time string, so we use “StringFind” to find the market opening time in the time with seconds that we have calculated here. The last parameter here is used for the starting position, we want to start to search from the first character in the string and we do exactly the same for the closing time. This time we use “StringFind” to find the market closing time in our time string and if the opening time was found the value for index market opening time will be greater than zero and in that case we want to set the market state to open, otherwise if the closing time was found the index market closing time is greater than zero and so we would set the market state to closed. Last but not least we use the “Comment” function to output the text “Time:” followed by the current time we have calculated and the text: “Market is” followed by the market state directly on our chart. So, let’s compile the code here by clicking on a little button here or pressing F7 and that worked without any errors and without any warnings so now we are finished and we can click on a little button here or press F4 to go back to Metatrader. In Metatrader you want to click on “View/ Strategy Tester” or press CTRL + R that should bring up the Strategy Tester panel and here you want to select the Expert Advisor called: “SimpleTime.ex4”, please make sure that you enable the visual mode here and start your test. Now you should see that the market is closed until the time reaches 9 am – that should be the case in a few seconds now and then it will change to market is open and it did. So, now you know how to find out the market open and closing time, maybe to use it for entry and exit signals and you have calculated it yourself with a few lines of MQL4 code.
    6 min
  • MQL4 TUTORIAL – SIMPLE WPR EXPERT ADVISOR
    In this video we are going to create an Expert Advisor to output buy or sell signals on your chart based on the WPR Indicator. This is the Williams’ Percent Range Indicator, it’s based on the last 100 candles and whenever the blue line here crosses one of the dotted lines, that will produce a buy or a sell signal, when it’s below it’s a buy signal, and when it’s above the upper dotted line here, that would be a sell signal. Now how can we create an Expert Advisor that is able to output buy or sell signals for the Williams’ Percent Range Indicator directly on your Forex chart? To do that please click 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 one: Simple WPR (SimpleWPR) for Williams’ Percent Range. Click on continue, continue and finish. Now you can delete everything that is above the “OnTick” function here and please also delete the two comment lines. We will start with a variable for the signal – this is a string variable called signal – and so far, we will not assign any value because we are going to calculate the signal later. Now let’s calculate the WPR value, we are doing it by using the “iWPR” function that comes with MQL4. It needs the current symbol on your chart, the selected time frame like 1 minute or 60-minute charts, this is the period for the calculation, we will use 100 candles here because when you right-click on the indicator and select properties, you will see that 100 candles are the period for the calculation in the default value. And the last parameter is for a shift value, we could use that to move the Indicator to the left or to the right, but we don’t need to do that. We use “_Symbol” for the symbol on the chart, _Period for the selected period on the chart, this parameter is for our 100 candles and because we are not going to use any shift value the last parameter is zero. When the WPR value is below minus 80 – that would be the case when the blue line is below the dotted line here, that’s the minus 80 mark – we want to create a buy signal, and here is how that is done with MQL4: if WPR value is below minus 80 we want to create a buy signal, so we assign the word: “buy” to our string variable with the name signal. In the other case if the WPR value is above minus 20 – that’s whenever the blue line here crosses the upper dotted line – we want to create a sell signal. So, if WPR value is bigger than minus 20 we create a sell signal by assigning the word: “sell” to our signal variable. In the last step we are going to create a screen output by using the “comment” function and that will output the word WPR value followed by the calculated value. This will produce a new line and in the second line we want to have the text signal followed by our calculated signal. Please don’t forget the closing bracket and when you are done you can click on the compile button here or press F7 on your keyboard. If you don’t get any errors and no warnings here, you can click on a little button here or press F4 to go back to Metatrader. In Metatrader we are going to use a little trick, just click on “Insert /Indicators /Oscillators /Williams’ Percent Range” and click on OK. Now your chart should look like this, and you want to right-click, select “Template /Save template” and save it as tester.tpl because this is the template the strategy tester is going to use for your back test. If you are ready, please click on select “View/ Strategy Tester” or press CTRL and R. Now you should see the Strategy Tester panel here and you want to select the file: “SimpleWPR.ex4”, mark the visualization mode here and start your test. This is our Expert Advisor at work, it generates buy or sell signals on our chart and you have created it yourself with a few lines of MQL4 code.
    6 min
  • MQL4 Tutorial – Simple RSI Expert Advisor
    What you see here on the chart is the RSI indicator, it is a very popular indicator and whenever the blue line here crosses one of the dotted lines that will create a signal. Let’s speed it up a little bit! Now you see that the blue line is between the two dotted lines most of the time, but when it’s above the upper line that is considered to be a sell signal. In the other case if it’s below the lower dotted line that would be a buy signal and now we want to find out how we can create an Expert Advisor that is going to output buy or sell signals directly on our chart. To do that please click the little button here or press F4 on your keyboard! Now you should see the Metaeditor window here. Here you want to click on “File/ New/ Expert Advisor (template)” from template. Continue. I will call this one: Simple RSI (SimpleRSI). Continue, continue and finish. Now you can delete everything above the “OnTick” function and the two comment lines here. The first thing we need is to create a string variable for the signal – a string variable is for text – we will also call it signal, but we will not assign any text here, because that is what we are going to calculate later on. Now we want to calculate the RSI value that can be done by using the “iRSI” function that comes with MQL4. It needs some parameters. The first one is the symbol on the chart, the second one is the selected period on the chart; like one minute or one hour, the third parameter is the number of the candles that are used for the calculation. If you right click the indicator and select RSI properties you will see that the period is 14 candles in the default settings and the indicator is calculated based on the close price. So, that’s what we are going to use for the next parameter. The last parameter here is for a shift but we are not going to use it because we don’t want to move the indicator to the right or to the left. And now that we have calculated the RSI value we want to find out if the value is below 20 – that would be the case when the blue line here is below the lower dotted line. In MQL4 we can use the “if” statement to find out if the RSI value is below 20 and in that case, we would have a buy signal, so we assign the word “buy” to our signal. In the other case, if the RSI value is above 80; so, if RSI value is greater than 80 we consider that to be a sell signal and we assign the word “sell” to our signal. Let’s create a screen output! To do that we use the built-in comment function to output the text: RSI value (RSIValue) followed by the calculated value we have created here. This backslash n (“\n”) produces a new line and in that second line we output the text: “signal” followed by our signal. That’s actually it. Now click on “Compile” or press F7 and that should work without any errors or warnings, and in that case please click here on the little button or press F4 on your keyboard to go back to Metatrader. In Metatrader we use a little trick; please click on “Insert /Indicators /Oscillators /Relative Strength Index” and click on OK. Now the RSI window should appear on your chart and now you want to right click in the chart window, select “Template /Save Template” and save it as tester.tpl because that is the template that the strategy tester is going to use for your next back test. After you have done that please click on “View / Strategy Tester” or press CTRL + R and in the strategy tester you want to select the file: SimpleRSI.ex4, enable the visual mode here and start your test. Now you should see… Oh, something is going wrong here! The signal is always present. Obviously I have missed something, and yes, this is only a comment! Let’s add the “if” statement, so if RSI value is above 80 that would produce a sell signal. Let’s recompile the code! Go back to Metatrader. Stop the running test and start a new one. This looks much better! We don’t see a signal as long as the blue line is between the dotted lines here,
    7 min
  • MQL4 TUTORIAL – SIMPLE SELL LIMIT EA
    In this video, we want to create an Expert Advisor to place a sell limit order. This sell limit order is a pending order and it will be triggered when the price rises and crosses this line and as soon as that happens we will have a sell trade. It might be a little hard to understand the sense, especially in the beginning. Why should anybody wait for the price to rise and sell afterwards, but in charting there are actually strategies where this makes sense. For now, we want to answer the question: how can we create an Expert Advisor in MQL4 that is able to place such a pending sell limit order automatically? 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 from template. Continue. I will call this one: Simple Sell Limit EA. Continue. Continue and finish. Now everything above the OnTick function can be deleted and please also delete the two comment lines here. The first thing we do is to check if no open order exists and that would be the case if the OrdersTotal function returns zero. In that case we want to send a sell limit order and we do that by using the OrderSend command, but actually we have to pass a few parameters. So, let’s start the parameter list with a round bracket. The first parameter is the current currency pair on the chart. That is delivered with the MQL4 function: Symbol. In the second parameter, we say that we want to trade a sell limit. That is done by using the constant: OP_SELLLIMIT. If you mark this constant and hit F1 you will see that there is also a buy limit, a buy stop or a sell stop. These four constants here are used for pending orders, while OP_BUY or OP_SELL would cause a direct order. Now we have to tell MQL4 how much we want to order. In our case the position size will be 10 micro lot, the pending order will be placed 20 points above the current Ask price and if you click on one of the currency pairs here you will see that you have a red line and a blue line. The red line is for the Ask price. That is the price we have to pay if we buy something. The blue line here is the Bid price, that is what we would get if we sell something. We have to tell MQL4 how much movement and deviation is allowed. We only want to allow 3 pips, so if the price movement… so whenever the volatility is too high here our OrderSend command will not be triggered. In this simple example, we don’t use a Stop Loss, so the next parameter is a zero. Our Take Profit will be 10 points below the Bid price. We don’t need a comment so we use the constant: NULL, we also use zero for the id number because we don’t need one. The same is for the expiration date because we don’t want our Expert Advisor order to expire and last but not least, we pass the color green, to show a green arrow on the chart. If you mark that and press the F1 key you will see a lot of other colors that you could use. Okay. We started our parameter list with a round bracket, so let’s add a closing round bracket and a semicolon. Please don’t forget the closing curly bracket and if you are finished you can click on the compile button or press F7. You should have no errors and no warnings here and in that case, you can click on 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 please pick the file: SimpleSellLimitEA.ex4, mark the visual mode option here and start your test. Here is our pending order, you can see that Metatrader has placed a sell limit above the current Ask price and now you know how to create an EA to automatically trade sell limits in MQL4 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