MQL4TUTORIAL.COM

MQL4TUTORIAL.COM

By MQL4TUTORIAL.COMBusinessInvesting
Download on the App Store

MQL4TUTORIAL.COM episodes

  • MQL4 TUTORIAL – SIMPLE MODULAR EXPERT ADVISOR
    In this video we are going to create a simple modular system that can output the entry signal for different indicators. Right now we are treading the MACD entry signal, right now it says buy and when the line is crossed and the bars are drawn on the other side of the horizontal line it will say sell; now the signal has turned again and it wants to buy. Let’s stop this test and find out how we can create an Expert Advisor that can handle different entries without changing the source code of the main module. To do that please click on the little button here or press F4 in your Metatrader and now you should see the Metaeditor window and here we want to click on “File/ New/ Expert Advisor (template)” from template, “Continue”, this one will be called: “SimpleModule”, let’s click on “Continue”, “Continue” and “Finish” and now you can remove everything that is located above the “OnTick” function here and let’s also delete the two comment lines. The first thing we want to do is to include files. We are going to include external files that contain the function to find out if we have a buy or a sell signal. That can be done by using the include statement that is going to import the function within the “CheckEntry_IAC.mq4” file. Let’s open that file. This is it. It contains a function called: “CheckEntry” that will use the “iAC” function to create a sell signal or a buy signal and it returns the signal to our main module. In the “OnTick” function – remember this is the function that will be called whenever the price changes – we get a string signal from our external file so let’s create a string variable called: “signal” and the value will be calculated in a check entry function (CheckEntry). That function is located in our external file: “CheckEntry_IAC” and for this simple example we just want to create an output for the signal, so let’s use the “Comment” function to output the word: “signal:” followed by the calculated signal on our chart. Remember you will need to have the imported file “CheckEntry_IAC.mq4” in the same directory. All you need to tell MQL4 for is the correct path to that file. We have explained the IAC entry in another video. In our case we want to find out how to import an entry as an external module, so let’s click on the compile button here or press F7 and that worked without any errors and any warnings here so now I can click on a little button here or press F4 to go back to Metatrader. In Metatrader I want to use a little trick; let’s click on “Insert/ Indicators/ Bill Williams” and select the Accelerator Oscillator, go with the default values here, click on “OK” and here is the Accelerator template, so let’s right-click into the chart, select “Template/ Save Template” and save it as: “tester.tpl” because this is the template that Metatrader is going to use for the next back test. After you have done that please click on “View/ Strategy Tester” or press CTRL + R, now please select the “SimpleModule.ex4” file we have compiled, mark the option for the visual mode here and click on start. Now our Expert Advisor is producing buy or sell signals based on the Accelerator Oscillator, let’s stop the test here and now I go back into Metaeditor and I will exchange the entry file here and now I include the “CheckEntry_MACD.mq4” file. It basically does the same as the other entry but this time it uses the “iMACD” function to create a sell or a buy signal and return it to our main module. This entry is also explained in another video and now I need to compile the main module so let’s click on compile or press F7, that also work without any errors or warnings so I can click here or press F4 to go back to Metatrader. Let’s delete the Accelerator Indicator, click on “Insert/ Indicators/ Oscillators/ MACD”, go with the default values, click on “OK”. Here is our MACD Indicator so let’s right-click, save the template, again we use the “tester.tpl” file, click on “Save” and start another test with exactly the same Expert Advisor...
    7 min
  • MQL4 TUTORIAL – SIMPLE EMA STOCHASTIC STANDALONE EXPERT ADVISOR
    In this video, we are going to create an Expert Advisor that uses the Parabolic SAR and Stochastic Oscillator indicators to generate buy and sell signals in MetaTrader. Let’s see how we can do that. First, start the MetaEditor. You can do this by clicking on its icon or simply pressing the F4 key. We begin with the #include directive to import the Trade.mqh library. This library provides us with essential trading functions. Following this, we create an instance of the CTrade class named trade. This instance will be our primary tool for executing buy and sell orders. Next, we calculate the current asking price using the Symbol Info Double function with the parameters Symbol and SYMBOL ASK. This gives us the price at which we can buy. To ensure precision, we use the Normalize Double function, inputting the price and Digits to adjust the number of decimal places. Similarly, we determine the bid price using the Symbol Info Double function with the parameters Symbol and SYMBOL BID. This is the price at which we can sell. This price is also normalized using the Normalize Double function. We then set up an array named Price Info of type Mql Rates. This array will store our price data for specific time periods on the chart. Within the On Tick function, we sort our Price Info array using the Array Set As Series function to prioritize the latest data. We then fill this array with price data for the current symbol and time frame using the Copy Rates function. Here, we’re copying data for three candles, giving us a snapshot of recent price movements. The closing price of the most recent candle is then determined using the Price Info[0].close reference. We then call the Check Entry function. Inside this function, we use the Parabolic SAR indicator to check the current and previous values to determine if there’s a buy or sell signal. If the current SAR value is below the current price and the previous SAR value was above the previous price, it suggests a buy signal. Conversely, if the current SAR value is above the current price and the previous SAR value was below the previous price, it suggests a sell signal. Additionally, the Check Entry Stochastic function is used to refine our signals. This function checks the Stochastic Oscillator values. If the K line crosses the D line from below in an oversold area, it suggests a buy signal. If the K line crosses the D line from above in an overbought area, it suggests a sell signal. With these signals in hand, the code decides whether to execute a buy or sell trade. If both the trading signal and the filter signal return a buy and there are no open positions, the trade.Buy function is used to buy 0.10, equivalent to 10 Micro Lot. If both signals return a sell, the trade.Sell function is used to sell 0.10 Microlot. Once you’ve input all the code, press F7 to compile it. If this was too fast for you or if you don’t understand what all the code is doing, you might want to check out the Premium course on our website or watch one of the basic videos first. After a successful compilation, return to MetaTrader by pressing the F4 key or clicking on its icon. Once in MetaTrader, press Control and R to start the strategy tester. Select the Expert Advisor you’ve just created, enable the visual mode, and start a strategy test. You should then see the Expert Advisor in action on the chart. If you’re already a Premium course member and have an idea for a video like this one, please send us an email. By the end, you’ll have a deeper understanding of what you’ve learned and the Expert Advisor you’ve coded yourself with just a few lines of MQL code. Thanks for watching, and I’ll see you in the next video!
    4 min
  • How to code a standalone Bollinger Bands Expert Advisor
    Here is a detailed summary of the video The video starts with an introduction on how to automate the Bollinger Bands indicator to automatically open four trades for Metatrader 0:01. It shows that a first open position is already in place 0:13. The speed is slightly increased to demonstrate that it works 0:16. It is explained that the Bollinger Bands indicator was the indicator with which the first profits were made in automated trading 0:23. Next, it shows how to automate this indicator with MQL4 for Metatrader 0:32. This is done by clicking on the small button or pressing the F4 key on the keyboard to call up the Meta Editor 0:41. In the Meta Editor, a new Expert Advisor is created and named “SimplerBollingerBandsStandAloneEA” 0:55. Everything above the On Tick function is deleted, as are the two comment lines 0:64. A variable for the signal is created 0:71. Then it goes to the determination of the Bollinger Bands 0:86. It is explained that entry signals should be created whenever a candle closes outside one of the bands and a re-entry takes place 0:93. The Bollinger Bands are calculated with the built-in iBands function for the current currency pair on the chart and the period selected on the chart 1:09. This is calculated for twenty candles 1:20. It shows how to insert the Bollinger Bands in Metatrader by clicking on Insert, Indicators, Trend, Bollinger Bands 1:33. It explains how the actual order commands are executed. If the signal has the value “Buy” and the OrdersTotal function returns zero, i.e., if there are no open positions, then ten micro lots are bought 2:40. The same applies if a sale is to be made 2:77. Finally, it shows how to create a chart output. The comment command is used for this 2:94. The video ends with the explanation that in this short video, you have learned how to generate buy and sell signals for the Bollinger Bands and how to automatically trade the recognized signals with Metatrader four 3:83.
    6 min
  • MQL4 TUTORIAL – SIMPLE STANDALONE BOLLINGER BANDS EA
    In this video we want to create an automated Expert Advisor that is actually able to trade this Indicator; it’s the Bollinger Bands Indicator for 20 candles, actually it’s producing buy or sell signals directly on the chart. Whenever the candle close below the lower Bollinger Band that would be a buy signal and when we have a breakout on the other side that would be a sell signal. Now let’s find out how to create an Expert Advisor in MQL4 that is actually going to trade. To do that please click on a little button here or press F4 on your keyboard, now you should see the Metaeditor window and here you want to click on: “File/ New/ Expert Advisor (Template)” from template, “Continue”, I will call this file: “SimpleBollingerBandsStandAloneEA”, click on: “Continue”, “Continue” and “Finish”. Now you can remove everything that is above the “OnTick” function and the two comment lines here. First we need to create an empty string for the signal, it will be called: “signal” and we don’t assign a value because we are going to calculate that now. The Bollinger Bands Indicator has 3 different bands, we are interested in the upper band and the lower band, so we use the included “iBands” function for the current symbol and the currently on the chart selected period for 20 candles. If you look at the Bollinger Bands properties you will see that we use 20 candles, a shift value of 0, and the deviation’s value is 2. These are the default values that we are going to use here, the result will be calculated based on the close price. We use “MODE_LOWER” for the lower Bollinger Band (LowerBB) and “MODE_UPPER” for the upper Bollinger Band (UpperBB). The first one will be calculated based on candle 1 and now we do it again for the previous lower Bollinger Band (PrevLowerBB) and the previous upper Bollinger Band (PrevUpperBB) and this time we are going to use the values for candle 2. If the close price of candle 2 was below the lower Bollinger Band, so if close for candle 2 is less than the value for previous lower BB (PrevLowerBB) and if the close price for candle 1 is above the Bollinger Band – that would be the case when close 1 is bigger than lower BB (LowerBB) – that would be a buy signal and we would assign the word: “buy” to our signal. In the other case if the close price for candle 2 was above the upper Bollinger Band, so if close 2 is bigger than previous upper BB (PrevUpperBB) and if the close price for candle 1 is now below the upper Bollinger Band, so if close 1 is less than upper BB (UpperBB) that would be a sell signal and now we would assign the word: “sell” to our signal. And whenever the signal equals buy and ”OrdersTotal” equals 0 (zero) – that would be the case when we have no open trades – we want to send a buy order so we use the “OrderSend” statement and “OP_BUY” to buy 10 micro lot. In the other case if the signal equal sell and we have no open orders we use “OrderSend” to open a sell trade for 10 micro lot and last but not least we create a chart output that is done by using the “Comment” statement, it will output the word: “Signal:” followed by our calculated signal value. Okay. That’s it. Now you can click on the “Compile” button or press F7 on your keyboard, we don’t have any errors here, two minor warnings and if that is the case you can click on the button here or press F4 to go back to Metatrader. In Metatrader we use a little trick, we click on: “Insert/ Indicators/ Trend/ Bollinger Bands” here are our default values, we click on “OK” and now we save the template by right-clicking into the chart and selecting “Template/ Save Template” and please save it as: “tester.tpl” because this is the template that our back tester is going to use. After you have saved the template please click on “View/ Strategy Tester” or press CTRL and R and here you want to select the file: “SimpleBollingerBandsStandAloneEA.ex4”, enable the visual mode here and start a test. …and here is our little Expert Advisor at work,
    6 min
  • MQL4 TUTORIAL – SIMPLE IADX EXPERT ADVISOR
    In this video, we are going to talk about this Indicator here; it is the Average Directional Movement Index. Basically it’s a trend confirmation oscillator. Whenever the line here is rising that’s a trend confirmation; in our case for a short trend that is developing on the chart here and as soon as the IADX Indicator is falling, you see, the trend is interrupted here, now its rising again and we see an uptrend and when the IADX Indicator starts to decline – like in this case – the uptrend is interrupted. Now how can we create an Expert Advisor that is able can calculate the Average Directional Index in MQL4? To do that please click on the little button here or press F4 on your keyboard. Now you should see the Metaeditor window and here you want to click on “File/ New/ Expert Advisor (template)” from template. “Continue” (Next). I’ll call this one Simple IADX (SimpleIADX), click on “Continue” (Next) “Continue” (Next), and “Finish”, and now you can delete everything above the “OnTick” function and the two comment lines here. In the first step we want to create a signal, especially a string variable for the signal that will also be called signal and we don’t assign any value because we are going to calculate that later. Let’s calculate the IADX value (IADXValue) by using the function: “iADX” that comes with Metatrader 4. If you mark it and press F1 the reference will tell you that it needs some parameters; the first one is for the symbol on the chart, the second one for the time frame you use on the chart, the third one is for the period for the calculation. If you right-click on the Indicator and select “ADX properties” you will see that the period is 14 and we calculate the values based on the close price so that’s what we use here; 14 and PRICE_CLOSE for the close price. This parameter is for the buffer, so what is a buffer? You see the Indicator produces 3 lines here, let’s hit the pause button and the value for the blue line is 29.93555 – that’s exactly what you see here. The 2 dotted lines have a different value and you could calculate the 2 other values if you exchange buffer 0 with buffer 1 or buffer 2. The last parameter here is the shift value – that’s also 0. We want to calculate the current IADX Indicator for the current value (IADXValue) here and to get the last IADX value (LastIADXValue) we use exactly the same parameters accept we use a 1 to get the last value. If we use a 10 instead we would get the value for 10 candles before. If the IADX value (IADXValue) is higher now so IADX value (IADXValue) is greater than last IADX value (LastIADXValue) we want to output: “IADX is rising” so that’s what we assign to our signal variable. In the other case if the IADX value (IADXValue) is lower now so the current IADX value (IADXValue) is below the last IADX value (LastIADXValue) we assign the text: “IADX is falling” to our signal. Let’s create a screen output by using the “Comment” function. It would output the text; “IADXValue:”, the calculated value and in a new line a text: “Signal:” and the calculated signal we have created here or here. So, that’s basically it, let’s click on “Compile” or press F7 on your keyboard. That worked without any errors so now we can click here or press F4 to go back to Metatrader. In Metatrader we are going to use a little trick; please click on “Insert/ Indicators/ Trend/ Average Directional Movement Index”, click on “OK”, leave the parameters as they are, click on “OK” and now you should see the Average Directional Movement Index in a separate window below the candles and because Wikipedia says: “The ADX does not indicate a trend direction or momentum and is only used to calculate the trend strength” I will insert another Indicator for a trend. Let’s use a Moving Average for 14 candles because the ADX Indicator here is also calculated based on 14 candles, let’s choose an SMA (Simple Moving Average) this is apply to the close price, I use red and click on “OK”.
    7 min
  • MQL4 TUTORIAL – PROFITS IN A DRAWDOWN
    Trading can be like a high stakes game where the challenge is not just in making profits, but also in managing risks and dealing with losses. That’s true for the robot trading system too, a tool that seeks to reshape traditional trading by emphasizing resilience and reward. I began using this live trading system about a week ago, and as with all new things, it wasn’t a smooth start. I found myself in a drawdown situation which can be a nightmare for traders. Despite opening a sell position during a downtrend, the market didn’t move in the predicted direction. This meant my trading account didn’t see any profit for a week.   Some might see this as an inefficient system, but I’d disagree. Although there was no influx of profit, the noteworthy thing is that there were no losses either. This is due to the system’s intelligent algorithm that hedges positions, maintaining an equilibrium even when the market doesn’t behave as expected. On the 23rd of June, despite the week’s market turbulence, my account was at a net gain of a single dollar, which isn’t much, but when taken in context, it’s evidence of the system’s effectiveness in protecting against losses.   If you want to test the system’s operations and features, there’s a demo account available. It provides a risk free opportunity. The robot trading system stands out from the other trading systems. Thanks to its focus on resilience and risk management. It may not give you instant profits, but it offers a buffer against potential losses during volatile market phases, making it a safer option. For anyone looking for a reliable stress tested system that can withstand market unpredictability, the robot trading system is worth a look. Here’s the link and as always, thanks for watching. I’ll see you in the next video.
    2 min
  • MQL4 TUTORIAL – 135 SIMPLE LOT SIZE ROUNDING
    Let’s look at how to determine a lot size using the account balance in this video, as well as how to round the result up or down to fit. So let’s look at how to use MQL4 to accomplish that. Please use the F4 key or click this button in MetaTrader to do that. The MetaEditor should then appear. In this case, we choose File, New Expert Advisor from template, and then provide a name. I’ve previously completed this. Simple Lot Size Rounding is the name of my file, which is already pre-programmed. Ontick will be our first function to deal with. We want to first determine the account balance there. The position size is calculated depending on the account balance using the Account Info Double, Account Balance function. In this instance, we divide the gross balance value by 100,000. Additionally, we construct two variables—one rounded up and one rounded down—for the rounded numbers. With the aid of the corresponding function, which we ourselves program, we can calculate that. The determined lot size and the value for the decimal rounding are passed as parameters to the first function, which is called Round up, and the second, Round down. This should be rounded to the nearest whole number. We can output the final results in a more structured manner by using Normalize Double. Despite the fact that we have given two decimal places here, we can see that the first digit of our results is truncated. We then display the entire thing onto the chart using the Comment function. On to the actual functions now. We pass our input value to round up. That is both our rounding value and the position size that we previously passed. For the decimal places, let’s add the second parameter. We multiply the rounded value by the function’s output in order to obtain the result. Once you press F1, you may access the help and notice that an integer value has been returned. We also pass the input value and the rounded value to the MathCeil function for further calculation. Then we return our outcome to the function using Return. Similar principles apply to the second function for rounding the value. But in this case, MathFloor is used rather than MathCeil. And in this case, we also return the result to our main function. And so, for a 0.25 lot determined lot size, this yields the rounded up value of 0.3 and the rounded down value of 0.2. You can alter this in accordance with the type of account you have and so pass the proper values so that a position can also be opened correctly. Not all account types can deal with microlot sizes that are staggered to the second decimal place. By the way, another premium customer had suggested this video topic. Additionally, if you’re a premium customer and have an idea for a video like this, please email me. If not, the premium course is available on our website. Additionally, you learned how to round lot sizes up or down with ease in this video so that they meet your account type. And you wrote these few MQL4 lines here to program that yourself.
    4 min
  • MQL4 TUTORIAL BASICS – 134 STANDALONE BOLLINGER MACD EXPERT ADVISOR
    In this video we are going to create an expert advisor that is able to use the Bollinger Bands to create a Buy or a Sell signal. And we are going to use the MACD as a filter. So let’s find out how to do that with MQL4. To get started, please click on the little icon here or Press F4 on your keyboard. Now you should see the Metaeditor window and here we have the precoded solution. In my case, I’m doing an include function for the Bollinger Bands module and for the MACD module. Both are separate files and the include function can import the content of those files. And they will be compiled when you compile the main module, which is the one with the Ontick function. And here we create a string variable for the trading signal and another string variable for the filter. And to get the trading signal we are opening a function that is called CheckEntry Bollinger. And to create a filter signal we open a function that is called Check Entry MACD. And when we have a Buy signal and the filter for the MACD also says that we should buy and if the return value for Orders total equals zero, that would mean all conditions are good for a Buy signal. And that’s when we use Order Send to open a Buy Trade for ten microlot. Otherwise, when the trading signal equals Sell and when the filter also equals Sell and we have no open positions, that’s when we use Order Send to open a Sell Trade for ten microlot. Finally, we use the comment statement to output the trading signal and the filter signal on our chart. That’s it for the main module. For the entry signal and the filter signal we use precoded entry modules that we have created before. If you don’t know what all that code here means, you maybe want to watch one of the other videos in our basic video series, or maybe even the premium course might be interesting for you. You can find that one on our website and there are also more precoded source codes available in our store. So this is it. Once you have all three modules in place you can click on the compile button. Here we are. And if you don’t have any errors you can click on the little button here or press the F4 button to go back to MetaTrader. And in MetaTrader you want to click on view, strategy tester, or press CTRL and R. Please mark the option for the visual mode here and start your test. Now our little expert advisor is running. So the expert advisor seems to work. Now let’s go to full speed for a few seconds. You see that we have several positions that are opened. Now let’s pause the whole thing and click on the graph tab. We have a few positions here. So it looks like our expert advisor works as expected. And in this little video you have learned how to create an expert advisor that is able to calculate buy and sell signals by using an external module for the Bollinger Bands. You also used a filter for the MACD signal and you have coded it all yourself with a few lines of MQL4 code.
    4 min
  • MQL4 TUTORIAL – SIMPLE POSITION MULTIPLIER
    In this video we are going to create an Expert Advisor that contains a position multiplier (SimplePositionMultiplayer). In our case we are trading 5 positions at once, let’s stop the Expert Advisor, click on “Expert properties/ Inputs/ NumberOfPositionsToTrade” and increase the value to 10, confirm it with okay. I start another test and this time our Expert Advisor is trading 10 positions and now we are going to find out how to code an Expert Advisor in MQL4 that is able to offer a user adjustable value that can be changed without changing the source code. To do that please click on the little button here or press F4 on your keyboard and now you should see the Metaeditor window and here you want to click on “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this one: “SimplePositionMultiplier”, click on “Continue”, “Continue” and “Finish” and now you can remove everything above the “OnTick” function and the two comment lines here. So now let’s create an external variable for the number of positions to trade that will be called: “NumberOfPositionsToTrade”; most coders like to use short names and a few weeks afterwards they ask themselves: “What the hell is this variable doing?” but I think if you invest a few seconds to type in a good name for the variable is always time that is good Invested. Okay. In the “OnTick” function we want to create a double variable that is called: “Candle1Close” and it contains the value for the close price of candle 1. Let’s do that same thing again but this time we call it: “Candle2Close” because it contains the close price for candle 2 and now we want to stack a few conditions to open a new trade. If “OrdersTotal” delivers a value that is below the “NumberOfPositionsToTrade” we have defined here and if that is the case we come to our second condition; the second condition is we want to test if the last close price was higher than the close price before and that would be the case if the “Candle1Close” price is bigger than the “Candle2Close” price. The current candle is always candle 0, this is candle 1 the candle before is candle 2 and so on, so if this expression is true our price is higher now and now we want to send a buy order that is done by using the “OrderSend” statement. To find out about all the different parameters here just watch the Simple Buy Order video; basically we buy 10 micro lots and our take profit will be 150 points above the “Ask” price and when you are done you can click on the little “Compile” button here or press F7 on your keyboard. That worked without any errors, so now we can click here or press F4 to go back to Metatrader. In Metatrader please click on “View/ Strategy Tester” or press “CTRL and R”, now select the “SimplePositionMultiplayer.ex4” file we just have created and enable the visual mode here, set the “Expert properties”, let’s say we want to have 3 trades, click on “OK” and start your test and this time we see 3 open trades on the chart and now you know how to create an Expert Advisor that is able to deliver a user-defined variable that can be adjusted by the user when he clicks on “Expert properties” and you have coded it yourself with a few lines of MQL4 code.
    5 min
  • MQL4 TUTORIAL – SIMPLE ACCELERATOR EXPERT ADVISOR
    In this video we are going to talk about the Accelerator Indicator, it’s an oscillator and it produces green and red bars. Whenever this zero line here is crossed by the bars we create a buy or a sell signal. Now how can we create an Expert Advisor that is able to output buy or sell signals directly on our Forex chart? To do that please click on a little button here or press F4 on your keyboard, and now you should see the Metaeditor window. Here you want to click on “File/ New/ Expert Advisor (template)” from template. Continue. I will call this one: Simple Accelerator (Simple Accelerator). Continue, continue and finish. Now you can remove everything above the “OnTick” function and the two comment lines here because now we want to create a variable for the signal – it will hold text, so we use a string variable call it signal – and so far, it has now value here because we are going to calculate that later on. To calculate the “IACValue”, we use the built-in “iAC” function. If you select it and press the F1 key you will see that it takes 3 parameters. The first one is the symbol, the second one is the time frame, and the third one is the shift. If you click on insert “Indicators /Bill Williams /Accelerator Oscillator” you will see that we don’t have any shift value here, so we use _Symbol for the currently selected currency pair on the chart, _Period for the selected period on the chart – that can be 1 minute, 1 hour or 4 hours or anything else up to 1 month – and the last parameter here would be the shift, we use zero here because we don’t need to move the Accelerator Indicator to the left or to the right. Now that the calculation is done we want to find out if the IAC value (IACValue) is above zero. We do that with an “if” statement; so, if “IACValue” is greater than zero (IACValue>0) that would create a buy signal, so we assign the word “buy” to the variable signal here. In the other case if the “IACValue” is below zero (IACValue
    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