How to create a simple average true range EA with MQL5

video
play-sharp-fill

 

  • Introduction and Objective:
    • The tutorial delves into creating an expert advisor that leverages the Average True Range (ATR) indicator. The ATR measures market volatility and is used to predict potential price movements.
  • Initial Setup in MetaEditor:
    • Users are instructed to open the MetaEditor using the designated icon or the F4 key.
    • A new file is initiated within the MetaEditor, named “simple average true range”.
  • Array Creation and Initialization:
    • An array, “price data”, is established to store price data for the last three candles.
    • The copyrates function is used to populate the array with the necessary price data.
  • ATR Definition and Calculation:
    • The ATR is defined using the built-in function and is calculated based on 14 candles, as recommended by J. Welles Wilder Jr., the creator of the ATR.
    • An array, “mypricearray”, is set up to store the ATR values.
  • Signal Generation and Logic:
    • The expert advisor evaluates the ATR values. If the ATR is high, it indicates strong market volatility, and if it’s low, it suggests weak volatility.
    • Depending on the ATR value, appropriate trading signals are generated, indicating either a “strong average range value” or a “weak average true range value”.
  • Displaying Results:
    • A comment function is utilized to display the current ATR value and its strength (strong or weak) directly 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 demonstrates the expert advisor’s capability to effectively trade based on the Average True Range indicator in MQL5.
    • The ATR is a versatile tool that can be combined with other indicators to enhance trading strategies.

By following this tutorial, users can effectively create an expert advisor that trades based on the Average True Range, allowing for informed trading decisions based on market volatility.


Video Timestamps

  • 0:00 – Introduction to the Average True Range indicator and its significance in trading.
  • 0:30 – Observing a sideways market and the low ATR value during such periods.
  • 1:00 – Importance of the ATR value in determining market movements.
  • 1:30 – Explanation of the Average True Range indicator created by J. Welles Wilder Jr.
  • 2:00 – ATR’s ability to measure market volatility over a set number of candles.
  • 2:30 – Steps to create an Expert Advisor for the ATR indicator in MetaEditor.
  • 3:00 – Setting up the Expert Advisor and defining its properties.
  • 3:30 – Sorting the price array and filling it with data using built-in functions.
  • 4:00 – Retrieving the ATR value for the current candle and displaying it on the chart.
  • 4:30 – Compiling the Expert Advisor and testing it in MetaTrader.
  • 5:00 – Conclusion on creating an Expert Advisor using the ATR indicator with MQL5 code.

Related Questions and Answers:

  1. What is the primary focus of the tutorial?
    • The tutorial is dedicated to creating an expert advisor in MQL5 that trades based on signals from the Average True Range (ATR) indicator, a tool that measures market volatility.
  2. How can users access the MetaEditor for coding?
    • Users can open the MetaEditor by clicking on the designated icon or pressing the F4 key.
  3. What is the purpose of the “simple average true range” file in MetaEditor?
    • The “simple average true range” file is initiated within the MetaEditor to code and develop the expert advisor that trades based on the ATR signals.
  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.
  5. How is the Average True Range defined and calculated in the tutorial?
    • The ATR is defined using a built-in function and is calculated based on 14 candles, following the recommendation of J. Welles Wilder Jr., the creator of the ATR. An array named “mypricearray” is set up to store the ATR values.
  6. How does the expert advisor generate trading signals based on the ATR?
    • The expert advisor evaluates the ATR values. If the ATR is high, it indicates strong market volatility, while a low ATR suggests weak volatility. Trading signals are generated based on these observations, indicating either a “strong average range value” or a “weak average true range value”.
  7. How are the results of the expert advisor displayed to the user?
    • A comment function is used to display the current ATR value and its strength (either strong or weak) directly on the MetaTrader chart, offering users real-time insights.
  8. What steps should be taken after coding the expert advisor?
    • After coding, users should compile the code. 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.
  9. How does the tutorial view the ATR in the context of broader trading strategies?
    • The ATR is a versatile tool that can be paired with other indicators to enhance trading strategies.
  10. What can users achieve by following this tutorial?
  • By following this tutorial, users can effectively create an expert advisor that trades based on the Average True Range, allowing for informed trading decisions based on market volatility.