MQL5 Tutorial

MQL5 Tutorial

By Raimund BauerBusinessTechnologyInvesting
Download on the App Store

All MQL5 Tutorial episodes

  • MQL5 TUTORIAL – SIMPLE ON BALANCE VOLUME
    Introduction to Onbalance Volume Indicator (00:00 – 00:16) Introduction to the Onbalance Volume Indicator, explaining its purpose and how it indicates potential price movements. Starting with MetaEditor in MetaTrader (00:16 – 00:41) Instructions on opening MetaEditor in MetaTrader and creating a new Expert Advisor file named ‘SimpleIOBValue’. Setting Up the Expert Advisor (00:41 – 01:00) Initial setup of the Expert Advisor, including removing unnecessary lines and preparing the code environment. Creating and Sorting the Array (01:00 – 01:15) Creating a double array for the Expert Advisor and using ‘ArraySetAsSeries’ to sort the array from the current candle downwards. Defining the Onbalance Volume (01:15 – 01:52) Using the ‘iOBV’ function to define the Onbalance Volume with the current symbol, period, and ‘VOLUME_TICK’. Filling the Array with Data (01:52 – 02:43) Using ‘CopyBuffer’ to fill the Expert Advisor array with data for the Onbalance Volume Indicator. Calculating the Current Onbalance Value (02:43 – 03:12) Calculating the current Onbalance Value by looking at the value for candle 0 in the Expert Advisor array. Creating Chart Output (03:12 – 03:52) Using the ‘Comment’ function to create a chart output displaying the calculated Onbalance Value. Compiling and Testing in MetaTrader (03:52 – 04:35) Instructions on compiling the code, resolving warnings, and testing the Expert Advisor in MetaTrader with a visualization of the Onbalance Volume Indicator.   In this video we are looking at this little Indicator, it’s the Onbalance Volume Indicator. Investopedia (www.investopedia.com) says that the Onbalance Volume should show us that whenever the Indicator increases without a significant price change the price should follow and now we are going to find out how to automate the Onbalance Volume Indicator in MQL5. To do that please click on a little button here or press F4 in your Metatrader, now you should see the Metaeditor window and here we click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “SimpleIOBValue”, click on “Continue”, “Continue” and “Finish”. Now you can delete everything above the “OnTick” function and let’s also remove the two comment lines here. This is a very simple Indicator, we start by creating an array for the Expert Advisor (EAArray), this one will be a double array so it can hold floating type values, now we use “ArraySetAsSeries” to sort the array (EAArray) from the current candle downwards and to define the Onbalance Volume we use the included function that is called: “iOBV”, so let’s mark that and press F1, here we see that it uses the current symbol on the chart, the currently selected period on the chart and the third parameter is called: applied volume so let’s click on this link and we see that we could use the tick volume or the real volume. In our case we use “VOLUME_TICK”. Now we use “CopyBuffer” to fill our Expert Advisor array (EAArray) according to the IOBV definition (IOBVDefinition) that we have created here for the first buffer… well, a buffer is in our case this line here, some Indicators have more than one buffer for example if I would “Insert/ Indicators/ Trend/ Bollinger Bands”, this one has three different lines, so it uses 3 buffers and the first buffers is always called buffer 0 (zero), the second buffer would be number one and so on. That’s because arrays are zero based in MQL5 so the first item in an array is always called by calling the index zero. Let’s copy the data for 3 candles and the result will be stored in our EA array (EAArray). To calculate the current Onbalance Value (IOBVVALUE) we now need to look at the value for candle 0 (zero) in our EA array (EAArray), remember this one is the current candle so this would be candle 0 (zero), candle 1, candle 2, and so on. Finally we want to create a chart output that’s done with the “Comment” function and it will output the words: “The IOB Value is:” followed by the calculated va...
    6 min
  • MQL5 Tutorial – Simple Sell Stop Expert Advisor
    A sell stop is an order that has been placed into the market and that will be triggered whenever the price is falling below the price level that we have defined, this one has already been triggered, so let’s see if we can create another one. Here you see that we have placed a sell stop order and as soon as the price reaches the price level that we have defined a sell position is opened. Now how can we create an Expert Advisor that is able to place such a sell stop? To do that please click on the little button here or press F4 in your Metatrader. 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: “SimpleSellStop”, click on “Continue”, “Continue” and “Finish”. Now we can delete everything above the “OnTick” function and the two comment lines here. We are going to start by using the “include” statement to include the file “Trade.mqh”, this one comes with MQL5 and we use the included “CTrade” class to create an instance that will be called: “trade” and we are going to use it to open our sell stop later on. Inside of the “OnTick” function we get the Bid price, that is done by using “SymbolInfoDouble” for the current symbol on the chart, we use “SYMBOL_BID” to get the Bid price and with “NormalizeDouble” and “_Digits” we make sure that we calculate the right amount of digits behind the dot, that could be 3 digits like for this currency pair or 5 digits like for this one. Let’s get the account balance by using “AccountInfoDouble”, “ACCOUNT_BALANCE” and we also want to calculate the equity by using “AccountInfoDouble” ,“ACCOUNT_EQUITY”, so if you mark “AccountInfoDouble” and press F1 you will see examples and here are all the values that you could use. This is all account related information.  Now If we have no open positions and no open orders, so if “PositionsTotal” equals 0 (zero) and “OrdersTotal” also equals 0 (zero) we want to open a new order for a sell stop for 10 micro lot. The difference between a position and the order is that a position is something that has already been triggered, so this is a sell position but when the position is closed we place an order below the current price level and as soon our order is triggered it becomes a position. To do that we use “trade.SellStop” to open an order for 10 micro lot, 100 points below the current price level, we don’t use a stop loss here and the take profit should be 300 points below the current Bid price, the last parameters here are used to set an expiration or a comment but we don’t need that. Instead we use the “Comment” function to output the current balance and the current equity directly on our chart. Okay, that’s it. Please click on the “Compile” button or press F7, and if you don’t have any errors here please click here or press F4 to go back to Metatrader. Now in Metatrader we click on; “View/ Strategy Tester” or we press CTRL and R, let’s pick the new file here: “SimplesellStop.ex5”, mark the visualization option and start your test. …and here we are! This is our sell stop and it will be triggered as soon as the price level drops below this line here, that has happened now and here is our first open position. Now you know how to code an Expert Advisor that is going to create automated sell stops and you have done it yourself with a few lines of MQL5 code.
    6 min
  • MQL5 Tutorial Classics – Simple Moving Average Robot with MQL5
    Introduction to Moving Averages (00:00 – 00:14) Explanation of moving averages and their use in determining if the current price is above or below the average value of a particular number of candles. Adjusting Moving Average Properties (00:14 – 00:32) Demonstrating how to change the properties of a moving average, such as adjusting the period to one candle. Exploring Different Moving Average Settings (00:32 – 00:54) Experimenting with different settings for moving averages, like setting the period to 100 and observing the changes on the chart. Using Moving Averages to Determine Market Direction (00:54 – 01:12) Discussing how traders use moving averages to identify market trends, such as when the current price crosses the moving average from above or below. Creating an Expert Advisor for Moving Averages (01:12 – 01:39) Introduction to creating an Expert Advisor in MetaTrader for moving averages, including how to view the value of the moving average at any point. Setting Up the Expert Advisor in MetaEditor (01:39 – 02:02) Instructions on opening MetaEditor in MetaTrader, creating a new Expert Advisor file named ‘Simple Moving Average’, and initial setup. Defining the Moving Average Array (02:02 – 02:34) Creating and setting up an array to hold price values for the moving average. Configuring the Moving Average Parameters (02:34 – 02:57) Detailed explanation of how to define the moving average parameters, including the period, shift, and type. Sorting the Price Array and Filling Data (02:57 – 03:36) Using ‘ArraySetAsSeries’ to sort the price array and ‘CopyBuffer’ to fill it with price data for the moving average. Calculating and Displaying the Moving Average Value (03:36 – 04:11) Calculating the current moving average value and using the ‘Comment’ function to display it on the chart. Adding a Moving Average Indicator to the Chart (04:11 – 04:53) Instructions on adding a moving average indicator to the chart for visual representation and saving the template for the strategy tester. Testing the Expert Advisor in Strategy Tester (04:53 – 05:50) Demonstrating how to use the strategy tester in MetaTrader to test the newly created Expert Advisor and verifying its accuracy. Verifying the Expert Advisor’s Accuracy (05:50 – 06:06) Final verification of the Expert Advisor’s accuracy by comparing its calculated value with the actual moving average value on the chart.   If you have been trading for a while, chances are high that you have used or maybe you have seen a moving average. This is a moving average and it is a line and you can use it to find out if the current price is above or below the average value of a particular number of candles. This is a moving average for the last twenty candles and if you right click on it, you can change the properties here. So let’s change the period to one and now you see that the moving average for one candle is connecting all the closed prices. This is a bearish candle so it closes here. This is a bullish candle so here is the closing price. Let’s look again at the properties and select one hundred and now you don’t even see the moving average because it’s far above the candles. As traders we use moving averages to find out if it’s going down and that would be the case when the current prices crosses the moving average from the above. Or if it’s going up and that would be the case when the current price crosses the moving average from below. Now how can we create an Expert Advisor for this? Now if you point your mouse on any point of the moving average, you will see a value and you will see that the value would change with very candle. Here it is 0.988749 and the closing price is 0.98848. So let’s create an Expert Advisor for that, to do that please hit this little button here or press the F4 key to bring up the Meta Editor. Now you need to click on new Expert Advisor from template, continue. We will give it the name simple moving average, continue, continue,
    7 min
  • MQL5 TUTORIAL – PLATIN SYSTEM – DEMARKER OSCILLATOR
    In this little video, we are going to calculate an entry signal for this Oscillator that is called the DeMarker Oscillator. It is not so well known, but we will create an entry signal for it. So let’s see how we can do that with MQL5.   A separate window below the candle chart shows the Demarker oscillator.   It has a scale and two lines.   Most of the time, oscillators are used to filter other signals, but they can also be used to make entry signals, which is what we’ll do here.   To use it, we need to create a separate MQ5 file and put it in the same folder as the other Platin System files.   CheckEntry iDEMARKER mq5 is the name of the file, and CheckEntry is the only function it has.   It will figure out what our entry signal is and send that info back to the main module.   We want to make a string variable for the calculated signal, but we won’t give it a value yet because that will be figured out later.   We need a price array. Please choose the type double as it can hold floating type values.   MQL5 includes a function called iDEMARKER that we can use to define our oscillator.   A few parameters need to be set. The first parameter is the chart’s symbol. The period on the chart is the second parameter.   And the last parameter is used for the number of candles we want to use for our calculation.   When you drag the Demarker oscillator onto one of your charts, you will also see these values.   Now we use array set as series to sort the array that we have created from the current candle 0 downwards.   With CopyBuffer, we put data into the array. We do it  according to our definition from above and calculate values for buffer 0, beginning with the current candle 0 and the next three candles.   Let’s keep going and figure out the current candle’s value by looking at the value of candle 0 in our array. With Normalize Double we can format the value to show 3 digits behind the dot.   To figure out when to buy, we look for a value that is below the lower line. That would be the case then it is below 0.3 !   So it would be a buy signal, and when that happens, we give our signal the word “buy.”   Otherwise, if the value is above 0.7 or above the upper line of the oscillator scale that would be a sell signal, so we put the word “sell” into our signal.   At the end of the function, the signal is sent back to the main module using the return command.   Please don’t forget to save the file!   You don’t need to compile it right now. Just save it and go back to where the OnTick function is in the main module.   There, you need to add the new file to the section that contains the include statements. Using the include statement, followed by the name of the file we have created.   Please use two slashes to comment out any other entry signals, and press F7 or click the Compile button to compile both the main module and the new entry file you just made.   Okay, I hope that the compilation process has worked for you. You should now be able to use the DeMarker Oscillator either as an entry signal or as a filter.   Thank you for watching this video, and I will see you in the next one.
    5 min
  • MQL5 TUTORIAL – PLATIN SYSTEM – IDEMA INDICATOR
    In this video we are going to calculate this little red line here. It is called the double exponential moving average, and we will now create an entry module to calculate buy and sell signals.   This time, we’re going to figure out the IDEMA indicator and use it to calculate a trading system entry signal.   The IDEMA indicator is painted right on the candle chart, and it shows up as a red line. If you point your mouse cursor over it, you will see that it creates a double exponential moving average.   To start, we make a new file called CheckEntry IDEMA and put it in the same directory as the other system files.   The new file will use a function called CheckEntry, and we’ll make a variable called signal that will be used to return our calculated signal at the end of the function.   We’ll also need an array to store price information for a few candles.   Now, we use Array set as Series to sort our array starting with the current candle and going down.   With copy rates we fill our price array with data.   We do it for the current symbol and the currently selected period, starting from the current candle 0 and copy the data for 3 candles to store them in our price array.   For the indicator we need a new array that we also need to sort downwards by using array set as series.   Let’s keep going and define what our function is. For this, MQL5 has a built-in function called IDEMA.   There must be 5 parameters defined. The first two are for the current symbol and period on the chart, and the third is for the calculation period. It is 14 in our case.   Parameter 4 is for a potential candle shift, we set it to 0.   And the last parameter defines that we are going to calculate the result based on close prices.   With copy buffer we can now fill our Array with price data according to our definition. We do that for buffer 0, starting from the current candle and store the prices for 3 candles.   Afterwards, you can now get the value for the current candle by looking at that price array and, in particular, the value for candle 0.   We can now figure out the buy signal.   When the red line is below the close price for candle 1, we want to use that as a sign to buy.   So let’s give our signal the word “buy.”   In the other case, we want to sell whenever the red line is above the close price of candle 1.   At that point, we want to give the signal variable the value “sell.”   At the end of the function, please use the return function to send the calculated value back to our main module.   The entry module is now finished. Save it right away.   Then you need to open the main file and look for the part where you need to add the entry signal.   You can do that by putting the file name for our entry signal after the include statement.   Please disable any other entry signal by putting two slashes in front of it.   When you’re done, you can compile the main module and the entry module you just made by pressing F7 or clicking the compile button.   If everything went well, you shouldn’t get any errors!   If you do, please look at the error messages and try to figure out what they mean.   On MQL5.com, you can find a list of all of these error codes.   Okay, by now you should have a working for the double exponential moving average indicator that we see on our chart. I would like to say thank you for watching this video and I will see you in the next one.
    4 min
  • MQL5 TUTORIAL – PLATIN SYSTEM – BULLS POWER OSCILLATOR
    In this video, we are going to create an entry signal for the bolts Power Oscillator. It looks very similar to the Bears Power Oscillator that we have created before. And it’s similar to do. So let’s find out how to do it with MQL5.    This time, we’re going to figure out the Bulls power oscillator and use it to make a trading system entry signal.   The Bulls Power is shown below the candle chart, and it shows numbers that are either above or below 0.   To start, we make a new file called CheckEntry BullsPower and put it in the same directory as the other system files.   The new file will use a function called CheckEntry, and we’ll make a variable called signal that will be used to return our calculated signal at the end of the function.   We’ll also need an array to store price information for a few candles.   Now, let’s keep going and define what our oscillating function is. For this, MQL5 has a built-in function called iBullsPower.   There must be three parameters. The first two are for the current symbol and period on the chart, and the third is for the calculation period. It is 13 in our case.   Then, we use Array set as Series to sort our array starting with the current candle and going down.   Now we can use CopyBuffer to add data to our array.   We do it for the definition we just made and for buffer 0!   We want to start with the current candle 0 and copy the price data for the next three candles.   Our price array holds the result.   And because of that, you can now find the value for the current candle by looking at that price array and, in particular, the value for candle 0.   We can now figure out the buy signal.   When the Bulls power value is greater than 0, we want to use that as a sign to buy.   So let’s give our signal the word “buy.”   In the other case, we want to sell whenever the value is less than 0.   At that point, we want to give the signal variable the value “sell.”   At the end of the function, please use the return function to send the calculated value back to our main module.   The entry module is done, now. Save it right away.   Then you need to open the main file and look for the part where you need to add the entry signal.   You can do that by putting the file name for our entry signal after the include statement.   Please remove  any other entry signal by putting two slashes in front of it.   When you’re done, you can compile the main module and the entry module you just made by pressing F7 or clicking the compile button.   If everything went well, you shouldn’t get any errors, just some warnings!!   Okay, that’s it for the Bulls Power Oscillator. Smart idea to do two Oscillators that look almost exactly the same. Thank you for watching this video. I will see you in the next one.
    4 min
  • MQL5 TUTORIAL – PLATIN SYSTEM – BEARS POWER OSCILLATOR
    In this video, we are looking at the Bears Power Oscillator. That’s the little Oscillator here below the candle chart. So let’s find out how to create an expert advisor entry signal for this Oscillator.   This time we want to calculate the bears power oscillator and use it to create an entry signal for your trading system.   The Bears Power is shown below the candle chart and it creates values that are either above or below 0!   To get started, we create a new file called CheckEntry_BearsPower in our directory where the other system files are already stored.   The new file will use a function called CheckEntry and we create a variable called signal that will be used to return our calculated signal, at the end of the function.   And, of course, we also need an array to hold price data for a few candles.   Now let’s continue and create a definition for our oscillating function. MQL5 offers an integrated function for that called iBearsPower.   Three parameters are required. The first two are for the current symbol and period on the chart, the third one is for the calculation period. In our case it is 13.   Afterwards we use Array set as Series to sort our array from the current candle downwards.   And now we can fill our array with data by using CopyBuffer.    We do it for the definition that we have created a minute ago and for buffer 0!   We want to start with the current candle 0 and copy price data for 3 candles.   The result is stored in our price array.   And that makes it possible to now get the value for the current candle by looking into that price array and especially at the value for candle 0!   Now we can calculate the buy signal.   Whenever the bears power value is above 0 we want to use it as a buy signal.   So let’s assign the word buy to our signal.   In the other case, we want to sell whenever the value is below 0!   That is when we want to assign the word sell to the signal variable.   And now please use the return function to return the calculated value to our main module at the end of the function.   That’s it for the entry module. Please save it now.   And afterwards you need to open the main file and look for the part where the entry signal now needs to be included.   You can do that by using the include statement followed by the file name for our entry signal.   Please outcomment any other entry signal by adding two slashes.   When you are finished, you can press F7 or click the compile button to compile the main module and the entry module you have just created!   If everything went well, you should not get any errors!   If you do, please check out the error messages and what they mean!   On MQL5.com there is a list of those error codes available!   Okay, by now, you should have a working version for the Bears Power Oscillator. I would like to say thank you for watching this video and I will see you in the next one.
    4 min
  • MQL5 TUTORIAL – PLATIN SYSTEM – CHAIKIN OSCILLATOR
    In this video, we are going to create an entry module for this oscillator here. It is called the Chaiken oscillator. So let’s find out how we can code an entry module.   The chaikin oscillator is usually used to confirm other signals, because it is an oscillator.   But in this example we will use it to generate buy and sell signals!   Let’s create a new file called CheckEntry_Chaikin.mp5 in the same directory where the other files are stored.   Like we have done for other entry modules we need to create a function called CheckEntry.   The signal is later returned by this function.   And now we need a string variable and a price array!   MQL5 comes with a function called iChaikin that we can use to create our definition for the calculation.   Parameter 1 is for the current symbol and parameter 2 for the current period on our chart.   Afterwards we have two numbers!   If you open Metatrader5 and select insert, indicators, oscillators, you will learn that these values are for the fast moving average and for the slow moving average.   The standard values are 3 and 10!   The following parameter is used to define that we want to calculate the result based on Mode_EMA, that stands for exponential moving average.   And in the last parameter we have defined that the result should be calculated on the tick basis.   Now let’s continue and sort the array from the current candle downwards by using array set as series.   And then we use Copy Buffer to fill our array with data!   We do it for the formerly created definition and buffer zero, starting from the current candle 0.   We want to store the values for 3 candles in our array!   Now we can calculate the values for the current candle and the one before.   We do that by looking at the values of candle 0 and candle 1 in our array.   If the current chaikin value is above 0 and the previous value was below 0, we consider that to be a buy signal and assign the word buy to our signal.   Otherwise, if the current value is below 0 and the previous value was above 0, that will be a sell signal, so we assign the word sell to our signal.   And finally we use the return function to return the calculated value to our main module.   That is it for the entry, please do not forget to save it.   Compiling is not required as it is imported into the main module.   Now let’s open the main module and find the include section.   There you can outcomment the other entry modules with two slashes and add a new include statement for the new file that we have created.   And now we need to press F7 or click on the compile button to compile both modules.   You will see some warnings, but you should not get any errors.   Okay, so far, this is it for the Chaikin oscillator. I hope the compilation process worked for you. Thank you for watching, and thank you for watching, and I will see you in the next video.
    4 min
  • MQL5-TUTORIAL-PLATIN-SYSTEM-THE-AWESOME-OSCILLATOR
    This colorful indicator here below the chart window is called the awesome Oscillator. We want to create an entry signal to calculate the values for our entry signals that are traded here. So let’s find out how we can do that with MQL5.   Since the Awesome indicator is an oscillator, it will be shown in a separate window below the candle chart.   To use it, we make a separate MQ5 file and put it in the same directory as the other Platin System files.   CheckEntry IAO.mq5 is the name of the file, and it only has one function called CheckEntry.   The buy and sell signals for our system are worked out by this function.   We start with a string variable called signal, but we don’t give it a value right away because we’ll figure that out later.   The next thing we do is make an array. We use the “double” data type because it can also be used with “floating point” numbers.   Then, we use the function iAO that comes with MQL5 to create a definition for the Awesome Oscillator signal.   And we want to do that for the current symbol on the chart and the period that is currently selected on that chart.   No further parameters are required.   Now we use Array Set as Series for our IAO Array to sort it from the current candle downwards.   Afterwards we can fill our IAO Array according to the definition that we have done above.   We do it for buffer 0, starting from candle 0 for 3 candles and store the values in our price array.   That makes it possible to calculate the current IAO Value by looking at candle 0 in our array.   With normalize double, we make sure to format the output with 6 digits behind the dot, as this is how the value also looks like when you add the oscillator manually to your chart.   Now, let’s continue with the calculation for the signal.   If the current value is above 0 we want to buy, so we assign the word buy to our signal.   And when the current value is below 0, we want to sell so we assign the word sell to the signal.   The last part is to give back the calculated value by using the return function and we also need to save the file.   Compiling will be done in the main file, so please open it and look for the include statements that are already contained in the source code.   There we will use two slashes to outcomment the other entry signals and add another line to include the new file called CheckEntry_ IAO.mq5.   Afterwards we can click the compile button or simply press the F7 key to get both files compiled.   A few warnings are expected, but you should not see any further error codes.   Okay, by now, you should have a compiled version for this little oscillator here. You see that it’s creating lots of trades. And I would like to say thank you for watching this video, and I will see you in the next one.
    4 min
  • MQL5 TUTORIAL – PLATIN SYSTEM – STOCHASTIC OSCILLATOR
    In this video, we want to check out this Oscillator here. It is called the Stochastic oscillator, and it is very popular. So let’s find out how we can create an entry signal for this one with MQL5.   In this video, we’re going to make an entry signal for this little oscillator that an expert advisor can use. It’s called the “Stochastic oscillator,” and a lot of people use it. So let’s find out how MQL5 can help us do that.   The Stochastic oscillator is shown in a separate window below the candle chart.   It has two lines and a scale.   Most of the time, oscillators are used to filter out signals, but they can also be used to make entry signals, which is what we’ll do here.   To use it, we make a separate MQ5 file and put it in the same folder as the other Platin System files.   The file is called CheckEntry Stochastic.mq5, and it has only one function called CheckEntry.   It will figure out what our entry signal is and send that information back to the main module.   We want to make a string variable for the calculated signal, but we won’t give it a value yet because that will be worked out later.   Now we need two double-type arrays to hold the different prices.   The first one is called the K-Array and the second one is called the D-Array.   We sort both arrays from the current candle downwards by using Array set as Series.   MQL5 comes with a function called iStochastic which we can use to create a definition for our oscillator.   We need to pass a few parameters. The first parameter is for the symbol on the chart. The second parameter is for the period on the chart.   Parameters 3, 4 and 5 are the standard values for the Stochastic oscillator to define the so-called K-period, the D-period and the slowing. You will also see these values when you drag the Stochastic indicator onto one of your charts.   In the last two parameters, we define that we want to use MODE_SMA which stands for the simple moving average mode and we want to calculate the result based on the low and high prices.   With CopyBuffer we fill both arrays with data and we do that for buffer 0 and buffer 1. In both cases from the current candle 0 and for 3 candles.   Let’s continue and calculate the value for the current candle by looking at the value of candle 0 in both arrays.   Afterwards we do the same for the candle before by looking at the values for candle 1 in both arrays.   To calculate the buy signal, we check for a crossover.   So if the K-value and the D-value for candle 0 are below 20, we want to know if the K-value is now above the D-value and if it was below for the candle before.   That would be a buy signal and that is when we assign the word buy to our signal.   Otherwise, if the K-value and the D-value for candle 0 are above 80 we want to know if the K-value is now below the D-value and if it was higher for the candle before.   That would be a sell signal and that is when we assign the word sell to our signal.   At the end of the function we use the return command to return the signal to the main module.   Please remember to save the file.   You don’t have to compile it. Just save it and go back to the main module, where the OnTick function is.   There, you must add the new file to the include section. This can be done with the help of the include statement.   Please use two slashes to outcomment any other entry signals and press F7 or click the Compile button to compile both the main module and the new entry file you just made.   Okay, if everything worked out as it should, you should now have a working version for the Stochastic Oscillator. Please note that this one will not create so many signals, because it will only create signals when we see a cross over here. That’s it for now. Thank you for watching, and I will see you in the next video.
    5 min