MQL4TUTORIAL.COM

MQL4TUTORIAL.COM

By MQL4TUTORIAL.COMBusinessInvesting
Download on the App Store

MQL4TUTORIAL.COM episodes

  • MQL4 TUTORIAL BASICS – 119 MYFXBOOK EXPERT ADVISOR INSTALLATION
    In this video we are going to install the Expert Advisor for MyFxBook. That is a statistics website. So let’s find out how to do that with MetaTrader 4. If you go to Google and type in MyFxBook, you will find this website. It provides statistics.   I already have an account, so I can sign in with Google. Here. I have my so called portfolio, a lot of systems and now I can open one of my systems and see all the statistical data. This is very helpful. So let’s install the MyFxBook Expert Advisor on our device.   Here is the link. You could also do a Google search. So let’s click on the link. The EA installer is downloaded. I will now double click it. In my case it comes up right away.   Usually it will need some additional files. I have done this installation process for MQL5 a few minutes ago. This is for MQL4 and MetaTrader 4. Both files require the DotNet framework from Microsoft to be installed. This would take a few additional steps, but as I did it before, it isn’t required anymore.   So I can now pick one of my installation directories. In this case I will pick the Metatrader4 installation. You can run MetaTrader 4  and MetaTrader 5 on the same computer.   This is the right entry. So let’s click on install. Now it says the installation was complete and I should restart my MetaTrader. So let’s click on finish, file, exit and after you have restarted the MetaTrader, you should see the Expert Advisor here in the navigator view.   It’s called MyFxBook. So let’s drag this one on the chart. Yes, I really want to stop the current one and replace it with the MyFxBook expert advisor. You can simply open a new chart if you run Expert Advisors for all the currency pairs that you need.   Please click on depencies and see if those entries here exist. Afterwards please click on inputs. Type in your credentials for your free MyFxBook account. I will now use the wrong password and click on OK, and that will cause that the Expert Advisor is right away removed from the chart. So this is a mistake.   Now you see we have never published anything.   Actually, auto trading is disabled here. That is another common mistake. So let’s enable that and try it again. This is still the wrong password. Now I click on okay, and it once again was removed.   Now let’s click on view, terminal, journal and you will actually see the entry here. Experthas MyFxBook been removed, this is one of the traps that you need to know. Another one is you need to click on tools, options and allow DLL imports on the Expert Advisors tab here. So let’s do that.   Click on Okay, drag the Expert Advisor on the chart. And this time it says the statement was uploaded successfully. So now everything works as expected and in this little video you have learned how to install and troubleshoot the MyFxBook Expert Advisor for MetaTrader4 and you have done it yourself within a few minutes.
    5 min
  • MQL4 TUTORIAL BASICS – 118 SIMPLE LAST ORDER TYPE
    In this video we are going to create an expert advisor that is able to calculate the direction for the last position that was closed. 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 last order type.   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. Inside of the Ontick function we want to check if we have no open orders. If that is the case, we need to open test positions. Obviously you wouldn’t do that on a real account, but this is what demo accounts are good for, and we need some positions to calculate the direction of the last one.   Therefore, we are going to use order send to open a buy and a sell position. Afterwards we want to create a chart output. That is done by using the comment statement. It will output the text. My last position was followed by the return value for this function here. It is called Get last order type. But it doesn’t exist so far, so we need to create it now. Our user defined function will return a string value. The name is Get last order type. We need a few variables for the details and we use a for loop to go through all the orders in the history.   Now we pick one order by using order select for the current counter value. We want to select the position for the mode underscore history. In the next step we want to check if the current order symbol equals the symbol on the chart, and we only want to have the direction for the last position. So we check if it is the last order. That would be true when the counter value equals orders history total minus one. If that is true, we want to calculate the last profit by adding the values for order profit, order swap and order commission.   And of course we want to check the order type. If it equals Op underscore buy, the last order type is set to buy order. Otherwise, if the order type equals Op sell, that would mean we have a sell order, so that’s when we assign the word sell order to our last order type. Let’s continue and store the values for the last order type and the last profit in our result variable. Now we close the for loop and return our result to the 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, 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.   By the way this was once again 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 please 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, please click on View, Strategy Tester or Press Control and R.   Please pick the new file simple last order type.ex4, mark the option for the visual mode here and start your test. Here we are, the expert advisor is running and right now the sell trade was closed. It also says that the last position was a sell order with a profit of -4.6 dollars, so let’s click on the results tab. Here it is. 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 calculate the direction for the last position that was closed and you have coded it yourself with a few lines of MQL4 code.
    6 min
  • MQL4 TUTORIAL BASICS – 117 SIMPLE MULTIPLE CHART TREND
    In this video we are going to create an expert advisor that is able to calculate trends on two different charts by using an exponential moving average. 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 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 start by creating a string variable. One is for the signal on the current chart, and let’s add another one, this time for the Euro US dollar. Afterwards we can use the integrated IMA function that comes with MQL4.   It will calculate our exponential moving average for the current symbol on the chart and the currently selected period on that chart. We are going to calculate it for 20 candles. We are not using a shift value. The mode is mode underscore Ema, that stands for exponential moving average. The result should be calculated based on the close price and we want to calculate it for the current candle zero.   Now let’s repeat the whole thing and this time we are going to calculate an old EMA 20. Everything is similar, but the result is calculated based on the value for candle two. Now comes the interesting part. This time we want to calculate it for the Euro US dollar, so we need to exchange the first parameter here. I have used the hard coded Euro US dollar currency pair.   When you open MetaTrader, you should see how it is shown on your own account. Depending on the account type, you could maybe see a little suffix here. So please make sure that you name it as it is shown for the account type you are using. The rest is like in the first line, and as you might have guessed, we need to calculate the same thing for candle two because now we are able to check the trend. If the current EMA 20 is above the old EMA 20, that would be a buy signal for the current chart, and that’s when we assign buy to our chart signal.   In the other case, if the EMA 20 is below the old EMA 20, that would be a sell signal, and that’s when we assign sell to our chart signal. Now it’s easy to do that for the Euro US dollar, everything is similar. All you need to do is to check if the value for the current EMA of the Euro US dollar is above the old value. That would be a buy signal, or if it is below the old value for the EMA Euro US dollar, that would be a sell signal.   Finally, we want to add a comment statement that will output the current values for both charts and the trend for both charts 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. But for now, please click on the compile button or press the F7 key. 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, you want to pick an empty chart.   Select Insert, Indicators, Trend, Moving Average. We want to use a moving average that is calculated for 20 candles. No shift value.   The Ma method should be exponential, apply to the close price, you can pick a color and click on Okay. Now the moving average shows up and now you want to rightclick into the chart. Select template, save template and save it as tester.tpl and default.tpl. Tester.tpl is what will show up in the strategy tester and default TPL is what you will see when you open a new live chart. Today is Saturday so the markets are closed and we only can do a backtest. So I click on OK.   If you don’t see the strategy tester, you want to click on View, Strategy Tester or press Control and R. Please pick the new file Simple Multi Chart Trend.
    7 min
  • In this video we are going to create a sell trailing stop for this indicator here. This is the envelopes indicator, 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 MetaEditor window and here you want to click on File, new File, Expert Advisor from Template. Continue.   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 also remove the two comment lines here. We start by creating a static variable for the last stop loss value of the envelopes indicator. Static means that this variable is going to hold the values, even when we leave the Ontick function, so that we can use the last stop value when the price changes the next time. And to test a trailing stop, we obviously need to create an open position, so we check if orders total equals zero.   If that is the case, that would mean we have no open positions and that’s when we use OrderSend to open a sell trade for ten micro lot. Afterwards we need to reset the last value, because once we open a new position we need to reset the stop loss level. Now let’s calculate the values for the lower band and for the upper band of the indicator. That can be done by using Ienvelopes for the current symbol on the chart and the currently selected period on that chart.   We want to calculate the indicator for 14 candles.   We use mode underscore SMA, that stands for Simple Moving average. This value is a shift value. We don’t need that, so we set it to zero. The result should be calculated based on the close price. This value here is what you see when you right click on the indicator properties.   It’s for 14 candles and the deviation value is 00.10. When you open an empty chart and click on insert, Indicators, trend, envelopes, you will see that this is the default value. Now please click on OK. Here is the indicator, now rightclick into the chart. Select template, save template and save it as tester.tpl.   You can override the current one because tester.tpl is what we are going to see in the strategy tester. This parameter here is for the buffer. We have either two for the lower band or one for the upper band. When you mark I envelopes and press F1, you will see the description and when you scroll down and click on this link for indicators line identifiers, you will see here is the Ienvelopes function. Mode_Upper equals one, Mode_Lower equals two and that’s exactly what we are going to use here.   The last parameter here is for the number of the candle. We want to calculate the results for candle one. Now we can try to change the stop loss. By using this function, it is called Check Envelopes Sell trailing stop. We will pass a parameter here, the one for the upper band.   Currently, this function doesn’t exist, so we need to create it in a few seconds. But before we do that, we want to set the variable for a last stop envelopes value to the current value of the upper band, so we can use this one the next time. That’s it for the Ontick function. So let’s create the one for the Sell trailing stop. The name is Check Envelopes Sell trailing stop.   We use void because we don’t need a return type. We pass a double variable called upper band, and now we need to use a for loop to go through all the open orders. We use OrderSelect for each counter value in the for loop to select the order. Afterwards we want to check if the current symbol of the order equals the symbol on the chart. We want to know if the order type of the current order equals Op_Sell, so it is a sell position and only if this is true, we want to check if the current order stop loss is above the value for the upper band. And if this is true, we want to use OrderModify for the current order ticket and the order open price. We want to change the current stop loss to the value for the upper band.
    8 min
  • MQL4 TUTORIAL BASICS – 115 SIMPLE ENVELOPES BUY TRAILING STOP
    In this video, we are going to create an Expert Advisor that is able to create a buy trailing stop that is based on this indicator, it’s the envelopes indicator. 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 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 let’s also remove the two comment lines here. We start by creating a static variable. It’s a double variable and we are going to use it to save the value for the last Stop Loss and to use a trailing stop, we obviously need to create a test buy position. You wouldn’t do that on a real account, but on a demo account we will check if OrdersTotal equals zero, that would mean we have no open position.   And in that case we use Ordersend to open a Buy position for 10 Microlot. Of course, we need to reset the value for the last Stop Loss, because with a new position we need a new Stop Loss level. Let’s continue and calculate the values for the lower band and for the upper band. That is done by using the included function Ienvelopes for the current symbol on the chart and the currently selected period on that chart. We want to calculate values for fourteen candles.   We use ModeUnderscoreSMA for simple moving average, no shift value. The result should be calculated based on the close price. And if you wonder what this value is, well, if you open a new chart window and click on insert indicators, trend, envelopes, the standard value is zero point ten percent. So let’s click on OK, let’s use that value in our indicator. This parameter here is for buffer two or buffer one. If you open the reference, you will see that the ienvelopes function uses mode upper or mode lower, or the values would be one for the upper line and two for the lower line.   That’s actually what we are using here. The last value here is for the candle number. We are going to use candle one. And if the last stop envelopes value is below the lower band, we want to call a function that is called check envelopes buy trailing stop. And we want to pass the lower band value here as a parameter. At the end of the ontick function, we want to save the lower band value as last stop envelopes value for the next time we call the function.   But this function doesn’t exist. So let’s create that. The return type is void, the name as check envelopes buy trailing stop. We are passing the lower band value here, afterwards we are going to use a For loop to go through all the open orders and for each order we want to use orderselect to select the order, then we want to check if the current order symbol equals the symbol on the chart. On top of that, we want to check if the order type equals OP buy.   So it’s a buy trade. And if all that is true, we also want to know of the order Stop Loss is below the lower band. If all those conditions are true, we use order modify to modify the current order and adjust the Stop Loss to the value for the lower band. Finally, please close all the open loops and functions 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 on our website might be interesting for you.   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 F4 to go back to Metatrader. And in Metatrader, you want to click on insert, indicators, trend, envelopes. Please go with the default values here. Click on OK. Now you should see the indicator on the chart. Maybe you need to zoom in or zoom out.   Now right click onto the chart,
    7 min
  • MQL4 TUTORIAL BASICS – 114 SIMPLE SHIFTED PRICE EA
    In this video, we are going to create an Expert Advisor that is able to trade price data from a shifted line chart. So let’s see how that can be done with MQL4. 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 and the two comment lines here. We start by creating a string variable called signal. What? We are not going to assign a value here because we want to calculate the signal later on. In the next step, we are going to use the integrated. IMA function that comes with MQL5, for the current symbol on the chart and the currently selected period. I would like to calculate an SMA for one candle and that should be drawn twenty candles ahead of the current time.   We are using mode SMA, the result should be calculated based on the close price. And this last one here is the candle number, we are going to calculate it for the current Candle zero. Well, when you cut this out here, you will see that the value is called MA shift. The last one here is also a shift value, and it’s hard to understand for beginners. But this shift value here is the one to draw the values on the chart.   And this shift value at the end is used to define for which candle you want to do that. Actually, this line chart here is the same as the simple moving average that we draw into the future. You can see the identical movements here and now we can check if the moving average value is below the close price for Candle zero. 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 moving, average, value is bigger than the close price for Candle zero, that would be a Sell signal and that’s when we assign sell to our signal. And if our signal equals buy and the return value for OrdersTotal is zero, that would mean we have no open orders and a buy signal. And that’s when we use Ordersend to buy 10 Microlot. Otherwise, if the signal equals sell and OrdersTotal is also zero, that means we have no open orders and a sell signal and that’s when we use Ordersend to sell 10 Microlot.   Finally, I would like to add a comment output for the chart. That will show us the text “the current signal is” followed by 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, 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. That’s why we also have links to the shop to download source codes like this one.   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 F4 to go back to Metatrader. And in Metatrader, please pick an empty chart, switch to the line chart view, that can be done by pressing ALT and 3, or clicking the little button here. So you have a single line chart, now.   Now, right click into the chart, select template, save template and save it as tester.tpl. You can override the current one. Tester.tpl is what we will see when we start the strategy tester. So let’s do that and click on View, strategy tester or press Control and R. Please pick the new file. Simple shifted price .EX4, mark the option for the Visual mode and start your test. Now you will see that the second moving average is not shown on the chart.   So let’s stop the test. And here it is. Now right click again. Select Template, save template and save this one as tester.tpl. And when you restart the test, you will see now are both lines on the chart. Currently we have a buy signal and this is our first position. Let’s speed that up a little bit.
    7 min
  • MQL4 TUTORIAL BASICS – 113 SIMPLE SELL PERCENTAGE RISK
    In this video, we are creating an Expert Advisor for Sell positions, that makes it possible to use user defined Stop Loss value. 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 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 by creating an input variable.   If you mark that and press F1, you will see that input variables can be changed by the user from the program properties window without the need to recompile the code. The start value for our trading risk percentage is zero point five. That is one half of a percent. We also need another variable called max position loss. That is the maximal value that we are going to accept as a loss. Inside of the ontick function we need to check if we already have open positions.   So we use the function OrdersTotal. And if that returns a return value that is below one, it would mean that we have no open orders and no open positions. And if that is true, we are going to send a test sell order by using Ordersend for the current symbol on the chart. We want to sell 10 Microlot. Actually, we could also use the new syntax here, because when you mark that and press F1, you will see that you can also use _symbol. We don’t use a defined Stop Loss value here. The Take Profit is 20 points below the current Bid price. Please remember, this is just a test sell order. You wouldn’t do that on a real account. But as we need to close positions, we first need to have open positions. And actually that’s where demo accounts are good for. On your account, you could have more than one open position. So we are going to use a for loop here to go through all the open orders.   Now we can use orderselect for the current counter value and try to select a position. If that is successful, we will calculate the position profit by using order profit. We calculate the max position loss by getting the current account balance divided through one hundred, that would be one percent. And that will be multiplied with the percentage risk value that we have defined here. And if you wonder what that part here is about, well, the max position loss is a negative value.   Therefore, we use this expression to calculate the negative value. Let’s add two  print statements here. The first one is for the position profit. The second one is for the max position loss. And we will see the output in our journal. And if the position profit is below the max position loss value that we have allowed. Remember, this is a negative value – we will use order close for the current order ticket and the current order lot size to close the current order.   Let’s close the orderselect the For loop and to see what’s going on, I would like to add a comment statement for the current balance, the current max position loss and the percentage risk value directly on our chart. 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 from the basic video series first, or maybe even the Premium Course on our website might be interesting for you.   That’s also where you can find offers to download source codes like this one. 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 click on View, Strategy tester or press Control and R. Please pick the new file Simple sell percentage risk dot EX4.   Mark, the option for the Visual mode here and start your test, here we are. This is our first position. Now let’s click onto the journal tab.
    7 min
  • MQL4 TUTORIAL BASICS – 112 SIMPLE BUY PERCENTAGE RISK
    In this video, we are going to create an Expert Advisor that is able to close positions based on a user defined percentage value. 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 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 let’s also remove the two comment lines here. We start with an input double variable. Input is a modifier that makes it possible to be changed by a user from the program properties. And this is the percentage risk value, zero point five would be a half percent. We also need a variable for the max position loss value. Inside of the ontick function we check if we have no open orders.   So if OrdersTotal returns a value that is below one, we would open a buy ticket or a buy order. This is just a test position. You wouldn’t do that on a real account, but we need something to close. So we now use Ordersend to open a buy trade for 10 Microlot on our demo account. Now let’s talk about the interesting part. We use For loop to go through all the open orders here. In our case, we will have only one order.   But on a real account, you would now go through each and every trade for every currency pair, select the order.   And afterwards we would calculate the profit for the position. That can be done by using order profit. It says that it will return the profit of the currently selected order. Well, that is not totally correct because it will calculate the profit without swaps and commissions. But for this simple example, it is good enough. Now let’s continue and calculate the max position loss. We use account balance divided by one hundred. So that would be one percent. And then we want to multiply it with percentage risk value.   That is the user defined value that the person in front of the screen has defined.   And if you wonder about this part, well, we need to calculate the negative value because actually a position loss is a negative thing. Now, let’s add two print statements. They will show us the position profit and the value for max position loss in our journal tab. And if the position profit is below the allowed max position loss, we would use order close for the current ticket and the current order lot size and close the order. This is the slippage value and the last value here is for the color.   Now let’s close the select part and the for loop here. And at the end of our little Expert Advisor, I would like to add a comment that will output the balance, the value for max position loss and the user selected percentage risk value on our chart. Well, that’s about it. If this was too fast for you or if you have no idea what all the code is good for, 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 suggestion of a German Premium Course member. And as soon as this video is finished, I will send him the source code. So if you are 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, 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 Metatrader. And in Metatrader, we want to click on View, Strategy tester or Control and R.   Please pick the new file, simple buy percentage risk dot EX4. Click on expert properties. In my case, I will use the one percent risk value. For four hundred US dollars, that would be four dollars, so let’s click on OK, mark the option for the Visual mode and start your test. Here is our Expert Advisor. It is running. Now let’s click on the journal tab and we can see the curr...
    7 min
  • MQL4 TUTORIAL BASICS 111 – SIMPLE STANDARD DEVIATION EA
    In this video, we are going to create an Expert Advisor for this standard deviation indicator, 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 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 EA. 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 string variable for the signal, but we do not assign any values here because we are going to calculate that later.   Now let’s create a deviation array for two hundred candles. This is a double array so it can hold floating type values. And now we are going to use For loop to go through all the values for as long as our counter is above zero. And inside of that loop we are going to assign a deviation value. That can be calculated by using the included function iSTDDEV. For the current symbol on the chart and the currently selected period on that chart, we want to calculate for twenty candles without a shift value.   We are using Mode Underscore SMA. That stands for simple moving average, and the result should be calculated based on the close price, for the current candle number. And now that we have done the calculation, we are going to assign the calculated deviation value to the counter number of our deviation array. That’s it for the For loop. Now let’s continue and calculate the current value. That is done by using the same function for the current symbol on the chart and the currently selected period on that chart.   We also calculate it for twenty candles, without any shift value, for the simple moving average and the close price. But in this case we are doing it for Candle zero. Afterwards we can use array maximum. If you mark that and press F1 you will see that will give us a maximal element in an array. In our case, it’s the number for the highest candle. Array Maximum needs a few parameters. The first one is the array. We want to search the whole array starting from Candle zero.   Let’s repeat that for the lowest candle number. This time we are going to use Array Minimum, that will give us the minimum value. Now we can check if the lowest candle equals Candle zero. That’s the current candle. And if that is true, we assign the word buy to our signal. In the other case, if the highest candle is the current Candle zero, that would be a Sell signal. And that’s when we assign the word sell to our signal.   Highest candle means the highest value for our indicator in this case. But often this is also the highest candle on the chart. Now let’s continue. If we have a buy signal and the return value for OrdersTotal is zero, that would mean we have no open positions.   And we have a buy signal, and that’s when we use Ordersend and by 10 Microlot.   Of course, we also need to do that when we have a sell signal. We will check if we have no open positions and if we have Sell signal. And if that is true, we use Ordersend. And sell 10 Microlot. Finally, I would like to add a comment statement for a chart output. That will output the current value, the number of the highest and the lowest candle for our indicator and the signal on our chart.   That’s about it.   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 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 a link to 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 F7 on your keyboard.   That 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. And in Metatrader you want to pick an empty chart,
    8 min
  • MQL4 TUTORIAL BASICS – 110 SIMPLE MULTIPLE INPUT
    In this video, we are going to create an Expert Advisor that can use a so-called enumeration list of values that can be picked by a user without the need to recompile the code. So let’s find out how to do that with MQL4. To get started please click on the little button here or press F4 on your keyboard.   Now you should see the Metaeditor window and 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. The list should contain some entry signals. And if you mark this key word here and press F1, you will see that enumerations are there for a limited set of data that can be predefined, for example, for a list of months.   We want to do that for a list of entry signals. And it’s also possible to assign a value here. So the first item is for random entries and we assign the value zero. The values are separated with commas. The next one would be for the EMA. That would be a value of one and so on. The list is short here because this is just a simple example. We could use a much longer list. The next step is to create an instance of that list.   Don’t forget the modifier input here because this key word is used to make it available for the user and you can afterwards change the values in the Expert Advisor properties. Our list will be called choice and the default value will be random. I would also like to add a readable version so I create a string variable that is called entry. And inside of the ontick function we will check if the choice is equal to zero. That is the default value. And if that is true, we set the entry to random for the other entries in our list it is very similar. We always check for the value, we check for a value here and assign an entry type to our entryle variable. To check what is going on, we need to add a comment statement that will output the entry and the choice values directly on our chart. Usually you would add a few more functions here to handle all the different entries. But this is just to show how you can use enumerations as input variables. So for this simple example, this is enough, 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 videos or maybe even the Premium Course on our website might be interesting for you. That’s also where we have a link for some video courses that also contain those source code files that you can download. If you don’t want to type all that stuff. For now, please 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 we pick an empty live chart. Please navigate to the file called simple multiple input and drag it on your chart. And here’s our choice box. We can pick one of the values that we have defined. 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, please let me know.   So let’s pick a value here and click on, OK! And when the next day comes and we should see that we have picked the EMA value, that happened right now, the value for the choice is one. Now you can press F7. Change the value here, so let’s pick the ADX entry, click on OK, and right away we have a new value here for the entry and for the choice. So our little Expert Advisor is working as expected.   And in this little video, you have learned how you can use an enumeration list of values to allow a user defined input without the need to recompile the code. 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