How to create a simple SAR Expert Advisor with MQL5

video
play-sharp-fill
  • Introduction and Objective:
    • The tutorial is centered on creating an expert advisor that leverages the Parabolic SAR (Stop and Reverse) indicator. The Parabolic SAR is a popular technical analysis tool that provides potential entry and exit points based on price movements.
  • 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 sar”.
  • 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.
  • SAR Definition and Calculation:
    • The Parabolic SAR 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 SAR values.
  • Signal Generation and Logic:
    • The expert advisor checks the SAR values. If the SAR is above the price, it indicates a potential downtrend, and if it’s below the price, it suggests a potential uptrend.
    • Depending on the SAR value and its position relative to the price, appropriate trading signals are generated.
  • Displaying Results:
    • A comment function is utilized to display the current SAR value and its position (above or below the price) 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 Parabolic SAR indicator in MQL5.
    • The Parabolic SAR can be a standalone tool, but it’s often combined with other indicators to enhance trading strategies.

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


Video Timestamps

  • 0:00 – Introduction to the parabolic SAR indicator.
  • 0:30 – Indicator’s ability to show when the direction changes.
  • 1:00 – Explanation of the parabolic SAR’s behavior above and below the price.
  • 1:30 – How to spot potential trading opportunities using the parabolic SAR.
  • 2:00 – Steps to create an Expert Advisor for the parabolic SAR in MQL5.
  • 2:30 – Setting up the Expert Advisor in MetaEditor.
  • 3:00 – Defining the properties of the parabolic SAR and creating a price array.
  • 3:30 – Sorting the price array and filling it with data.
  • 4:00 – Retrieving the SAR value for the current candle and displaying it on the chart.
  • 4:30 – Compiling the Expert Advisor and testing it in MetaTrader.
  • 5:00 – Observing the parabolic SAR’s movement on the chart and its trading implications.

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 Parabolic SAR (Stop and Reverse) indicator, a renowned technical analysis tool.
  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 sar” file in MetaEditor?
    • The “simple sar” file is initiated within the MetaEditor to code and develop the expert advisor that trades based on the Parabolic SAR 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 Parabolic SAR defined and calculated in the tutorial?
    • The Parabolic SAR 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 SAR values.
  6. How does the expert advisor generate trading signals based on the Parabolic SAR?
    • The expert advisor evaluates the SAR values. If the SAR is positioned above the price, it indicates a potential downtrend, while if it’s below the price, it suggests a potential uptrend. Trading signals are generated based on these observations.
  7. How are the results of the expert advisor displayed to the user?
    • A comment function is used to display the current SAR value and its position (either above or below the price) 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 Parabolic SAR in the context of broader trading strategies?
    • While the Parabolic SAR can serve as a standalone tool, the tutorial mentions that it’s often 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 Parabolic SAR, allowing for informed trading decisions based on real-time signals.