How to create a MacD EA with MQL5

video
play-sharp-fill
  • Introduction and Objective:
    • The tutorial delves into the MACD (Moving Average Convergence Divergence) indicator, an old and reliable tool created in 1979 by Gerald Appel. The MACD helps identify potential bullish or bearish trends in the market. When the MACD is above a certain line, it may indicate a bullish trend, and when below, a bearish trend. The crossing of the MACD lines can also be a good indication of a potential trend reversal.
  • Initial Setup in MetaEditor:
    • Users are guided to open the MetaEditor by clicking a specific icon or pressing the F4 key.
    • A new file is initiated within the MetaEditor, named “simple MACD”.
  • Array Creation and Initialization:
    • Two arrays, “mypricearray0” and “mypricearray1”, are established to store price data for the last three candles.
    • The copyrates function is used to populate these arrays with price data.
  • MACD Definition and Calculation:
    • The MACD is defined using the built-in MQL5 function. It calculates based on the last thirteen candles, considering fast and slow exponential moving averages.
    • The MACD values are stored in the arrays created earlier.
  • Signal Generation and Logic:
    • The expert advisor evaluates the MACD values. Depending on the MACD’s position relative to the zero line, it will display “trending upwards” or “trending downwards” on the MetaTrader chart.
  • Testing and Visualization:
    • After coding, users are advised to compile the code.
    • The functionality is then tested in MetaTrader using the strategy tester, with visualization providing a real-time view of the expert advisor in action.
  • Conclusion and Further Learning:
    • The tutorial showcases the expert advisor’s capability to effectively trade based on the MACD indicator in MQL5. The MACD is a versatile tool that can be used to spot potential bullish or bearish trends in the market.

By following this tutorial, users can effectively create an expert advisor that trades based on the MACD indicator, allowing for informed trading decisions based on the indicator’s signals.


Video Timestamps

  • 0:00 – Introduction to the MACD indicator and its history.
  • 0:30 – Explanation of the MACD’s behavior above and below its signal line.
  • 1:00 – Starting the MQL5 process by opening the MetaEditor.
  • 1:30 – Setting up the basic structure for the Expert Advisor named “Simple MACD”.
  • 2:00 – Creating an array to hold price data and defining the MACD function.
  • 2:30 – Sorting the price array and filling it with recent price data.
  • 3:00 – Calculating the MACD value for the current candle.
  • 3:30 – Creating a chart output based on the MACD value.
  • 4:00 – Compiling the Expert Advisor and testing it in MetaTrader.
  • 4:30 – Observing the Expert Advisor’s output on the MetaTrader chart.
  • 5:00 – Explanation of the MACD’s behavior in bearish and bullish trends.
  • 5:30 – Conclusion: Creating an Expert Advisor for the MACD indicator with a few lines of MQL5 code.

Related Questions and Answers:

  1. What is the main focus of the tutorial?
    • The tutorial focuses on the MACD (Moving Average Convergence Divergence) indicator and how to create an expert advisor in MQL5 that trades based on the MACD signals.
  2. Who created the MACD indicator and when?
    • The MACD indicator was created by Gerald Appel in 1979.
  3. How does the MACD help in market analysis?
    • The MACD helps identify potential bullish or bearish trends in the market. When the MACD is above a certain line, it may indicate a bullish trend, and when below, a bearish trend. The crossing of the MACD lines can also indicate a potential trend reversal.
  4. How can users open the MetaEditor?
    • Users can open the MetaEditor by clicking a specific icon or pressing the F4 key.
  5. What is the purpose of the “simple MACD” file in MetaEditor?
    • The “simple MACD” file is initiated within the MetaEditor to code and create the expert advisor based on the MACD indicator.
  6. What are “mypricearray0” and “mypricearray1”?
    • These are two arrays established to store price data for the last three candles.
  7. How is the MACD defined and calculated in the tutorial?
    • The MACD is defined using the built-in MQL5 function, which calculates based on the last thirteen candles, considering fast and slow exponential moving averages.
  8. How does the expert advisor interpret the MACD values?
    • Depending on the MACD’s position relative to the zero line, the expert advisor will display “trending upwards” or “trending downwards” on the MetaTrader chart.
  9. What steps should be taken after coding the expert advisor?
    • After coding, users should compile the code and then test its functionality in MetaTrader using the strategy tester. Visualization provides a real-time view of the expert advisor in action.
  10. What is the significance of the MACD in trading?
  • The MACD is a versatile tool that can be used to spot potential bullish or bearish trends in the market, allowing traders to make informed decisions based on the indicator’s signals.