How to create a Simple Moving Average Expert Advisor with MQL5

video
play-sharp-fill

 

  • Introduction and Objective:
    • The tutorial provides a comprehensive guide on creating an expert advisor that trades based on signals from the Bollinger Bands. The Bollinger Bands are a popular technical analysis tool that provides buy and sell signals based on price volatility.
  • 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 and request from a YouTube subscriber for an Expert Advisor with two exponential moving averages crossover.
  • 0:30 – Explanation of the crossing of two exponential moving averages and their significance in trading.
  • 1:00 – Buy and sell signals based on the crossover of the moving averages.
  • 1:30 – Challenges of using the indicator in a sideways market.
  • 2:00 – Starting the MQL5 process: Opening the MetaEditor.
  • 2:30 – Setting up the basic structure for the Expert Advisor.
  • 3:00 – Defining two arrays for the moving averages and their properties.
  • 3:30 – Using the IMA function and defining the properties for the exponential moving averages.
  • 4:00 – Filling the arrays and calculating the entry signals based on the crossover.
  • 4:30 – Compiling the Expert Advisor and testing it in MetaTrader.
  • 5:00 – Observing the results of the Expert Advisor in real-time on the chart.
  • 6:00 – Conclusion and the ease of creating a crossover entry signal with MQL5.

Related Questions and Answers:

  1. What is the primary focus of the tutorial?
    • The tutorial offers a detailed guide on creating an expert advisor in MQL5 that counts new candles on a chart, even though the introduction mentions trading based on signals from the Bollinger Bands.
  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.