MQL4TUTORIAL.COM

MQL4TUTORIAL.COM

By MQL4TUTORIAL.COMBusinessInvesting
Download on the App Store

MQL4TUTORIAL.COM episodes

  • MQL4 TUTORIAL BASICS – 48 SIMPLE CHART OBJECT
    In this video we are going to draw an object on our chart for the opening period, you can’t see it right now but once the time on our computer reaches half-past ten in the morning you should see it on your chart. I will try to speed things up a little bit here and here is the object, so let’s find out how to draw that with mql4. To get started please click on the little icon here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple chart object, click on continue, continue and finish. Now you can delete everything above the on tick function and let’s also delete the two comment lines here. We will start with a string variable that is called end of opening period that will contain this string, it stands for half-past nine in the morning. Let’s calculate the current time, that is done by using time local, we pass time underscore seconds as a parameter and the built-in function time to string will convert this date time type to a string variable called current time and afterwards, we can use a function that is called string find, it will open the string current time and it will look for the string end of opening period. Remember this is the string here and the result will be stored into this integer variable and it will be minus one whenever the string is not found. I would like to draw an object that includes the highest of the last thirty candles so I use ihighest for the current symbol on the chart and the currently selected period on that chart. This parameter mode underscore high must be written all in capital letters and we want to have the highest of the last thirty candles starting with candle zero. Let’s repeat the whole process for the lowest candle. That is pretty similar. This time we use ilowest for the current currency pair on the chart and the currently selected period on that chart. This time we use mode underscore low and this one is also for thirty candles starting with the current candle zero. Let’s add an output on the chart. I will do that by using the comment statement and this one will output the text, current time followed by the current time that we have calculated here. And once a day we should see that it is half-past nine and that is the case when end of opening period found is not equal to minus one. And then we want to use object delete, the object with the name rectangle that will not exist the very first time but we destroy the old object from the day before. And afterwards, we can create a new object with the same name. The object type is obj rectangle in this case. If you mark this expression and press F1 you will see that there are also a lot of other objects. For example, you could use something like a label or a button. All those objects have different parameter settings. In our case this parameter stands for the current main chart, this is the time value for the current candle zero. We want our object to be drawn from the highest candle to the lowest candle and in this parameter we define that we want to have it for thirty candles. Let’s close this one, and we are almost done. Well, if this was a too fast for you or if you don’t know what all the code here does, maybe you want to watch one of the other videos in this basic video series first or maybe you are even interested in 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. I don’t see 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 can click on view, strategy tester or press control and r, please pick the new file simple chart object dot ex4, mark the visual mode here and start a test. Here we are! It’s nine in the morning. We should see the rectangle in a few seconds, exactly now and here it is! So in this little video,
    7 min
  • MQL4 TUTORIAL BASICS – 47 SIMPLE STOCHASTIC EA
    In this video we are going to create an expert advisor for this oscillator here, this is the stochastic oscillator and we are using it to create buy and sell signals so let’s find out how to do that with mql4. To get started please click on the little icon here or press F4 on your keyboard. Now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple stochastic ea, click on continue, continue and finish. Now you can delete everything above the on tick function and the two comment lines here. First, we want to create a string variable called signal but we don’t assign a value here because this what we are going to calculate later on. The next step is to define the expert advisor properties. We will use the built-in function istochastic, we have two lines here, one is the k line the other one is the d line. And we start with the current value for the k line. We need to pass a few parameters. The first parameter is for the current currency pair on the chart, the second one for the currently selected time period on that chart and the next three values here is what you see if you click on insert, indicators, oscillators, stochastic oscillator. We see we have a k period with a value of five, a d period with a value of three and the slowing value is also three and that’s exactly what we are using here. The next parameter mode underscore sma stands for the moving average method, this one is simple for simple moving average. Here we have another parameter, the zero value is used to define that we are using low high for the price field calculation. There is also something called close close but we will go with the default values here. So please click on okay, right-click into the chart, select template, save template and save it as tester dot tpl because this is the template that we are going to see in the next strategy test, you can overwrite the old one. So far so good! Let’s calculate the d value, this is pretty similar but we are using mode underscore signal in this case, that’s for the second line. We also want to calculate the same values for candle one, so now we create a variable called k one and d one. You can copy everything from the first two lines but you need to use another name for the variables and the last parameter is different because we use a one for candle one. If the current k and the current d value are above eighty – that is the case when both lines are above the dotted line here – and if that is the case we want to check if we had a crossover, so if the current d value is bigger than the current k value but the last d value was below the last k value that would be a sell signal so we assign sell to our signal. So let’s actually use sell signal here! For a buy signal, we would check if the current k value and the current d value are below twenty – and that is true if both lines are below this dotted lower line here – and this time we would check if the current d value is below the current k value and if the former d value was above the former k value. If this expression is true we would have a crossover and now we assign the word buy 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 that’s when we use order send to open a buy trade for ten micro lot. In the other case 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 function to output the text, the current signal is, followed by the calculated signal directly on our chart. So far so good! Well, if you don’t understand what all the code here does or if this was a little bit too fast for you, maybe you want to watch one of the other videos in this basic video series first or maybe even the premium course might be interesting for you. You can find that one on our website. For now,
    7 min
  • MQL4 TUTORIAL BASICS – 46 SIMPLE COMMODITY CHANNEL INDEX EA
    In this video we are going to create an expert advisor for this oscillator here, it’s the commodity channel index, usually, it’s used as a filter but we will use it to create buy and sell signals, 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 here you want to click on file, new file, expert advisor from template, continue, I will call this one simple commodity channel index ea, click on continue, continue and finish. Now you can delete everything above the on tick function and the two comment lines here. We start by creating an empty string variable called signal, we don’t assign any value here because this is what we need to calculate later on. The commodity channel index can be calculated based on the icci function that comes with mql4. It is calculated based on the current symbol on the chart and the currently selected period on that chart. Actually, this is the old way to describe it. We could use underscore symbol and underscore period, and the result is calculated based on fourteen candles. In mql4 the default value seems to be price typical, we could use the close price so let’s actually do that and use price underscore close – all in capital letters –, the last value here is for a shift, we don’t need it so let’s set that to zero. And when the icci value is above one hundred – that would be the case when the signal line here is above the upper dotted line – we want to sell so we assign sell to our signal. In the other case if the current icci value is below minus one hundred – that would be the case when the signal line is below the lower dotted line – we consider that to be a buy signal so we assign the word buy to our signal. And if we have a buy signal and the return value for orders total is zero, that would mean that we don’t have any open trades and in that case, we use order send to open a buy trade for ten micro lot. Otherwise, when the signal equals sell and we also have no open orders we use order send to open a sell trade for ten micro lot. Finally, we use comment to output the text, the current signal is and the calculated signal directly on our chart. That’s about it. 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 basic videos in this video series or maybe even the premium course on our website might be interesting for you. For now please click on the compile button, and if you don’t get any errors you can click on the little button here or press F4 to go back to Metatrader. And in Metatrader we click on insert, indicators, oscillators, commodity channel index, the default value here is to calculate the value for fourteen candles, I will change the typical price here to close price as we have done that in the code. Now let’s click on okay, right-click into the chart, select template, save template and save it as tester tpl, you can overwrite the old one because tester tpl is the template that is going to be used in the strategy test otherwise you wouldn’t see the commodity channel index here. Now let’s click on view, strategy tester or press control and r, please pick the new file simple commodity channel index EA dot ex4, mark the option for the visual mode here and start a test. Here we are! It started right away with a buy signal so our little expert advisor is working and in this little video you have learned how to create an expert advisor for the commodity channel index that is able to open buy and sell trades and you have coded it yourself with a few lines of mql4 code. MQL4 Tutorial searches:mql4 get current commodity
    6 min
  • MQL4 TUTORIAL BASICS – 45 SIMPLE SAR SELL TRAILINGSTOP
    In this video, we are going to create an sar based sell trailing stop, actually, this is an improved version of the previous video, I have confused a few words in the last one so let’s find out how to do that with mql4. To get started please click on a little button here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on file, new file, expert advisor from template, continue, I will call this file simple sar sell trailing stop, click on continue, continue and finish. Now you can delete everything above the on tick function and the to comment lines here, first, we need to create a variable called sar value and inside of the on tick function we want to open a test sell position in case we don’t have an open position. To check that we want to know if the return value for orders total is zero and now we check if the sar value is above the bid price. I messed that up in the first video, here I was looking for the ask price and the ask price, of course, is relevant for buy orders so if we have no open orders and the current sar value is above the bid price we would use order send to sell ten micro lot. To calculate the sar value we use the included function isar that comes with mql4 for the current symbol on the chart and the currently selected period on that chart and these values here is what you see if you click on insert, indicators, trend, parabolic sar. We have a step value of zero point zero two and a max value of zero point two, so let’s click on ok, right-click into the chart, select template, save template and save it as tester dot tpl because this is what we will see in the next backtest. You can replace the old value, the last parameter here zero is for a shift value, we don’t use that so it is zero and if the current sar value is above the bid price we want to check the sar sell stop. In the previous video, I accidentally called this the check sar buy stop function, even it was for the sell stop, so let’s do the correct version now. The name of our customized function will be check sar sell stop, we will use a for loop to go through all the open orders and for each order we find we will use order select, select by position and find out if we have a trade. Mode trades is for the current trades and the pending orders while mode history would be for historical data, that means for closed and cancelled orders. Now we want to check if the current order symbol equals the symbol on our chart and we also want to find out if the order type equals op underscore sell or in other words if we have a sell trade and when it is a sell trade we want to know if the order stop loss is bigger than the current sar value or if the order stop loss is zero. If all those conditions are true we use order modify to modify the current order ticket, we don’t change the order open price but we change the stop loss to the sar value, the order take profit will remain unchanged, we don’t use any expiration and we also don’t need any color and finally we close all the loops here 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 check out one of the other basic videos in this video series or maybe even the premium course might be interesting for you but for now please click on the compile button or press F7, that should work without any errors and if this is the case you can click on the little button here or press F4 to go back to Metatrader. And in Metatrader we want to click on view, strategy tester or press control and r, please pick the new file simple sar sell trailing stop dot ex4, mark the visual mode here and start a test. And here’s our little expert advisor at work, we see that the trailing stop is working and in this little video you have learned how to code the sar sell trailing stop for Metatrader 4 and you have coded it yourself with a few lines of mql4 code.
    7 min
  • MQL4 TUTORIAL BASICS – 44 SIMPLE SAR BUY TRAILING STOP
    In this video, we are going to create a trailing stop that is calculated based on this indicator value here for the parabolic sar. You see that the trailing stop moves whenever one of those dots appears on the chart. So let’s find out how to code that 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 we click on file, new file, expert advisor from template, continue, I will call this file simple sar buy trailing stop, click on continue, continue and finish. Now you can delete everything above the on tick function and the two comment lines here. We start by creating a global variable called sar value and inside of the on tick function we want to open a test position, you wouldn’t do that on a real account but in our case we need to open a position or we cannot set a trailing stop. So if orders total returns a value of zero – in other words we don’t have any open orders – and if the sar value is below the bid price we use order send for the current symbol on the chart and open a position for ten micro lot. Afterwards, we want to calculate the sar value that is done by using the integrated isar function that comes with mql4 for the current symbol on the chart and for the currently selected period on that chart. And these two parameter values here that’s what you see if you click on insert, indicators, trend, parabolic sar, here we have a step value of zero point zero two and the max value of zero point two, so let’s go with the default values here. And now we right-click into the chart, select template, save template and save it as tester dot tpl, you can replace the current one. And now that we have finished the definition we want to check if the current sar value is below the bid price – that is the case when the dots are below the candles – and in that case we want to check our sar buy stop function, that function doesn’t exist so far so we need to create it now. Our custom function will not have any return values so it is a void function, it is called check sar buy stop, we start by using a for loop to go through all the open orders and positions, afterwards we want to select an order for the current counter value, we use select buy position and mode trades here. We also want to know if the order symbol equals the symbol on the chart and if that is the case we check if the current order type equals op buy – or in other words if it is a buy trade – and only if the current order stop loss is below the current sar value we use order modify for the current order ticket to adjust the stop loss to the current sar value. We leave all the other parameters unmodified. Let’s close the loop and the function here and that’s about it. Now you can click on the compile button here or press F7, you shouldn’t get any errors here but if this was too fast for you or if you don’t understand what all the code here does you maybe want to watch the other videos in this basic series first or maybe even the premium course on our website is interesting for you. If you don’t get any errors here and the compilation process is fine please click on the little button here or press F4 to go back to Metatrader. And in Metatrader you want to click on view, strategy tester or press control and r, please pick the new file simple sar buy trailing stop dot ex4, mark the visual mode here and start a test. Here is our expert advisor, let’s zoom into the chart and as soon we see dots appear below the candles we should also see a trailing stop, that happened right now, so our expert advisor is working as expected and now you know how to create a parabolic sar trailing stop in mql4 and you have coded it yourself with a few lines of mql4 code in the Metaeditor.
    7 min
  • MQL4 TUTORIAL BASICS – 43 SIMPLE IOSMA EXPERT ADVISOR
    In this video we want to calculate the value for this little moving average of oscillator indicator, we just have seen the first trade on our chart, trade signals are generated whenever this zero line here is crossed, so let’s find out how to calculate that with 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 file, expert advisor from template, continue, I will call this file simple iosma expert advisor, click on continue, continue and finish. Now you can delete everything above the on tick function and let’s also remove the two comment lines here, we start by creating an empty string variable called signal, we don’t assign any value here because we need to calculate that later on. To get the current value for the oscillator we use the built-in function iosma that stands for moving average of oscillator. The first parameter here is for the current chart, I have used null all in capital letters, you could also use underscore symbol, both values will work for the current chart you use. The second parameter here is for the time frame, let’s actually use underscore symbol for the currency pair and underscore period for the time frame. These three values here also appear here in the properties because if you click on insert, indicators, oscillators, moving average of oscillator you will see the same values here as default values. Twelve is the default value for the fast ema, twenty six is the value for the slow ema and nine is the default value for the macd sma, that’s exactly what we are using here. The values are calculated based on the close price and the last parameter here is the number of the candle, zero is the current candle and to find out if we have a crossover we now want to find out the value for candle one, that’s the candle before, and we assign that value to a variable called last iosma value because that makes it possible to check if the last value was below the zero line and if the current value is above the zero line, because that would mean that the zero line is crossed from below and that’s a buy signal so we assign buy to our signal. Otherwise, if the last iosma value was above the zero line and if the current value is below the zero line that would mean that we have crossed the zero line from above and now we want to sell, so we assign the word sell to our signal. So if our signal equals buy and if the function orders total returns a value of 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 equal sell and we 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, it will output the words, the current signal is, followed by the calculated signal. Okay, that’s it. If you don’t understand what the code here does or if this was too fast for you, you probably want to watch one of the other videos in this basic video course or maybe even the premium course on our website is interesting for you, for now, you can click on the compile button here or press F7, that should work without any errors and if that is the case you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader we click on insert, indicators, trend, oscillators, moving average of oscillator, we want to go with the default values, click on ok, here is the oscillator, now let’s right-click into the chart, select template, save template and save it as tester dot tpl, you can override the default value because tester dot tpl is what is going to be used in our strategy tester, so let’s click on view, strategy tester or press control and r, pick the new file simple iosma expert advisor dot ex4, enable the option for the visualization here and start a test. Here we are! This is the expert advisor,
    7 min
  • MQL4 TUTORIAL BASICS – 42 SIMPLE Accumulation Distribution EA
    In this video we are going to calculate this little accumulation distribution oscillator value and use it as a filter for a simple moving average, so let’s find out how to do that with mql4. To start please click on the little button here or press F4 on your keyboard, now you should see the Metaeditor window and here we click on file, new, expert advisor from template, continue, I will call this file simple iad ea, click on continue, continue and finish. Now you can delete everything above the on tick function and the two comment lines here, we start by creating a signal string, this one will be empty because we need to calculate the current signal, we also want to calculate a moving average that is done by using the ima function, in this case we calculate the simple moving average for twenty candles, we have done that before so maybe you want to watch the previous videos in this basic series and on top of that simple moving average I want to use the accumulation distribution oscillator as a filter, so let’s also calculate that one, that is done by using the iad function for the current symbol on the chart and for the currently selected period on the chart, the last value here is for a shift, we don’t use that because first, we want to calculate the value for the current candle zero but afterwards we want to calculate the accumulation distribution value for the candle ten candles before. Now let’s create an entry condition. First I want to know if the current ask price is above the moving average value, that is the case whenever the candles are above the green line here and on top of that I want to know if the current value for the oscillator is bigger than the last value for ten candles before, and that would be true whenever the oscillator values are rising and in that case we have a buy signal, so I assign the word buy to our signal, otherwise if we have a downtrend, that would be the case when the bid price is below the moving average so basically when the candles are below the green line here. And I also want to know if the current accumulation distribution value is below the one for ten candles before, that is the case when the oscillator line goes down and if this is true I assign the word sell to our signal. Now if the signal equals buy and orders total equals zero, that means that we have an uptrend, a buy signal and no open orders, we use the order send command to open a buy trade for ten micro lot and if the signal equals sell and we also have no open orders that’s when we use order send to open a sell trade for ten micro lot. And finally we use the comment statement to output the current iad value followed by the calculated value and in a new line the signal that might be buy or sell and that’s about it. Now if this all was too fast for you or if you don’t understand what is going on with all that code, maybe you want to watch the other videos in the basic series or maybe even the premium course is interesting for you, you can find that one on the website, for now, please click on the compile button or press F7, you shouldn’t get any errors here and if that is the case you can click on a little icon here or press F4 to go back to Metatrader. And in Metatrader we want to use a little trick, first we click on insert, indicators, trend, moving average, here we pick a period of twenty candles, the shift value is zero, we want the simple moving average that is calculated based on the close price, so let’s click on ok, and here is the sma line, let’s repeat the same thing, this time insert, indicators, volumes, accumulation distribution, we go with the default values here so let’s click on ok, now your chart should look like this, so let’s save that for the strategy tester by right-clicking into the chart, please select template, save template. Now we want to save that file as tester dot tpl, you can override the old one. To start the backtest please click on view, strategy tester or press control and r,
    7 min
  • MQL4 TUTORIAL BASICS 41 SIMPLE SELL BREAKEVEN STOP
    In this little video, we are going to find out how to set a breakeven stop for sell trades, this breakeven stop will be placed whenever the price runs into our direction, so let’s find out how to set the breakeven stop with 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 from template, continue, I will call this file simple sell breakeven stop, click on continue, continue and finish. Now you can delete everything above the on tick function and the two comment lines here. First, we want to use orders total to find out if we have no open orders, that would be the case if the return value is zero and if that is the case we want to open a sell ticket, that is a test position because we need an open position to set the breakeven stop. You wouldn’t do that on your real account but for the strategy test we use order send to open a sell trade for ten micro lot and afterwards we want to check if we need to set a breakeven stop for our sell trade, that will be done by calling a function that is called check sell breakeven stop, it doesn’t exist so far so we need to code it now. Our function will not have a return type and we use a for loop to go through all the open orders, we count down from orders total until we have no orders left and for each of the orders we use order select to find out if it’s a current position, that is done by using order select and the parameter mode underscore trades. Mode trades is for open and pending orders while mode history is for closed and cancelled orders. In the next step we check if the order symbol equals the current symbol on the chart and we also want to find out if the order type equals op sell, in that case, it’s a sell trade and we want to set a breakeven stop only if the current order stop loss is above the order open price and finally I would like to know if the current bid price is at least thirty points below the order open price and only if all those conditions are true we want to use order modify for the current order ticket with the current order open price to set the breakeven stop six points below the order open price. We will not change the order take profit value here, we don’t need a time for expiration and we don’t need a color and that’s about it. We just need to close a few loops here and the function. Well if this was too fast for you or if you don’t know what all the code here does maybe you want to watch the other videos in this basic series first or maybe even the premium course on the website is interesting for you, for now please click on the compile button or press F7, we don’t have any errors and if that is the case you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader, we click on view, strategy tester or press ctrl and r, please pick the new file simple sell breakeven stop dot ex4, mark the visual mode here and start a test. Here we are! And in a few seconds, we should see the first breakeven stop appear on our chart, so our little expert advisor is working and in this little video you have learned how to place an automated breakeven stop for sell trades and you have coded it yourself with a few lines of mql4 code.
    6 min
  • MQL4 TUTORIAL BASICS – 40 SIMPLE BUY BREAKEVEN STOP
    In this video we want to find out how to set a breakeven stop, that’s the red line here, actually, it’s a little bit above the buying price so let’s find out how to do that with mql4. To get started please click on the little icon here or press F4 on your keyboard, now you should see the Metaeditor and here you want to click on file, new, expert advisor from template, continue, I will call this file simple buy breakeven stop, click on continue, continue and finish. Now you can remove everything above the on tick function and the two comment lines here, we start by checking if we have no open orders, that would be the case if the function orders total delivers a return value of zero, and if that is the case we want to open a test position, you wouldn’t do that on a real account but for the strategy tester we need an open position so that we can set the breakeven stop. We use order send to open a buy trade here and afterwards we want to check if the breakeven stop for the buy trade is okay. So far this function does not exist so we need to code it now, our custom function does not return any value, it is called check buy breakeven stop, we use orders total to get the number of all the orders and this loop here will count down until there are no orders left, we check if the selected order is actually an open position, we do that by using order select for the current number of the position, we use select by position – all in capital letters – and we use mode underscore trades. If you mark that and press the F1 key you will learn that mode underscore trades will be used to find open and pending orders, while mode history would be used if we need cancelled and closed orders, so if we have an open position we want to check if the order symbol actually is equal to the currency pair on our chart, and we want to know if the order type equals op underscore buy and if that is the case we actually have a buy position. We also want to know if the order stop loss is below the order open price because it doesn’t make much sense to set a breakeven stop when the current stop loss would be far above the open price and finally we need to check if the current ask price is above the order open price – in my case actually I want to set the breakeven stop when it’s thirty points above the open price – and only if all those conditions are true we want to use order modify to move the stop loss to four points above the open price for the current order ticket that was opened for the order open price, we set the stop loss to order open price plus four points, the order take profit will remain unchanged, that’s also true for the last two parameters, we don’t have an expiration value so we set it to zero, and we use clr underscore none because we don’t need any color, please don’t forget to set two curly braces here, one is to close the for loop and the other one to the function and that’s about it. If you don’t know what all the code here does or if this was too fast for you maybe you want to watch the other videos in this basic video series or maybe even the premium course on the website is interesting for you, for now, please click on the compile button or press F7, you shouldn’t get any errors here, we only have one warning, we could check the return value for order modify but for this simple example we don’t need to do that, so if you don’t have any errors please click on a little button here or press F4 to go back to Metatrader. And in Metatrader we click on view, strategy tester or press control and r, please pick the new file simple buy breakeven stop dot ex4, mark the visual mode here and start a test. So let’s zoom into the chart, we have opened a buy trade and here comes the breakeven stop, so in this little video, you have learned how to automatically set a breakeven stop once your buy trade is going into the right direction and you have coded it yourself with a few lines mql4 code.
    7 min
  • MQL4 TUTORIAL BASICS – 39 SIMPLE CHART LABEL
    In this video we are going to create a simple dynamic label that will be placed on the chart, it shows the current bid price and as soon as the price changes here, the label will also change, so let’s find out how to create something like this 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 from template, continue, I will use the name simple chart label, click on continue, continue and finish. Now you can delete everything above the on tick function and the two comment lines here, we start by creating an object that is done by using object create, this is the name of the object, I will call it bid because it will show the bid price, this is the type of the object, in our case it’s a label and the last three parameters here are used to define the window, we use the main chart, we don’t have to set a time and we don’t need to set a price, so that’s it for the object create statement. We can use object set to set the label for the bid price, it should appear in one of the four corners and we use corner one, let’s mark that and press F1, these are different types of objects, it uses this enum base corner, you could use something like corner left upper, let’s actually use corner right upper, that should be equal to one, that’s the return value for this corner here, okay you see that the bid price label is not right in the corner and that’s because we can set a distance, this is once again the name of the object, this is the setting for the x distance, and I would like to have a distance of thirty pixels to the right side of the window, and let’s also use object set to set a distance for the height, so this is sixty pixels from the top and that’s about it. This is very short but if you don’t understand what the code does or if this was too fast for you, maybe you want to watch the other videos in this basic series or maybe the premium course that you can find on the website might be interesting for you, for now, we can click on the compile button, you shouldn’t get any errors or warnings here and if that is the case you can click on the little button here or press F4 to go back to Metatrader. And in Metatrader we pick an empty chart, here is the new expert advisor that we have created, if you don’t see it you can right-click anywhere and choose refresh, now let’s drag that expert advisor on the chart, click on ok and you see that something is appearing here, it’s called label, it actually shows the bid price but I would like to have a real output and to do that we need to set the text for the label, that is done by using object set text for the object with the name bid, the text will be bid price and we use this expression double to string, to convert the bid price into a string value with the right number of digits behind the dot. I use twenty for the font size, this is the font type and this is the color, so let’s re-compile the code and actually our label has changed, I can use green instead, re-compile the code and now we have a green label, let’s try another font type here, I like impact and when our re-compile and switch to Metatrader now we have a different font type and that’s about it. So in this little video, you have learned how to create a dynamic object label right on the chart and you have coded it yourself with a few lines of mql4 code. MQL4 Tutorial searches:https://mql4tutorial com/mql4-tutorial-english/mql4-tutorial-basics-39-simple-chart-label
    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