MQL4TUTORIAL.COM

MQL4TUTORIAL.COM

By MQL4TUTORIAL.COMBusinessInvesting
Download on the App Store

MQL4TUTORIAL.COM episodes

  • MQL4 TUTORIAL BASICS – 79 SIMPLE COLOR CHANGER
    In this video, we are going to create an expert advisor that is able to change a lot of colors for different objects right on the chart, so let’s find out how to do that with mql4. To get started please click on a little icon here or press the F4 key on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple color changer, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. In this simple example, we are going to change the color whenever the close price for the candle before is below the close price for the last candle and if that is true we want to start by setting the color for the bull candles so that’s the color of the body inside of the candles and we use chartsetinteger for the current chart, the property we want to select is chart underscore color underscore candle underscore bull and I would like to set it to green, we have a lot of different color options. All these colors here are available. Well, you might wonder why we use chartsetinteger instead of something like chartsetcolor. Actually, we could use a number like a twenty-two here and when we now compile the code this wouldn’t give us any errors but actually clr green is better to read, so this was the body color for the bull candles. Let’s repeat that for the bear candles. Everything is the same except for the property value here. I would also like to set the outer color and this is the property that is called chart color chart up, let’s also pick green here and we are going to repeat that for the bear candles, that is the property chart color chart down. One more of those, this one is called chart mode and now I can define what type of candle I would like to see on the chart because you can either pick candles, bars or a line chart. We are going to use chart underscore bars here and if you mark that and press F1 you will see that each of those candle types can be picked. Now we are going to set the grid to visible that is done by setting the chart show grid property to true. Let’s also change the foreground color with chart color foreground, we want to set it to yellow and of course, you can also set the background color that is chart color background and I’ll set it to black. Now let’s repeat the whole thing because when the close price for candle two is bigger than the close price for candle one I would like to see other colors. I just will copy and paste it here, basically, it’s all the same, of course, you can not only set properties you also can get properties. For example the max price and the min price on the chart that is done by using chart get double for the current chart, we are going to use chart price max and this last parameter here is for the current sub window, for example, if you would like to insert an oscillator here this would be sub window zero and this would be sub window one and we are going to chose the main window and get the max price and the min price, so let’s add a chart output here by using the comment statement. This will output the text and the values for those properties 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 first or maybe even the premium course on our website might be interesting for you. This was a suggestion from a premium course member and if you are already a premium course member and have an idea for a video like this one please send me an email. For now, please click on the compile button or press F7 on your keyboard, you shouldn’t get any errors and if this is the case you can now click on the little button here or press F4 to go back to Metatrader. And in Metatrader, we want to click on view, strategy tester or press control and r, please pick the new file, simple color changer dot ex4,
    7 min
  • MQL4 TUTORIAL BASICS – 78 SIMPLE MULTI CURRENCY ORDER
    In this video, we are going to create an expert advisor that is able to trade randomized signals on multiple currency pairs in one chart, so let’s drag the expert advisor onto a live chart, I need to allow auto trading, I click on okay and now we see that it is able to open multiple positions on one chart, so let’s find out how to do that with mql4. To get started please click on a little icon here or press the F4 key on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple multi-currency order, 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 a statement to calculate the ask price, this is very uncommon for mql4, it’s what we usually do in mql5 and to calculate an ask price you can use symbol info double, in this case for the current symbol on the chart, the second parameter here is symbol underscore ask – all in capital letters – and with normalize double and underscore digits I am going to cut the number of digits behind the dot to automatically fit the currency pair because we have currency pairs with three digits behind the dot and others with five digits behind the dot. And that’s what we do here. Well usually we just would take the ask price as it is but in this case we are going to open multiple positions for different currency pairs and therefore we need to find a way to calculate the ask prices for the other currency pairs, in this case for the US dollar against the Canadian dollar and this is how we can do it, in this case, I have exchanged the first parameter for the currency pair I want to trade. Please make sure that it matches what you see here in the market watch because some brokers use suffixes so let’s make sure that you get it right. Now let’s repeat that for the second currency pair. This is almost the same, except for the name of the variable and the currency pair string. Of course, we can do the same for the bid price, in this case, its symbol info double for the current symbol on the chart and we use symbol underscore bid and now we repeat that for the US dollar against the Canadian dollar. I have called this one USDCADBid and I have exchanged the first parameter and you might have guessed it we also do it here for the British pound against the US dollar. Now that we have all those bid prices and ask prices let’s create a string variable called signal. We are not going to assign a value here because this is going to be calculated now. In this case, we are going to use random entries, so I use mathsrand and gettickcount to create an initial value because gettickcount returns the number of milliseconds since we have started the system, this is a unique value and this whole expression will make sure that we do not get the same random values all the time and to calculate the actual random number we are going to use mathrand. This looks almost like the one we used before except the s in the middle and mathrand is used to calculate pseudorandom integer values between zero and thirty-two thousand seven hundred sixty-seven and this suffix here, percent two will give us two random numbers, so whenever the random number equals zero we would consider that to be a buy signal, so we assign the word buy to our signal. And if the random number equals one we consider that to be a sell signal so now we assign the word sell to our signal and whenever we have a buy signal and when orders total equals zero – that would mean we have a buy signal and no open orders – that’s when we are going to send three orders for the current symbol on the chart, the British pound against the US dollar and for the US dollar against the Canadian dollar. In the other case if the signal equals sell and we also have no open orders I would like to use order send to sell for the current symbol,
    9 min
  • MQL4 TUTORIAL BASICS – 77 SIMPLE AWESOME INDICATOR
    In this video, we are going to calculate this awesome oscillator here and we will also be able to define user signal values for the entries, 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 awesome indicator, 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 variable, this input modifier will make it possible to let the user change the property in the expert advisor settings, it’s a floating type variable, we will call it signal value and this is the initial value and it can be changed by the user inside of the expert properties later on without recompilation. Let’s continue by creating a string variable called signal, we will not assign a value here because that needs to be calculated. And to get the current value for the awesome oscillator we use the included function iao, this one comes with mql4 and it has only three parameters. The first one is for the current symbol on the chart, the second parameter is for the period that we have selected on that chart, and the third parameter here is for the shift, we don’t use that so it is zero and that’s all to get the basic value here but to avoid confusion about rounding problems I would like to convert it to a better format so I will use a function called normalize double, the first parameter here is the value that we have calculated, the second parameter here is for the number of digits behind the dot so our awesome value here will be better to read in the comment statements. Now let’s define the entry conditions if the current awesome value is bigger than the signal value that we have defined here we would consider that to be a sell signal, so we assign the word sell to our signal. In the other case if the awesome value is below zero minus the defined signal value – that would be the negative value here – and if this expression is true we want to assign the word buy to our signal. So whenever we have a buy signal and the return value for orders total is zero – that would mean that we have no open orders and we want to buy – and that’s when we use order send to buy ten micro lot. In the other case if the signal equals sell and we have no open orders that’s when we want to sell and now we use order send to sell ten micro lot. Finally, we use the comment statement to make some outputs on the chart I would like to see the awesome value on the chart please notice that I used double to string to prevent that we see exponential expressions here and the last two things on the chart will be the signal value for buy and for sell trades so that’s about it. If this was too fast for you or if you have no idea what all the code here does maybe you want to watch one of the other videos in this basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button here or press F7 on your keyboard, you shouldn’t get any errors and if that is the case you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader please open an empty chart and click on insert, indicators, Bill Williams, awesome oscillator, we will go with the default values here, so let’s click on okay, here is the oscillator and now please right-click into the window and select template, save template and save it as tester dot tpl, you can override the current value just tester tpl used in the strategy tester, otherwise, we wouldn’t see anything, so now that we have done that please click on view, strategy tester or press control and r, select the new file, simple awesome indicator dot ex4, mark the option for the visual mode here and start a test. Here we are!
    8 min
  • MQL4 TUTORIAL BASICS – 76 SIMPLE ACCOUNT INFORMATION
    In this video we are going to create an expert advisor that is able to show account-related information directly on our chart, 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 account info, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. We start by getting the account server that is done by using the function account info string, the used parameter is account underscore server, and in my case, it returns the RoboForex ProCent value here. The next parameter is for the used account currency, you can get that by using account info string account underscore currency and in my case, it’s US dollar. The next string is for the account name, like before you would use account info string and this parameter account underscore name and in my case, the account name is Raimund Bauer. The next one is a little bit tricky because the account trade mode is on integer value so it would return a number and whenever I see numbers on the chart that represent something that could be a string value I prefer to use the string value, so let’s create a variable for the readable account trade mode because if you mark that and press F1 you will see that the return type here can either be a demo, a contest or a real account. Demo account equals zero, contest account equals one and the return value two would be a real account. And therefore if the account mode equals zero the readable account trade mode should be demo account. If the return value is one I want to see the text contest account on the chart and in case the value equals two that would be a real account. Let’s continue with the account info integer value for the account login. If you use account underscore login it will return the account number. The next one is for account underscore company, this also is a string value and in my case, it returns RoboForex Ltd. Now let’s get the account leverage, this is account info integer for account underscore leverage and because this is an integer value I see the output five hundred here, actually it would be 1 to 500. Now let’s get the number of allowed orders and this is a value you can find behind account underscore limit underscore orders. My account allows me to have 200 orders. We will continue with the free margin, this is the first double value so we use account info double here and it will return the value for account underscore margin underscore free. The next two values are actually boolean values, so you would probably expect that we use something like account info bool but actually it’s account info integer. Account underscore trade underscore allowed will give us the return value if we are allowed to trade at all and account underscore trade underscore expert will return the value if we are allowed to trade with an expert advisor, in my case both values here return a one and if you mark bool and press F1 you will see that it can return true or false and the numeric representation is one for true and zero for false, so I’m allowed to trade manually and with expert advisors. Now we have all the values and we want to see them on the chart, so we use a comment statement and create a formatted output here. Please keep in mind to use the readable account trade mode here and that’s about it. Well, if this was too fast for you or if you have no idea what all the code here does maybe you want to watch one of the other videos in this basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button here or press F7 on your keyboard, you shouldn’t get any errors and if this is true please click on a little button here or press F4 to go back to Metatrader.
    8 min
  • MQL4 TUTORIAL BASICS – 75 SIMPLE TIME FILTER
    In this video we will create a filter that is going to allow or disallow trading based on the current time 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 time filter, click on continue, continue and finish. Now you can remove everything above the ontick function and the two comment lines here. We start by creating an input string for the start trading time, this one is set to 9:00 am but I will change it to 1:00 am in this case, the input modifier will allow any user to change the values in the expert properties tab without any recompilation, we also need a stop trading time, this is set to 10:00 am so trading will be allowed between 1:00 am and 10:00 am, obviously we need to find out if the current time is between those two timestamps, so let’s create a variable current time, and finally, we want to allow or disallow trading that’s done with this variable, trading is allowed, it’s a bool so it can either be true or false. Inside of the ontick function, we start by getting the current time that’s a datetime variable and we are using the function time local, so let’s mark that and press F1 and we learn that it returns the local time of the computer where the client terminal is running so that’s your PC and in the next step we use time to string to convert the time that we have calculated, we want to use a special format called time underscore minutes, let’s mark that and press F1 and now you see that we will get this format, hours and minutes divided by a colon. To check for the entry conditions we are going to use a function that is called check trading time and if the return value is true we consider to open a position, this function doesn’t exist so far so we need to code it later on. The second entry condition will be if orders total returns a value of zero so this is true when we have no open orders or no open positions and if both conditions are true we are going to use order send to buy ten micro lot. Obviously, you wouldn’t do that on a real account you would add other things like entry signals from an indicator or something like that but for this simple example, it’s good enough. Let’s add a chart output the comment statement will output if trading is allowed, the current time, the start trading time and the stop trading time that we have defined but now we need to create this function here, it is called check trading time and it’s boolean so it can either return true or false. In mql4 that will be represented by zero for false and one would be true and to set the trading allowed variable we are going to look into the current time, we are using string substring to find a certain value and the value that we are looking for is the start trading time, let’s mark that and press F1. String substring has an original string and we are going to look for the value inside of the string, the starting position in our case is zero, the second parameter is for the length of the substring, in our case it’s five and if we can find the defined start trading time within the current time we will set the trading is allowed variable to true. Otherwise, if the current time contains the defined stop trading time we would set the trading is allowed variable to false. Finally, we use the return statement to return the trading is allowed result to the main function and that’s about it. If this was too fast for you or if you have no idea what all the code here does maybe you want to watch one of the other videos in this basic video series first or maybe even the premium course on our website might be interesting for you. This was another suggestion that came from a premium course member and if you are already a premium course member and have an idea for a video like this one please let me know. For now,
    8 min
  • MQL4 TUTORIAL BASICS – 74 SIMPLE ENVELOPES INDICATOR
    In this video we are going to create an expert advisor that is able to calculate 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 indicator, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. First, we want to create a string variable called signal, we don’t assign any values now because we are going to calculate that later. And now we are going to use the included function ienvelopes to calculate the lower band. This indicator has two bands, a lower band and a higher band so we need to use two different buffers here and for the lower band we use the current symbol on a chart and the currently selected period on that chart, we want to calculate the indicator based on fourteen candles, we use mode sma for simple moving average, this zero here is the shift value, we don’t want to use a shift value, the result should be calculated based on the close price and this value here is the so-called deviation value, if you right-click on the properties for the indicator you will see that you can change the value here. The bigger the value the fewer signals you will get and I decided to use zero point zero five in this case. This parameter here is for the buffer. So what is a buffer? If you mark ienvelopes and press F1 you will see that the mode parameter here can be used for different things, two is for the lower and one is for the upper band so let’s actually replace that with mode lower, here we are and the last parameter is for the current candle. To calculate the upper band we do the same, this is all pretty much the same code but this time we are going to use mode upper and if the close price for candle one is below the lower band we would consider that to be a buy signal so now we assign the word buy to our signal. Otherwise, if the close price for candle one is above the upper band we would consider that to be a sell signal and now we would assign the word sell to our signal. And if our signal equals buy and the return value for orders total is zero – that would mean that we have no open orders and a buy signal – and in that case, we use order send to buy ten micro lot. Otherwise, if the signal equals sell and we have no open orders we would use order send to sell ten micro lot. Finally, we use the comment statement to output the values for the upper band, the lower band and the signal and that’s about it. Well, if this was too fast for you or if you have no idea what all the code here does maybe you want to watch one of the other videos in this basic video series or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button or press F7, you shouldn’t get any errors here and if this is the case please click on the little button here or press F4 to go back to Metatrader. And in Metatrader we need to change the template otherwise we wouldn’t see the indicator so let’s open a new chart window, click on insert, indicators, trend, envelopes, pick a period for fourteen candles, the ma method should be simple, apply to the close price and the deviation value in this example is zero point zero five, of course, you could change that but please keep in mind that you also have to change it in the source code. Now let’s click on okay, here is the indicator and now we want to right-click, select template, save template and save it as tester dot tpl, you can overwrite the current one because tester dot tpl is what you will see in the next strategy test. If you don’t see the strategy tester please click on view, strategy tester or press control and r, please pick the new file, simple envelopes indicator dot ex4,
    7 min
  • MQL4 TUTORIAL BASICS – 73 SPREAD FILTER
    In this video we are going to create an expert advisor that is able to allow or disallow trading based on the current spread, 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 spread filter, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. We start by creating an input variable, this one actually is adapted code from mql5, this modifier will allow the user to change the value without any recompilation, in our case we use an integer value for the max spread that is allowed and the first value that we are going to assign here is fifteen but we can change that later on without recompilation. Inside of the on tick function, we create a string variable for the signal but we don’t assign any values here. Let’s use mql rates to create a price array as I said this is adapted from mql5 to get the price data because mql rates stores the information about price, volume and spread. We use array set as series to sort the price array from the current candle downwards and then we use copy rates for the current symbol on the chart and the currently selected period, we start with candle zero and we want to copy the values for three candles and store them in our price array. And now we can use symbol info integer for the current symbol on the chart to calculate the spread for the symbol, we use symbol underscore spread – all in capital letters – and that will be our current spread, let’s add another string variable called spread filter and now we want to find out if the current spread is bigger or equal to the max spread that we have allowed if that is the case we assign the words, trading is not allowed to our spread filter. Otherwise, if the current spread is below or equals the max spread that we have allowed we assign the words, trading is allowed to our spread filter. Now let’s add a simple entry condition here if the close price for candle one in our array is bigger than the close price for candle two we would consider that to be a buy signal so we assign the word buy to our signal otherwise if the close price for candle one is below the close price for candle two in our price array we would assign the word sell to our signal and now we make it a precondition that our spread filter should equal, trading is allowed before we check for any entry signals and only if this is true we are going to check if the signal equals buy and if orders total equals zero if this is true we have no open orders and a buy signal so we use order send to buy ten micro lot. In the other case if the signal equals sell and we have no open orders we use order send to sell ten micro lot. Finally, we use the comment statement to output the current spread, the max allowed spread and the value for the spread filter. Well if this was too fast for you or if you don’t understand what all the code here does maybe you want to watch one of the other videos in our basic video series or maybe even the premium course on our website might be interesting for you. Actually, this video was another suggestion from 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 you shouldn’t get any errors here and if that is the case you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader we pick an empty chart, in this case on my demo account, now we can drag and drop the new simple spread filter onto the chart, here is the max value that we are going to allow, so let’s say the value should be four. Here is our little expert advisor at work, we can see that trading is allowed or not allowed based on the spread, in this case,
    7 min
  • MQL4 TUTORIAL BASICS – 72 SIMPLE TRIPPLE EMA
    In this video we are going to create an expert advisor that is able to calculate signals for three exponential moving averages, so let’s find out how to do that with mql4. To get started please click on a little icon here or press F4. Now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file, simple triple ema, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. We start by creating a signal variable that is a string variable but we don’t assign any value here because we are going to calculate that later. So let’s start with the first exponential moving average. I will call this one ema ten. To calculate it we use the integrated ima function that comes with mql4, for the current symbol on the chart and the currently selected period on that chart. I would like to calculate the exponential moving average for the last ten candles, I don’t use a shift value and I’m going to use mode underscore ema that stands for exponential moving average. The result should be calculated based on the close price for the current candle that is candle zero. Now let’s repeat the whole thing for the next moving average. This one is for fifty candles so it is called ema fifty and the only difference is that we are going to use fifty candles instead of ten candles and we also use a different variable name here. So let‘s repeat that one more time this time for the ema one hundred that is calculated for one hundred candles. Now that we have done that we are able to calculate the buy signal and that would be the case if the ema ten is bigger than the ema fifty and if the ema fifty is also bigger than the ema one hundred. If all these conditions apply we consider that to be a buy signal so we assign the word buy to our signal. Otherwise, if the ema ten is below the ema fifty and the ema fifty is also below the ema one hundred we would consider that to be a sell signal and now we assign the word sell to our signal. So if our signal equals buy and the return value for orders total is zero – that would mean that we have no open orders and a buy signal and in that case, we use order send to buy ten micro lot. Otherwise, if the signal equals sell and we also have no open orders we use order send to sell ten micro lot. Finally, we create a chart output that is done by using the comment statement. This will output the text, the current signal is followed by the calculated signal. So far so good. Well if this was too fast for you or if you have no idea what all the code here does maybe you want to watch one of the other videos in this basic video series or maybe you want to buy the premium course. You can find that one on our website. For now, please click on the compile button or press F7 on your keyboard, you shouldn’t get any errors here and if this is the case you can click on the little button here or press F4 to go back to Metatrader. And in Metatrader you want to pick an empty chart and click on insert, indicators, trend, moving average. We start with a blue moving average for ten candles, the method should be exponential and we want to calculate the result based on the close price, so let’s click on okay and here is the first moving average. Now let’s repeat that insert, indicators, trend, moving average, pick fifty candles, change the color and click on okay, here is the second moving average and one more time, this time for hundred candles, let’s make this one yellow, click on okay and here we are. Now right-click into the chart, select template, save template and save it as tester dot tpl, you can override the current value because tester tpl is what we will see in the next backtest so if you don’t see the strategy tester here please click on view, strategy tester or press control and r, please choose the new file simple triple ema dot ex4, mark the option for the visual mode and start ...
    7 min
  • MQL4 TUTORIAL BASICS – 71 SIMPLE ARROW SYMBOLS
    In this video we are going to create an expert advisor that is able to create random symbols directly on your chart, 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 arrow symbols, click on continue, continue and finish. Now you can delete everything above the ontick function and the two comment lines here. First, we want to start by calculating the ask price that can be done by using symbol info double for the current symbol on the chart, we use symbol underscore ask and with normalize double and underscore digits we make sure that we calculate the right number of digits behind dot because for some currency pairs you might need three digits while other currency pairs have five digits. And if you ask yourself why we are not going to use ask as we always do in mql4, well this is actually an example that can be used in mql4 or in mql5 so the code that we are generating will work for both versions of the Metatrader. Now let’s continue and repeat the whole thing for the bid price, everything is similar except for the name of the variable and we are going to use symbol underscore bid this time. I would also like to calculate a medium price by adding the ask price and the bid price and when we divide the result by two we will get the medium price. To create randomized symbols we need to use the random generator. To prepare it we use the function mathsrand if you mark that and press F1 you will learn that it sets the starting point for generating a series of pseudorandom integer values and as a parameter we pass the function gettickcount, this one will return a number of milliseconds that have passed since we have started our system and this is how we get a start value that is unique. Afterwards, we use mathrand, this time not with an s to calculate a random value within a special range. This is our range and we assign the result to our random arrow code that we are going to use to draw our symbols. Now let’s use object create for the current symbol on the chart, we want to create an object that is called my object and we use obj underscore arrow if you mark that and press F1 you will see that we can create lots of other object types but we are going to use the arrow because we can create different shapes with that kind of object type. This is the parameter for the chart window, chart window zero stands for the main chart, if you use an oscillator you will see a second chart below the candles but we don’t need that, so let’s draw the shapes inside of chart zero and I would like to use time current because that function will return the last known server time, that’s always the time for candle zero and the last parameter here is the medium price that we have calculated here, we are going to use that as an anchor point to draw the shape. And to get different shapes we now use objectsetinteger on the main chart zero for the object with the name my object and we want to change the object property arrowcode and set it to the random arrow code that we have calculated here. Objectsetinteger is also used to change the object property for the width, I will use a value of twenty to get bigger objects. And whenever the price changes I want to use objectmove to move our object and redraw it for the current time and the medium price. Finally, we need a chart output. We will use the comment statement to output the ask price, the bid price, and the medium price and that’s about it. Well, if you don’t understand what all the code here does or if this was too fast for you maybe you want to watch one of the other videos in this basic video series or maybe even the premium course on our website might be interesting for you. For now, please click on the compile button or press F7.
    8 min
  • MQL4 TUTORIAL BASICS – 70 SIMPLE BWMFI OSCILLATOR
    In this video we are going to calculate the Bill Williams Market Facilitation Index, that’s the oscillator here, so let’s find out how to do that with mql4. To start 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 bwmfi 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 don’t assign any values here. Afterwards, we use the included ibwmfi function that comes with mql4, we need to pass three parameters. The first one is for the current symbol on the chart, the second one is for the currently selected time frame on that chart and the last one is a shift value. If we mark the function and press F1 we learn that the shift value means that it is relative, so zero means that we are calculating the current bar, now let’s repeat that to calculate the last bwmfi value for candle one. Except for the variable name and the last parameter, everything else is the same. And now we can compare the values and if the current bwmfi value is bigger than the last value we would consider that to be a buy signal and that’s where we assign the word buy to our signal. Otherwise, if the current value is below the last value we would consider that to be a sell signal and then we would assign the word sell to our signal. And if our signal equals buy and the function orders total has a return value of zero – that would mean that we have no open orders and we have a buy signal – and that’s when we use order send to buy ten micro lot. Otherwise, if the signal equals sell and orders total is zero – that would mean that we have a sell signal and no open orders – and now we use order send to sell ten micro lot. Finally, we want to create an output on the chart, so we use the comment statement to output the text, the current signal is, followed by the calculated signal and that’s all. Well, if you don’t understand what all the code here does or if this was too fast for you maybe you want to watch the other videos in the basic video series first or maybe even the premium course on our website might be interesting for you, for now, please click on the compile button here or press F7 on your keyboard. You shouldn’t get any errors and if that is the case you can click on the little button here or press F4 to go back to Metatrader. And in Metatrader we want to open a clean chart, now please click on insert, indicators, Bill Williams and select the Market Facilitation Index, we will go with the default values and click on okay. Now you should see the oscillator in the chart below, please right-click into the chart, select template, save template and save it as tester dot tpl because this is the template that is going to be used in the strategy tester. You can overwrite the current value and if you don’t see the strategy tester below you want to click on view, strategy tester or press control and r. Please pick the new file, simple bwmfi ea dot ex4, enable the visual mode here and start a test. Here we are! The expert advisor is running, it’s creating buy and sell signals and we see that we have produced the first sell trade here. Usually, you would use an oscillator in combination with a trend indicator but in this little video you have learned how to calculate the Market Facilitation Index 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