How to find new chart candles with MQL5

video
play-sharp-fill
  • Introduction and Objective:
    • The tutorial introduces the creation of an expert advisor that counts new candles on a chart. This is essential as many trading strategies rely on close prices, and by counting candles, traders can optimize resource usage and avoid potential computer crashes during fast market movements.
  • Initial Setup in MetaEditor:
    • Users are directed to access the MetaEditor by clicking on an icon or pressing the F4 key.
    • A new file is initiated within the MetaEditor, named “simple new candle”.
  • Array Creation and Initialization:
    • An array named “price data” is crafted to store price data for the last three candles.
    • The array is filled with data using the copyrates function, which captures price data for the specified number of candles.
  • Timestamp and Candle Counting:
    • Two datetime variables are created: one to hold the timestamp of the last check and another for the current candle.
    • A static integer, “candle counter”, is used to count the number of new candles since the expert advisor’s last start.
  • Signal Generation and Logic:
    • The expert advisor checks if a new candle has been created by comparing the current candle’s timestamp with the last checked timestamp.
    • If a new candle is detected, the candle counter is incremented.
  • Displaying Results:
    • A comment function is employed to display the current candle count directly on the MetaTrader chart, providing users with real-time insights.
  • Testing and Visualization:
    • After coding, users are prompted to compile the code to ensure its accuracy.
    • The functionality is subsequently tested in MetaTrader using the strategy tester, with a visual mode offering a real-time view of the expert advisor in action.
  • Conclusion and Further Learning:
    • For those unfamiliar with the coding aspects or who find the tutorial’s pace challenging, there are suggestions to explore other basic video series or consider a premium course for a comprehensive understanding.
    • The tutorial concludes by showcasing the expert advisor’s capability to effectively count new candles on a chart, providing valuable insights for traders.

By following this tutorial, users can effectively create an expert advisor that counts new candles on their chart, allowing for optimized resource usage and more efficient trading strategies.


Video Timestamps

  • 0:00 – Introduction: The importance of counting new candles on the chart.
  • 0:30 – Explanation of how an Expert Advisor can trade multiple positions and the challenges with multiple price moves.
  • 1:00 – The significance of using close prices in trading strategies and the potential resource challenges with high-tech computers.
  • 1:30 – Emphasizing the need to save resources to avoid computer crashes.
  • 2:00 – Starting the MQL5 process: Opening the MetaEditor and setting up the basic structure for the Expert Advisor.
  • 2:30 – Creating a price array to hold price data and sorting the array.
  • 3:00 – Filling the array with data using the copy rates function.
  • 3:30 – Implementing a new candle counter and creating timestamp variables to track the current and last checked candles.
  • 4:00 – Compiling the Expert Advisor and testing it in MetaTrader.
  • 4:30 – Observing the results of the Expert Advisor in real-time on the chart.

Related Questions and Answers:

  1. What is the primary focus of the tutorial?
    • The tutorial centers on creating an expert advisor in MQL5 that counts new candles on a chart, which is crucial for optimizing resource usage in trading strategies, especially during rapid market movements.
  2. How can users access the MetaEditor for coding?
    • Users can open the MetaEditor by clicking on a specific icon or pressing the F4 key.
  3. What is the purpose of the “simple new candle” file in MetaEditor?
    • The “simple new candle” file is initiated within the MetaEditor to code and develop the expert advisor that counts new candles on a chart.
  4. How is the array named “price data” utilized in the tutorial?
    • The “price data” array is designed to store price data for the last three candles. It is populated using the copyrates function, which captures price data for the specified number of candles.
  5. How does the expert advisor determine and count new candles?
    • Two datetime variables are set up to hold timestamps of the last check and the current candle. The expert advisor checks for new candles by comparing these timestamps. If a new candle is detected, a static integer named “candle counter” increments.
  6. How are the results of the expert advisor displayed to the user?
    • A comment function is used to display the current candle count directly on the MetaTrader chart, offering users real-time insights.
  7. What steps should be taken after coding the expert advisor?
    • After coding, users should compile the code to ensure its accuracy. The functionality is then tested in MetaTrader using the strategy tester, with a visual mode providing a real-time view of the expert advisor in action.
  8. What resources are suggested for learners who find the tutorial’s pace challenging?
    • For those unfamiliar with the coding aspects or who find the tutorial challenging, it’s recommended to explore other basic video series or consider enrolling in a premium course for a more comprehensive understanding.
  9. What can users achieve by following this tutorial?
    • By following this tutorial, users can effectively create an expert advisor that counts new candles on their chart. This allows for optimized resource usage, potentially preventing computer crashes during fast market movements and leading to more efficient trading strategies.
  10. Why is counting new candles on a chart significant for traders?
  • Counting new candles is essential as many trading strategies rely on close prices. By counting candles, traders can optimize resource usage, ensuring smoother trading operations, especially during rapid market movements.