How to create a simple Momentum Expert Advisor with MQL5

video
play-sharp-fill

 

  • Introduction and Objective:
    • The tutorial focuses on creating an expert advisor that utilizes the momentum indicator. The momentum indicator is believed by some traders to predict the continuation of a trend, remaining positive during an uptrend and negative during a downtrend.
  • Initial Setup in MetaEditor:
    • Users are guided to open the MetaEditor by clicking on a specific icon or pressing the F4 key.
    • A new file is initiated within the MetaEditor, named “simple momentum”.
  • Array Creation and Initialization:
    • An array, “price data”, is established to store price data for the last three candles.
    • The array is populated using the copyrates function, which captures the price data for the specified candles.
  • Momentum Definition and Calculation:
    • The momentum is defined using the built-in function and is calculated based on 14 candles using the close prices.
    • An array, “mypricearray”, is set up to store the momentum values.
  • Signal Generation and Logic:
    • The expert advisor checks the momentum values. If the value surpasses 100, it indicates a strong momentum, and if it’s below 999, it indicates weak momentum.
    • Depending on the momentum value, appropriate trading signals are generated.
  • Displaying Results:
    • A comment function is utilized to display the current momentum value and its strength (strong or weak) directly on the MetaTrader chart, offering real-time insights to users.
  • Testing and Visualization:
    • After coding, users are advised to compile the code to ensure its correctness.
    • 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.
  • Conclusion and Further Learning:
    • The tutorial demonstrates the expert advisor’s capability to effectively trade based on the momentum indicator in MQL5.
    • While the momentum indicator can be a standalone tool, it’s often used in conjunction with other indicators, such as moving averages, to enhance trading strategies.

By following this tutorial, users can effectively create an expert advisor that trades based on the momentum indicator, allowing for informed trading decisions based on real-time signals.


Video Timestamps

  • 0:00 – Introduction to the momentum indicator and its significance in predicting trends.
  • 0:30 – Locating the momentum indicator in Metatrader and its default settings.
  • 1:00 – Starting the MQL5 process: Opening the MetaEditor.
  • 1:30 – Creating a new Expert Advisor and setting up the basic structure.
  • 2:00 – Defining the price array and properties for the momentum.
  • 2:30 – Using the iMomentum function and sorting the price array.
  • 3:00 – Filling the price array and retrieving the value of the current candle.
  • 3:30 – Displaying the momentum value on the chart based on conditions.
  • 4:00 – Compiling the Expert Advisor and returning to MetaTrader.
  • 4:30 – Testing the Expert Advisor in the strategy tester.
  • 5:00 – Observations on the momentum indicator’s behavior and its potential combinations with other indicators.

Related Questions and Answers:

  1. What is the primary focus of the tutorial?
    • The tutorial centers on creating an expert advisor in MQL5 that trades based on signals from the momentum indicator, a tool believed by some traders to predict the continuation of a trend.
  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 momentum” file in MetaEditor?
    • The “simple momentum” file is initiated within the MetaEditor to code and develop the expert advisor that trades based on the momentum indicator 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, which captures price data for the specified number of candles.
  5. How is the momentum indicator defined and calculated in the tutorial?
    • The momentum is defined using a built-in function and is calculated based on 14 candles using their close prices. An array named “mypricearray” is set up to store the momentum values.
  6. How does the expert advisor generate trading signals based on the momentum?
    • The expert advisor evaluates the momentum values. If the value exceeds 100, it indicates strong momentum, while values below 999 indicate weak momentum. Trading signals are generated based on these momentum values.
  7. How are the results of the expert advisor displayed to the user?
    • A comment function is used to display the current momentum 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 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.
  9. How does the tutorial view the momentum indicator in the context of broader trading strategies?
    • While the momentum indicator can serve as a standalone tool, the tutorial mentions that it’s often paired with other indicators, such as moving averages, 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 momentum indicator, allowing for informed trading decisions based on real-time signals.