MQL5 Tutorial

MQL5 Tutorial

By Raimund BauerBusinessTechnologyInvesting
Download on the App Store

MQL5 Tutorial episodes

  • MQL5 Tutorial – How to simply adjust user input with MQL5

     

    1. Introduction to Enhancing a Simple Expert Advisor (00:00 – 00:07) Introduction to improving a simple expert advisor by allowing user adjustments, following the results of a year-long test.
    2. Reviewing the Year-Long Test Results (00:07 – 00:19) Overview of the test results: 73 trades made, with 54 short trades and 19 long trades, and the lack of adjustable inputs.
    3. Enabling User Adjustments for Lot Size (00:19 – 00:30) The goal to enable users to adjust the lot size of trades, which is currently hard-coded in the source code.
    4. Modifying the Expert Advisor to Include Input Variables (00:30 – 00:43) Steps to modify the expert advisor to include input variables, specifically for adjusting the lot size.
    5. Creating a Dynamic Input Variable for Lot Size (00:43 – 00:56) Instructions on creating a dynamic input variable for lot size, allowing it to be changed by the user.
    6. Replacing Fixed Lot Size with the New Variable (00:56 – 01:03) Replacing the fixed lot size in the code with the new variable and saving the changes.
    7. Compiling the Code and Testing the New Feature (01:03 – 01:17) Compiling the updated code and testing the new feature in Metatrader, with visualization enabled.
    8. Observing the Adjustable Lot Size in Action (01:17 – 01:28) Observing the first trade with the new adjustable lot size and stopping the test to change the input.
    9. Changing the Lot Size and Testing Again (01:28 – 01:43) Adjusting the lot size to a different value and testing again to demonstrate the flexibility of the new input feature.
    10.  

      In one of our other videos we have created a simple buy trade system and this is the result of a whole year.

      It made seventy three trades, fifty four were short trades and nineteen were long trades.
      You see under the input tab we have absolutely no values here so we cannot set anything that is not hardcoded in our source code.
      Now we want the user to be able to adjust the Lot Size of a trade here, to do that we simply click on Simple Buy Trade and click Modify.
      This is how our short E.A. looks like and this is the Lot Size.
      To create a dynamic value that can be changed by the user you have to make it an input variable and will be a double variable, and we will call it MyLotSize.
      Let’s assign ten Micro Lot here, copy the name and exchange the fixed ten Micro Lot Size here with our new variable.
      I will save it as Simple Buy Trade with input. Let’s compile the code and hit F4 to bring up the Meta Trader.
      I will select the system here, check the visualization option and start the test. This is our first trade and its ten Micro Lot.
      Let’s stop the test, go to inputs and change it to 0.2, now it is 20 Micro Lot.
      If you make something adjustable by the user, you can do it by making it an input.
      Afterwards the value can be simply changed without recompiling the code.

      Download “MQL5 Simple Buy Trade with User Input EA from MQL5 Tutorial” SimpleBuyTradeWithInput.txt – Downloaded 456 times
      – 381.00 B

      The post MQL5 Tutorial – How to simply adjust user input with MQL5 appeared first on MQL5 Tutorial.

      2 min
    11. MQL5 Tutorial – Simple Commodity Channel Index

      With MQL5 for Metatrader5 we can use the ICCI function that is built in to create an Expert Advisor that will use the Commodity Channel Index Indicator to create entry signals on our Forex Trading Chart…

      This video is about the commodity channel index.

      The commodity channel index is an oscillator and it will tell you if something is overbought or oversold.
      This is one of the oscillators I like because it is very easy to understand.
      It has one hundred plus and a one hundred minus line here and whenever the value rises above the upper line, it’s overbought.
      In the other case if the indicator falls below the lower line, it’s oversold.
      The commodity channel index can be created with the MQL 5 function ICCI that is built-in into MQL 5.
      And now we want to create a little Expert Advisor that will tell us when the market is overbought or oversold.
      To do that please click the little button here or hit the F4 key on your keyboard. That will bring up the Meta Editor, and here we want to select File, New, Expert Advisor from template, continue.
      And we will call the Expert Advisor Simple Commodity Channel Index. Now click on Continue, Continue, Finish, everything above the Ontick function can be removed and we will also delete the two comment lines here and we will start by creating a little array for our prices.
      It’s a double array and we will call it my price array. And for the definition of our commodity channel index, we will use the ICCI function of MQL 5.
      For the current symbol on the chart and the selected period, this might be Euro/U.S. dollar and this might be the minute chart or the hourly chart, and the calculation is done for fourteen candles, because this is the default value of the commodity channel index when you drag it on your chart by using Insert, Indicators, Oscillators, commodity channel index.
      And it is calculated based on the close prices.
      In the next step we need to sort the price array from the current candle downwards by using the function arraysetasseries for the price we have created here.
      And now we use copy buffer for the CCI definition from line here.
      This is for the first line, it is line zero. And for the current candle that’s candle zero, and we need the values for three candles, that’s the three here, and we want to store the results in my price array.
      We want to get the CCI value of the current candle in our price array.
      Okay now we need the chart output depending on the value so if our value is above the upper line we want to put the text “Overbought” on our chart by using the comment function.
      And if it’s below the lower line we want to output the text “Oversold.”
      And when it’s between the lines we just use an empty output because we have no signal.
      Okay that’s it. If you’re ready, please click on the little compile button here or hit the F7 key on your keyboard.
      That should compile your Expert Advisor without any error or warnings. And in that case we want to bring up the MetaTrader by pressing the F4 key or hitting the little button over here.
      In Metatrader please click on View, Strategy Tester or hit control and R. That should show you the strategy tester panel, and here we want to select the simple commodity channel index.ex5 file.
      Please make sure to mark the visualisation option here and click on start. And here is our Expert Advisor at work.
      Now it’s below the lower line and then it says oversold and when it’s above the upper line it says overbought.
      Okay, now you know how you can use the Commodity Channel Index Indicator to create entry signals in your own Expert Advisor. And you have done it yourself with a few lines of MQL 5 code.

      Download “MQL5 Simple Commodity Channel Index Expert Advisor from MQL5 Tutorial” SimpleCommodityChannelIndex.txt – Downloaded 346 times
      – 928.00 B

      The post MQL5 Tutorial – Simple Commodity Channel Index appeared first on MQL5 Tutorial.

      6 min
    12. MQL5 TUTORIAL – SIMPLE AWESOME STANDALONE EXPERT ADVISOR

      This time we are going to create a standalone Expert Advisor to trade the Awesome Oscillator, it will output buy and sell signals directly on the chart and whenever the line is crossed here we either get a sell signal when it’s below the dotted line or we would get a buy signal as soon as it crosses the line like right now the bars are above and now we consider that to be a buy signal.

      Now how can we create an Expert Advisor in MQL5 that is able to not only output the signals on the chart but to automatically trade them?
      To do that 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/ Expert Advisor (template)” from template, “ Continue”, I will call this file: “SimpleAwesomeStandaloneEA”, click on “Continue”, “Continue” and “Finish”.
      Now you can delete everything above the “OnTick” function and the two comment lines here.
      We start by including the file “Trade.mqh”, this one comes with MQL5 and it makes it possible to create an instance from the class “CTrade” that will be called: “trade” and we are going to use it to open positions later on. Before we do that we calculate the Ask price and the Bid price that is done by using “SymbolInfoDouble” for the current symbol on the chart, “SYMBOL_ASK” will give us the Ask price and “SYMBOL_BID” will give us the Bid price.
      With “NormalizeDouble” and “_Digits” we automatically calculate the right number of digits because the current currency pair has 5 digits behind the dot but there are also other currency pairs with 3 digits behind the dot.
      Now we need a signal variable that will be a string variable so it can contain text later on right now we don’t assign any values because we need to calculate them later on.
      With “MqlRates” we create a price information array (PriceInformation), that function here stores the information about the prices, the volumes and the spread.
      Now we sort the array from the current candle downwards by using “ArraySetAsSeries” and with “CopyRates” we fill it for the current symbol and the currently selected period on the chart from candle 0 (zero) for 3 candles and we store the data in our price information array (PriceInformation).
      Let’s create another array called: “PriceArray” that one will hold the data for our Oscillator, so let’s use the integrated “iAO” function of MQL5 to define the Awesome Oscillator Indicator for the current symbol and the current period on the chart. This array (PriceArray) also needs to be sorted from the current candle downwards so we use “ArraySetAsSeries” for this one and now we use “CopyBuffer” to fill our price array (PriceArray) for the first buffer – that’s the line here – from the current candle 0 (zero) for 3 candles and store the information for the Expert Advisor in our price array (PriceArray).
      And to calculate the Expert Advisor for the current candle we simply look at the value of candle 0 (zero) in our price array (PriceArray), we also use “NormalizeDouble” and a 6 to get six digits behind the dot like here and the result will be stored in the Awesome Oscillator value (AwesomeOscillatorValue) and if that value is above 0 (zero) we consider that to be a buy signal and now we assign the word: “buy” to our signal.
      Otherwise if the value (AwesomeOscillatorValue) is below 0 (zero), so if the Awesome Oscillator value (AwesomeOscillatorValue) is less than 0 (zero) we assign the word: “sell” to our signal and if the signal equals sell and “PositionsTotal” is below 1 – in other words we don’t have any open position – we use “trade.Sell” to sell 10 micro lot.
      Otherwise if the signal equals buy and we have no open positions we use “trade.Buy” to buy 10 micro lot.
      The last thing is to create a chart output by using the “Comment” function to output the text: “The current signal is:” and the calculated “signal” directly on our chart.
      Okay, if you’re done you can click on the “Compile” button here or press F7, that should work without any errors and in that case you can click on the 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 select the new file: “SimpleAwesomeStandaloneEA”, let’s also mark the visualization option here and start a test.
      …and here we are, our Expert Advisor is working, actually we have opened the first automated trade and now you know how to code the Awesome Oscillator Standalone Expert Advisor and you have coded it yourself with a few lines of MQL5 code.

      The post MQL5 TUTORIAL – SIMPLE AWESOME STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.

      7 min
    13. MQL5 TUTORIAL – SIMPLE SAR STANDALONE EXPERT ADVISOR

      In this video we are going to create a standalone Expert Advisor that is actually able to trade the Parabolic SAR Indicator.

      This is a very nice Indicator, you can see the dots above and below the price and whenever the direction changes here you will see that we have a buy or a sell signal. The signal output will be in the left upper corner here; this Expert Advisor will be able to automatically trade the signal. We have already an open position here and now we want to find out how we can code such a standalone Expert Advisor in MQL5.
      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 version: “SimpleSARStandaloneEA” (Expert Advisor), click on: “Continue”, “Continue” and “Finish”.
      Now we delete everything that is above the “OnTick” function and let’s also remove the two comment lines here.
      We start by importing the file: “Trade.mqh” that will enable us to create an instance of “CTrade” that will be called: “trade” and we use it later on to open the positions.
      Inside the “OnTick” function we create a price array (PriceArray) that is done by using the “MqlRates” function that is included in MQL5, now we use “ArraySetAsSeries” to sort our price array (PriceArray) from the current candle downwards and with “CopyRates” we fill it for the current symbol on the chart and a currently selected period, we start with the current candle 0 (zero) and we copy price data for 3 candles and store it in our price array (PriceArray).
      We also need to create a string for the signal, that variable will be also called: “signal” and we don’t assign a value here because we are going to calculate that later on.
      First we need to get the Ask and the Bid price, that can be done by using “SymbolInfoDouble” for the current symbol, we use “SYMBOL_ASK” to get the Ask price and “SYMBOL_BID” to get the Bid price, and with “NormalizeDouble” and “_Digits“ we calculate the number of digits behind the dot – you see that this currency pair has 3 digits while other currency pairs may have 5 digits – and if you mark “_Digits“ and press F1 you will see that the “_Digits“ variable stores the number of digits after the decimal point.
      Let’s create another array for our SAR Indicator that will be called my SAR array (mySARArray), it’s a double array so it can hold floating type values and by using a “iSAR” we create an SAR definition (SARDefinition) for the symbol on the chart and the currently selected period. Now you might ask yourself; what these two parameters are?
      Well, if you click on “Insert/ Indicators/ Trend/ Parabolic SAR” you will see that we have a step value of: 0.02 and a max value of: 0.2, that’s exactly what we are using here.
      Now it’s time to sort the SAR array (mySARArray) with “ArraySetAsSeries” and we use “CopyBuffer” one more time to fill our SAR array (mySARArray) for the first buffer – that’s the one that is used for the dots here – from the current candle 0 (zero) for 3 candles and store the values in our SAR array (mySARArray). Now we are able to calculate the value for the last candle, I will call it: “LastSARValue”, I use ”NormalizeDouble” here and a 5 because when you pause the Strategy Tester and hold your mouse above one of these dots you will see that we have 5 digits behind the dot of the value – that’s what “NormalizeDouble” does; if I would use “NormalizeDouble” and a 4 we would have 4 digits behind the dot – and we get the value for the last candle by looking at candle 1 in our SAR array (mySARArray).
      We actually do the same here, this time for candle 2 – that’s the candle before the last candle – so I call it: “NextToLastSARValue” and whenever the “LastSARValue” is below the lowest price of candle 1 – or in other words; whenever the dots are below the candles – and if the “NextToLastSARValue” was greater than the highest price for the candle before that would be a buy signal so we assign the word: “buy” to our signal.
      Otherwise if the “LastSARValue” was above candle 1 and the value was below the candles before that would be a sell signal and now we would assign the word: “sell” to our signal. And if our signal equals sell and “PositionsTotal” is below 1 – in other words we have no open positions – we use “trade.Sell” to sell 10 micro lot, otherwise if the signal equals buy and we have no open positions we would use “trade.Buy” to buy 10 micro lot.
      Finally we create a chart output here, we use the “Comment” function to output the words: “The current signal is:” followed by our calculated “signal”.
      Okay. That’s it. Please click on the “Compile” button or press F7, you should get no errors and no warnings here and in that case we can click here or press F4 to go back to Metatrader.
      In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, please select the file: “SimpleSARStandaloneEA.ex5”, mark the visualization option here and start a test.
      …and here we are! Our Expert Advisor is actually trading, this is our first position and in this little video you have learned how to create a standalone Expert Advisor that is actually trading the SAR Indicator and you have coded it yourself with a few lines of MQL5 code.

      Download “MQL5 TUTORIAL - SIMPLE SAR STANDALONE EXPERT ADVISOR” SimpleSARStandaloneEA.txt – Downloaded 391 times
      – 2.34 KB

      The post MQL5 TUTORIAL – SIMPLE SAR STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.

      8 min
    14. MQL5 TUTORIAL – SIMPLE ICCI EXPERT ADVISOR

      In this video we are taking a look at the ICCI Indicator, that’s the Commodity Channel Index Indicator.

      You can see that this signal here is creating buy and sell signals and whenever the blue line here is above the upper dotted line that would be a sell signal, in the other case if the blue line here is below the lower dotted line that would be a buy signal.
      Now, how can we create an Expert Advisor that is able to calculate the Commodity Channel Index Indicator?
      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: “SimpleCommodityChannelIndex”, click on “Continue”, “Continue” and “Finish” and now you can delete everything that is above the “OnTick” function and let’s also delete the two comment lines here.
      Here we need to create a string for the signal that will be also called: “signal” but we don’t assign any value here.
      We also need to create an array for the price data that will be called: “myPriceArray”, it’s a double array so it can hold floating type values and now we define the ICCI Expert Advisor by using the “iCCI” function that is built in into MQL5, it uses a few parameters; the first one is for the current chart – we use “_Symbol” to get the current currency pair on the chart and “_Period” to get the currently selected period. Right now we are trading the 1-minute chart but another period could be 30 or 60 minutes, the third parameter is the number of the candles. We use 14 candles and if you click on: “Insert/ Indicators/ Custom/ CCI/ Inputs” you would see a period of 14 candles is the default value. When I click on “OK” that’s what we see within the round brackets here, let’s right-click and select “Properties”, go to the “Parameters” tab until you see that we use a typical price and in MQL5 that’s “PRICE_TYPICAL” for the last parameter and now that we have defined the ICCI we want to use “ArraySetAsSeries” to store the price data from the current candle downwards for our price array (myPriceArray) we have created here and with “CopyBuffer” we fill our price array (myPriceArray) according to our “ICCIDefinition” for buffer 0 from the current candle 0 and for 3 candles and to get the ICCI value (ICCIValue) we just need to have a look at candle 0 in our price array (myPriceArray) and we assign the result to the variable ICCI value (ICCIValue) and whenever the ICCI value (ICCIValue) is greater than 100 that would be considered to be a sell signal so we assign the word: “sell” to our signal.
      In the other case if the ICCI value (ICCIValue) is below -100 that would be a buy signal so we assign the word: “buy” to our signal.
      Now let’s make that a capital and in the last step we want to create an output on the chart that will output the word “Signal:” followed by the calculated signal.
      Please don’t forget the closing bracket. I will enable the toolbar so now I can click on the “Compile” button here or press F7 on the keyboard to compile the code. We have one warning here because we used the float value here, usually that would be a double value so let’s correct that, press F7 and now the warning is gone, it doesn’t really make a difference because we use the ICCI value (ICCIValue) to find out if something is above 100 or below -100, you can store a lot of digits behind the dot in double value but that’s not very helpful if you just want to find out if something is above plus or below minus 100.
      Okay, if you could compile your code without any errors you could now click on the little button here or press F4 on your keyboard to go back to Metatrader.
      In Metatrader you want to click on “View/ Strategy Tester” or press CTRL and R on your keyboard and here in a Strategy Tester please select the “SimpleCommodityChannelIndex.ex5” file, mark the visualization option here and start your test and here’s our little Expert Advisor at work it creates outputs for buy and sell signals on your chart and now you know how you can code it and you have coded it yourself with a few lines of MQL5 code.

      Download “MQL5 TUTORIAL - SIMPLE COMMODITY CHANNEL INDEX” SimpleICCI.txt – Downloaded 367 times
      – 911.00 B

      The post MQL5 TUTORIAL – SIMPLE ICCI EXPERT ADVISOR appeared first on MQL5 Tutorial.

      6 min
    15. MQL5 Tutorial – Simple Adaptive Moving Average Robot

      Okay, this time we are talking about an Adaptive Moving Average Indicator.

      It was created (I think) by Perry Kaufman and you can use it to find entries or exits like you could with a simple moving average.
      Now if that is almost the same, why should we prefer to use an Adaptive Moving Average?
      Well Perry J. Kaufmann created this fascinating formula here for a reason. The Adaptive Moving Average has less lagging and generates less false signals. Let’s see if that is true.
      Now how can we create an Adaptive Moving Average Expert Advisor for Meta Trader 5?
      First please click on the little button here, that should bring up the MetaEditor.
      And here you want to select File, New, Expert Advisor from template, Continue and we will call that Simple Adaptive Moving Average.
      Now click on Continue, Continue, finish, and you can remove everything above the Ontick function here and I will also delete the two comment lines.
      So let’s create an array that will hold our prices, I will call it my price array and it is a double array because double and float variables can hold floating point types.
      And the adaptive moving average has six digits behind the dot and now we want to use the integrated MQL5 function iAMA for the current symbol on the chart and the current period, we want to calculate our prices based on the last nine candles.
      The Fast Moving Average has a value of two because if you Insert, Indicators, Trend, Adaptive Moving Average, you will see the values here, these are the nine candles.
      The fast EMA, that’s an Exponential Moving Average, is calculated for two candles and the slow EMA is calculated for thirty candles.
      And we do not need any shift, so we will use the exact same values here: nine candles, two candles for the fast EMA, thirty candles for the slow EMA.
      Zero for no shift and I would like to have the values calculated based on the close prices because the close price is also the default setting here.
      Okay let’s move on and sort the price array from the current candle downwards by using the array set as Series function for the price array we have created here.
      And now we want to fill it with data, that is done by using Copy Buffer for the Defined Moving Average, that’s the Adaptive Moving Average Definition we have created in this line.
      We just need one line, that’s the zero here, and we want to copy values from the current candle that’s candle zero for three candles that’s the three here, and we want to store the results in our price array.
      And now what we have done that, we want to get the value of the current candle, that’s candles zero of our price array and we use the normalized double function to get six digits behind the dot and the calculated value should be stored in a variable that is called Adaptive Moving Average Value.
      And the last step is to create a chart output by using the comment function.
      It will output the text AMA value and the calculated value for the Adaptive Moving Average Value we have extracted here.
      Okay that’s it, now please click the Compile bottom and you should get no errors and no warnings here so now you can click the button or hit the F4 key to go back to MetaTrader.
      And in MetaTrader you want to click on View, Strategy Tester, and in the Strategy Test panel you want to select the Simple Adaptive Moving Average.ex5 file.
      Select any currency pair you like and please make sure to enable the check mark for the visualisation option before you start your test.
      And here we go! if you move your mouse to the current value here, you’ll see that we have a value of 1.544031, that’s exactly what we have calculated here.
      And in your Expert Advisor you would now compare the value of the adaptive moving average to the current price.
      And if the price is above the moving average you would buy, and if the price is below the moving average you would sell.
      Okay now you can create an Expert Advisor that uses the Adaptive Moving Average Indicator to find out if you want to buy or if you want to sell and you have created it in less than five minutes with a few lines of MQL5 code.

      Download “MQL5 - Simple Adaptive Moving Average Robot” SimpleAdaptiveMovingAverage.txt – Downloaded 475 times
      – 762.00 B

      The post MQL5 Tutorial – Simple Adaptive Moving Average Robot appeared first on MQL5 Tutorial.

      7 min
    16. MQL5 Tutorial – Simple Force Index Trading Robot

      Okay this time we are talking about the Force Index Indicator.

      It is a very simple indicator. It’s easy to read and also easy to code.
      If the indicator crosses the line in the middle from below and stays above the line, that could mean that we are bullish.
      And when it crosses the line from above and stays below the line like in this case, we have a bearish trend and we would like to sell.
      According to the website www.traderhq.com, this is also an indicator that was developed by Dr Alexander Elder, the author of the book: Trading for a Living.
      Okay now that we know how it works how can we create an Expert Advisor to use the indicator?
      The first step is to click the little button over here or hit the F4 key on your keyboard.
      That will start the Meter Editor and we want to click on File, New, Expert Advisor from template, Continue.
      We will call it Simple Force Index Robot. Now click on Continue, Continue, Finish, and delete everything above the Ontick function.
      These two comment lines are also no longer needed, because here we want to create an array, it shall holds several prices so it’s a double array and I will call it my price array.
      And now it’s time to define the Force Index definition by using the iForce function that is built-in into MQL 5.
      It takes some parameters, the first one is the current symbol on the chart, the second one is the period you have selected on your chart.
      The Force Index is calculated based on the last thirteen candles. You will also see it here in this little brackets.
      It is using the MODE_SMA that stands for Simple Moving Average and we want to use Tick volume.
      If you insert the indicator by clicking on Insert indicators, Oscillators, Force Index, you will see the exact same values here: thirteen candles, simple moving average based on the tick volume.
      Okay, let’s use the array set as series function that will sort the price array from the current candle downwards and now we use Copy Buffer for the Force Index definition we have created here.
      We need one line for the indicator that’s a zero here and we want to fill our array from the current candle that’s candle zero, for three candles that’s the three and store the result in our price array.
      And from our price array we are now going to extract the Force Index value for the current candle zero and we will use normalize double for six digits to get the six digits behind the point.
      And now we want to create a chart outputs depending on the value and if our Force Index value is above zero, we want to output the comment “trending upwards” directly on our chart and in the other case if the Force Index value is below zero, we want to have the text “trending downwards” on our chart.
      Okay, now please click on the little Compile button here or press the F7 key on your keyboard.
      That should compile your Expert Advisor without any errors or warnings here.
      And if that was going well please click on the button here or press F4 to go back to MetaTrader. Now in MetaTrader you want to click on View, Strategy Tester or press control and R.
      And in the Strategy Tester you want to select the Simple Force Index Robot.ex5 file.
      Let’s pick a currency pair here, enable the visualisation mode and click on Start and here we go.
      Now the indicator is below the line so it says trending downwards and as soon as the little indicator crosses the line from below, that changes to trending upwards.
      Okay, now you know how to create an Expert Advisor for Meta Trader5 that is using the Force Index Indicator and you have created it yourself in five minutes with a few lines of MQL5 code.

      Download “MQL5 - Simple Force Index Trading Robot from MQL5 Tutorial” SimpleForceIndexRobot.txt – Downloaded 387 times
      – 807.00 B

      The post MQL5 Tutorial – Simple Force Index Trading Robot appeared first on MQL5 Tutorial.

      6 min
    17. MQL5 TUTORIAL – SIMPLE CUSTOM TIME FUNCTION

      In this video we are going to talk about a simple custom time function that we have created in MQL5.

      You see the output here on the chart, we have the date and we have the time including the seconds that is the local time that has been traded right here in the Strategy Tester and now we are going to find out how we can do a custom time function that is going to return the time and this readable format and to do that please click on the little button here or press F4 on your keyboard.
      Now you should see the Metaeditor and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “SimpleCustomTimeFunction”, click on “Continue”, “Continue” and “Finish” and now you can delete everything above the “OnTick” function and the two comment lines here.
      Okay, that’s it.
      First we need to create a string variable for our custom time that will be called: “myTime” and it’s of the type string, so it can contain text and to calculate it we just want to call a custom function called: “GetTime” to calculate the time, so the value of “myTime” will be calculated in the function “GetTime” and when we click on the “Compile” button right now we will see that the “GetTime” function is not defined, so that’s what we are going to do now.
      To create a custom function you can use a return type, in our case we will use the string return type, because we are going to deliver the time as text. The name of the function is: “GetTime” as we are calling it here and we don’t have any parameters so let’s add two brackets here, we use a local string that will be called: time with seconds (TimeWithSeconds). Now we create a string for the time with seconds (TimeWithSeconds) that’s also a string type variable and the name will be: “TimeWithSeconds”.
      Here comes the interesting part; we calculate the time with seconds (TimeWithSeconds) for the local time and that is done by using “TIME_LOCAL”. If you mark “TIME_LOCAL” and press the F1 key you will see that it returns the local time of a computer where the client terminal is running, but it’s a datetime variable so we use “TimeToStr” to change it to a text and the function: “TimeToStr” (time to string) is converting a value containing time in seconds since the 1st of January in 1970 into a string in this format.
      We use “TIME_DATE” that will give us the year, the month and the day – that’s the first part here, this is the pipe sign, it separates the first from the second parameter, the second parameter is “TIME_SECONDS” and that will deliver us the local time including the seconds.
      Okay. In the last step we want to return the calculated time to the main function by using the “return” function for “TimeWithSeconds” so it will return the calculated value here and assign it to “myTime” and to see it on the chart we use the “Comment” function to create a chart output for the time and when you are done you can click on the “Compile” button here, that should work without any errors now and if that is the case you can click on the little button here to go back to Metatrader.
      In Metatrader you want to click on “View/ Strategy Tester” or press CTRL and R and now you should see the Strategy Tester here, please select the “SimpleCustomTimeFunction.ex5”, mark the visualization option here and start your test.
      We have the date and the time directly on the Forex Chart and now you know how to create an Expert Advisor to calculate the formatted time output on your chart and you have done it with a few lines of MQL5 code.

      Download “MQL5 TUTORIAL - SIMPLE CUSTOM TIME FUNCTION” SimpleCustomTimeFunction.txt – Downloaded 410 times
      – 598.00 B

      The post MQL5 TUTORIAL – SIMPLE CUSTOM TIME FUNCTION appeared first on MQL5 Tutorial.

      6 min
    18. MQL5 TUTORIAL – LIVE TRADING EXPERIMENT 2024 – LIVE UPDATES AND A LIVE PROFIT DOCUMENTED
      20240101: DOWNLOAD 28 result videos for this system https://bit.ly/41OIpzK 20240101: README Documentation (updated often): https://bit.ly/41FPceY 20240102: System Download for Demo accounts: https://bit.ly/3H3diqt 20240103: Account Setup: https://youtu.be/qtCXQI3XL_4 20240104: Trading System Import: https://youtu.be/4AWpxGKVS4A 20240105: First Account Profit: https://youtu.be/BqXaoGyy3QU 20240106: Setup MX Linux server in 5 minutes: https://youtu.be/JVZoYn2w6Yw 20240107: Setup Metatrader on Linux in 3 minutes: https://youtu.be/DTkOQKW3HT4 20240109: Live Updates Live Profit: https://youtu.be/BCnttK7d4HI In this video, I want to talk about how I got my advanced statistics to run. Actually, I had to change the account to Robo Forex and use a demo account there because what I didn’t know was that FXblue is not able to provide statistics for MetaQuotes demo accounts because they simply do not have the MetaQuotes company in their list. So when you pick a broker, you need to pick one that’s in their list, and MetaQuotes is not part of that. Yes, I could write to the support to add MetaQuotes, but I guess for this experiment, it’s more useful to use an account that actually is included. And for Robo Forex, they support demo accounts. I have to admit that advanced statistics for Robo Forex have been a pretty standard for me and my clients in the last few years. If you don’t know, I’m offering a premium course about MQL5 programming, and that is also where a lot of people use the same Robo Forex account settings that I use. So I actually didn’t know that MetaQuotes wasn’t in the brokers list. And I switched to this account, and that means that we had to start over with $100,000. So right now, we have made a profit of $71, and I guess in the next hour or so, we will make a few more trades. But the crazy thing is, I actually tried to use this account sync option. They say that it works for MetaTrader 4 and MetaTrader 5, but it wasn’t running on Linux and it wasn’t performing. So I thought, okay, I need to download this publisher app here, and I did. So the version I picked was this one for MetaTrader 5. You can download it for free and you will get a zip file. And when you open that zip file with Linux, you will find there is a publisher ex5 file inside. I had to extract that. Now, let’s go back to the trading terminal and click on File, Open Data folder, MQL5 experts. And here is that FX Blue publisher ex5 file. I then opened a new chart, and here is the ExpertAdvisor that you can drag onto the chart. I’m not going to replace it right now because it’s already working. You can see that the last synchronization was today at about 20 minutes past 5. Let’s open the FX Blue statement. This is the correct account number. It says that we have a history of eight days, which is true because the account is eight days old, but I started to use it yesterday. I can now refresh the state, and it says we have an open loss of $23 and a profit of $71. So let’s go back to MetaTrader and check. Yes, that’s about what is happening right now. And you can see that we have a profit here. So I expect my system to close both trades in the next few minutes because it’s configured in a way that when a new candle appears on the chart and the profit is higher than what I have defined, it should close both trades and lock in the account-based profit. This is the current candle. Currently, I’m using the hourly candles, so let’s switch to one minute. And I think that it will only take a few seconds until we see that this trade is closed, at least until the profit value drops. But with the lot size of 0.86 lots, it’s just a question of a few seconds before the profit value is reached again. Here is the new candle, but the profit is below $10, so let’s wait for the next one. And here we are. We have closed closed the trade. Now, let’s go back to the hourly chart. It already opened a new one. Now, the balance is $100,101. The history has changed.
      6 min
    19. MQL5 TUTORIAL – LIVE TRADING EXPERIMENT 2024 – SYSTEM DOWNLOAD AVAILABLE (below)

       

      20240101: DOWNLOAD 28 result videos for this system

      20240101: README Documentation (updated often):

      20240102: System Download for Demo accounts:

       

      Okay, let’s start from the beginning. The trading experiment we’re conducting in 2024 is different from anything I’ve done before. A few weeks ago, I was pretty sick and was lying in bed, watching movies on Netflix all day. These included movies with commercials, and one ad I kept being shown was about a woman getting face cream for Christmas. She also demonstrated how to use the cream with pineapple to improve her skin. This didn’t interest me at all, and even if I was shown this ad a thousand times, I would never use face cream with pineapple.

       

      Why am I telling you this? It’s about relevance! If I offer something that is irrelevant, nobody will want to buy it. It’s the same with pineapple face cream. It doesn’t matter how hard I try to convince someone if it’s just not relevant. I don’t think it matters what advertising technology is used. If something doesn’t interest me, there’s little anyone can do about it, no matter how appealing the advertising is. As a rule, I look for solutions that bring me more benefit than cost – popularly known as a bargain. In other words, you get something of value for less than you would be prepared to pay. That’s why we’re doing something different this year. I think a lot of companies are at an impasse right now because they’re trying to convince everyone on the planet to buy their products and everyone is trying to get louder and louder. I myself am not a fan of being ripped off and have never made a big show of how and what I do in trading.

       

      I know that many people in this field wave big wads of cash from a skyscraper in Dubai or loll around on their Ferrari, but I believe that most potential clients quickly see through such dubious strategies. So I spent a long time looking for a way to offer something that I would buy myself, in an unobtrusive way that could convince people like me. I found Frank Kern, who teaches a strategy that I really like. It is described as the oldest trick in his books and is about really helping someone to convince them that you can help them. When it comes to automated trading, that’s pretty easy and that’s why we’re using a demo account now and will be trading with a demo system to get better results in 2024. I believe that you are interested in better results, and I know from the last ten years that 10 to 15 percent of the people who watch these videos are interested in buying the right solution. That doesn’t mean you have to buy it yourself, but I believe that probabilities are the key to success.

       

      Knowing my numbers, it is very likely that 10 to 15 percent of viewers will spend money with me later because they are convinced that what I am offering is exactly the solution they were looking for. That’s why the Robot Trading System is now available as a free download for demo accounts. You can find the link below this video. In the next videos we will look at how to set up this system in Meta Trader to achieve good results in the long term. Anyway, I believe that you should trade the first weeks or months on a demo account, and after that you can use the system on a so-called cent account. So this strategy fits well. And I think it can help you and me to achieve better results in 2024. Okay, that’s it for this video. I’ll see you in the next one, and thank you for watching.

      The post MQL5 TUTORIAL – LIVE TRADING EXPERIMENT 2024 – SYSTEM DOWNLOAD AVAILABLE (below) appeared first on MQL5 Tutorial.

      0 min

    About MQL5 Tutorial

    From the publisher's feed

    MQL5 Expert Advisor Algo Trading for Metatrader5