How to check the spread with MQL5

video
play-sharp-fill

 

  • Introduction and Objective:
    • The tutorial delves into the creation of an expert advisor capable of calculating the highest and lowest spread for a specified number of candles in a currency pair.
  • Initial Setup in MetaEditor:
    • Users initiate the process by clicking on an icon or pressing the F4 key to access the MetaEditor.
    • Within the MetaEditor, a new file is created and named “simple spread checker”.
  • Setting Parameters:
    • An input value is defined to specify the number of candles to be considered. The tutorial uses five candles as an example.
    • This input allows users to modify the number of candles without recompiling the code.
  • Spread Calculation:
    • Two variables, “lowest spread value” and “highest spread value”, are initialized to track the spread range.
    • The mql rates array is employed to gather price, volume, and spread data.
    • The array is sorted and filled with data for the desired number of candles.
  • For Loop Implementation:
    • A for loop is utilized to iterate through the specified candles.
    • For each candle, the spread is determined and compared to the current highest and lowest spread values.
    • If the spread of the current candle is outside the existing range, the highest or lowest spread value is updated accordingly.
  • Chart Output:
    • A comment statement is used to display the lowest and highest spread values directly on the MetaTrader chart.
    • This visual representation aids users in quickly discerning the spread range for the specified candles.
  • Testing and Visualization:
    • After coding, users are guided to compile the code and rectify any potential errors.
    • The functionality is then tested in MetaTrader using the strategy tester.
    • The visual mode allows users to observe the changing spreads and verify the accuracy of the expert advisor.
  • Conclusion and Further Learning:
    • For those who might find the tutorial’s pace challenging or are unfamiliar with the coding aspects, there are suggestions to explore other basic video series or consider a premium course for a comprehensive understanding.
    • Feedback and suggestions from premium course members are encouraged, emphasizing the tutorial’s commitment to continuous learning and improvement.
    • The tutorial concludes by demonstrating the expert advisor’s efficacy in accurately calculating the highest and lowest spread for a given number of candles.

By following this tutorial, users can effectively create an expert advisor that calculates the spread range for a specified number of candles, offering valuable insights into market conditions and spread fluctuations.


Video Timestamps

  • 0:00 – Introduction to calculating the highest and lowest spread for a certain number of candles in a currency pair using MQL5.
  • 0:30 – Opening the MetaEditor to start the MQL5 process.
  • 1:00 – Setting up the basic structure for the Expert Advisor named “Simple Spread Checker”.
  • 1:30 – Creating a simple array for integer values and assigning values to it.
  • 2:00 – Passing the whole array to a function called “addvalues” and displaying the returned result on the chart.
  • 2:30 – Creating the “addvalues” function and adding the ampersand symbol to pass the array by reference.
  • 3:00 – Adding values for the array and returning the results to the main function.
  • 3:30 – Compiling the Expert Advisor and testing it in MetaTrader.
  • 4:00 – Observing the returned result on the MetaTrader chart.
  • 4:30 – Adding another value to the array, recompiling the code, and observing the new returned value.
  • 5:00 – Conclusion: The effectiveness of the Expert Advisor in calculating the highest and lowest spread for a certain number of candles.
  • 5:30 – Encouraging viewers to watch other videos in the basic video series or consider the premium course for more in-depth knowledge.
  • 6:00 – Testing the Expert Advisor in Metatrader and observing the changing spreads for a currency pair with a high spread value.
  • 6:30 – Adjusting the settings to test for a different number of candles and observing the results.
  • 7:00 – Conclusion: The Expert Advisor works as expected, demonstrating its ability to calculate the highest and lowest spread for a specified number of candles.

Related Questions and Answers:

  1. What is the primary objective of the tutorial?
    • The tutorial aims to guide users on creating an expert advisor in MQL5 that calculates the highest and lowest spread for a specified number of candles in a currency pair.
  2. How can users access the MetaEditor for coding?
    • Users can access the MetaEditor by clicking on an icon or pressing the F4 key.
  3. What is the significance of the “simple spread checker” file in the MetaEditor?
    • Within the MetaEditor, a new file named “simple spread checker” is created to code and develop the expert advisor for checking the spread.
  4. How does the tutorial specify the number of candles to consider for spread calculation?
    • An input value is defined to specify the number of candles to be considered. The tutorial uses five candles as an example, allowing users to modify the number without recompiling the code.
  5. How are the highest and lowest spread values determined?
    • Two variables, “lowest spread value” and “highest spread value,” are initialized. A for loop iterates through the specified candles, determining the spread for each candle and updating the highest or lowest spread value if the current candle’s spread is outside the existing range.
  6. How are the spread values displayed to the user?
    • A comment statement is used to display the lowest and highest spread values directly on the MetaTrader chart, providing a visual representation of the spread range for the specified candles.
  7. What steps should be taken after coding the expert advisor?
    • After coding, users are advised to compile the code, rectify any potential errors, and then test its functionality in MetaTrader using the strategy tester. The visual mode allows users to observe the changing spreads and verify the expert advisor’s accuracy.
  8. How does the tutorial emphasize the adaptability of the MetaTrader platform?
    • The creation of a custom expert advisor for checking the spread showcases the adaptability of the MetaTrader platform. Users are encouraged to explore further customizations to enhance their trading experience.
  9. What options are available for learners who find the tutorial’s pace challenging?
    • For those who find the tutorial challenging or are unfamiliar with the coding aspects, the tutorial suggests exploring other basic video series or considering a premium course for a more in-depth understanding.
  10. How does the tutorial view feedback from its premium course members?
  • Feedback and suggestions from premium course members are encouraged, emphasizing the tutorial’s commitment to continuous learning and improvement.