MQL5 TUTORIAL - Spread Checker explained (in 4 min)

Опубликовано: 17 Октябрь 2024
на канале: MQL5 Tutorial
175
4

https://mql5tutorial.com/?s=spread

In this video, we are going to create an Expert Advisor that calculates and displays the lowest and highest spread values for a given number of candles. Let's see how we can do that.

We start Metaeditor by clicking a little icon or pressing F4.

First, we create a variable named Candles To Count and set its value to 5. This variable will determine how many candles we will analyze.

Inside the On Tick function, we create a variable named Lowest Spread Value and initialize it with a high value. This variable will store the lowest spread value found during the analysis.

We also create another variable named Highest Spread Value and initialize it with 0. This variable will store the highest spread value found.

Next, we create an array named Price Information to hold the price data for the candles. We use the Array Set As Series function to sort the array from the current candle downwards.

We then fill the Price Information array with price data using the Copy Rates function. This function takes five parameters: the symbol for which we want to copy the data, the period for the data, the starting position (0 for the current candle), the number of candles to copy (200 in this case), and the array to store the data.

We use a for loop to go through all the candles specified by the Candles To Count variable. Inside the loop, we calculate the spread for the current candle by accessing the spread value in the Price Information array.

We create a journal output to print the current spread value for each candle.

We then check if the current spread value is lower than the Lowest Spread Value. If it is, we update the Lowest Spread Value with the current spread value.

Similarly, we check if the current spread value is higher than the Highest Spread Value. If it is, we update the Highest Spread Value with the current spread value.

Finally, we use the Comment function to display the lowest and highest spread values on the chart.

At the end, we press F7 to compile the code.

If this was too fast for you or if you don't understand what all the code is doing, you may want to check out the Premium course on our website, or watch one of the basic videos first.

If the compilation works, we go back to MetaTrader by pressing F4 or clicking on the icon.

Back in MetaTrader, we press Control and R to start the strategy tester, pick the Expert Advisor that we have just created, enable the visual mode, and start a strategy test.

We should see the Expert Advisor on the chart.

If you are already a Premium course member and have an idea for a video like this one, you can send us an email.

In this video, we have learned how to create an Expert Advisor that calculates and displays the lowest and highest spread values for a given number of candles with just a few lines of MQL code.

Thanks for watching and I will see you in the next video.


Смотрите видео MQL5 TUTORIAL - Spread Checker explained (in 4 min) онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь MQL5 Tutorial 17 Октябрь 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 175 раз и оно понравилось 4 людям.