How to create an Adaptive moving Average EA with MQL5

video
play-sharp-fill

 

  • Introduction and Objective:
    • The tutorial is centered on the Adaptive Moving Average (AMA) indicator and its application in creating an expert advisor. The AMA is designed to adjust its sensitivity based on market conditions. It was created by Perry Kaufman and can be used to determine potential entries or exits, similar to a simple moving average.
  • Initial Setup in MetaEditor:
    • Users are instructed to open the MetaEditor by clicking a specific icon or pressing the F4 key.
    • A new file is initiated within the MetaEditor, named “simple adaptive moving average”.
  • 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 price data.
  • AMA Definition and Calculation:
    • The AMA is defined using the built-in MQL5 function. It calculates based on the last thirteen candles, with the fast EMA calculated for two candles and the slow EMA for thirty candles.
    • An array, “mypricearray”, is set up to store the AMA values.
  • Signal Generation and Logic:
    • The expert advisor evaluates the AMA values. The indicator’s value and its position relative to the price are displayed on the MetaTrader chart. The AMA can be used to determine potential buy or sell signals based on its position relative to the current price.
  • 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 Adaptive Moving Average in MQL5. The AMA is a versatile tool that adjusts its sensitivity based on market conditions, potentially offering more accurate signals compared to a simple moving average.

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


Video Timestamps

  • 0:00 – Introduction to the Adaptive Moving Average indicator.
  • 0:30 – Background on Perry Kaufmann’s creation of the Adaptive Moving Average.
  • 1:00 – Benefits of the Adaptive Moving Average: less lagging and fewer false signals.
  • 1:30 – Starting the creation of an Adaptive Moving Average Expert Advisor for MetaTrader 5.
  • 2:00 – Setting up the Expert Advisor in MetaEditor.
  • 2:30 – Defining the price array and the properties of the Adaptive Moving Average.
  • 3:00 – Sorting the price array and filling it with data.
  • 3:30 – Using the Copy Buffer function to fill the array with price data.
  • 4:00 – Retrieving the value of the Adaptive Moving Average for the current candle.
  • 4:30 – Compiling the code in MetaEditor and testing the Expert Advisor in MetaTrader.
  • 5:00 – Observing the Adaptive Moving Average value on the chart and its potential trading implications.

 

  1. What is the topic of the video?
    • The video discusses the Adaptive Moving Average Indicator and how to create an Expert Advisor for it in MetaTrader 5.
  2. Who is believed to have created the Adaptive Moving Average Indicator?
    • The Adaptive Moving Average Indicator is believed to have been created by Perry Kaufman.
  3. How does the Adaptive Moving Average differ from a simple moving average?
    • The Adaptive Moving Average has less lagging and generates fewer false signals compared to a simple moving average.
  4. Why might one prefer to use an Adaptive Moving Average?
    • Perry J. Kaufman created the Adaptive Moving Average with a special formula that results in less lagging and fewer false signals, making it potentially more accurate than a simple moving average.
  5. How do you create an Adaptive Moving Average Expert Advisor in MetaTrader 5?
    • In the MetaEditor, select “File”, “New”, “Expert Advisor from template”, name it (e.g., “Simple Adaptive Moving Average”), and then add the necessary MQL5 code.
  6. What is the purpose of the “OnTick” function in the code?
    • The “OnTick” function is a predefined handler used in MQL5 to handle the event of a new tick receipt.
  7. How is the Adaptive Moving Average calculated in the code?
    • The code uses the integrated MQL5 function “iAMA” for the current symbol on the chart and the current period. It calculates prices based on the last nine candles, with the fast Exponential Moving Average (EMA) calculated for two candles and the slow EMA for thirty candles.
  8. How do you test the created Expert Advisor in MetaTrader?
    • In MetaTrader, click on “View”, “Strategy Tester”, select the created Expert Advisor (e.g., “Simple Adaptive Moving Average.ex5”), and start the test.
  9. What does the Expert Advisor display during the test?
    • The Expert Advisor calculates the value of the Adaptive Moving Average and displays it on the chart. It can be used to compare the value of the adaptive moving average to the current price to determine buy or sell signals.
  10. What is the main takeaway from the video?
  • The video teaches viewers how to create an Expert Advisor that uses the Adaptive Moving Average Indicator to determine potential buy or sell signals. This Expert Advisor can be created in less than five minutes with a few lines of MQL5 code.