How to create a commodity channel index EA with MQL5

video
play-sharp-fill

 

 

  • Introduction and Objective:
    • The tutorial is dedicated to creating an expert advisor that employs the Commodity Channel Index (CCI) oscillator. The CCI is designed to determine if a financial instrument is overbought or oversold. When the CCI value rises above the upper line, it’s considered overbought, and when it falls below the lower line, it’s deemed oversold.
  • 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 commodity channel index”.
  • 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.
  • CCI Definition and Calculation:
    • The CCI is defined using the built-in function. It calculates based on the last thirteen candles.
    • An array, “mypricearray”, is set up to store the CCI values.
  • Signal Generation and Logic:
    • The expert advisor evaluates the CCI values. When the indicator is above the upper line, it’s considered overbought, and when it’s below the lower line, it’s deemed oversold.
    • The indicator’s value and its position relative to the price are displayed 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 Commodity Channel Index in MQL5. The CCI 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 Commodity Channel Index, allowing for informed trading decisions based on the indicator’s signals.


Video Timestamps

  • 0:00 – Introduction to the Commodity Channel Index (CCI) as an oscillator.
  • 0:30 – Explanation of the CCI’s ability to indicate if something is overbought or oversold.
  • 1:00 – Highlighting the 100+ and 100- lines of the CCI and their significance.
  • 1:30 – Introduction to the MQL5 function I CCI for creating the Commodity Channel Index.
  • 2:00 – Steps to create an Expert Advisor using the CCI in MetaEditor.
  • 2:30 – Defining the properties of the CCI and creating a price array.
  • 3:00 – Sorting the price array and filling it with data using the Copy Buffer function.
  • 3:30 – Retrieving the CCI value for the current candle and displaying it on the chart.
  • 4:00 – Chart output based on the CCI value: Overbought, Oversold, or No Signal.
  • 4:30 – Compiling the Expert Advisor and testing it in MetaTrader.
  • 5:00 – Observing the CCI’s movement on the chart and its trading implications.

Related Questions and Answers:

  1. What is the primary focus of the tutorial?
    • The tutorial focuses on creating an expert advisor in MQL5 that trades based on signals from the Commodity Channel Index (CCI) oscillator, which determines if a financial instrument is overbought or oversold.
  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 commodity channel index” file in MetaEditor?
    • The “simple commodity channel index” file is initiated within the MetaEditor to code and develop the expert advisor that trades based on the CCI oscillator 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 CCI oscillator defined and calculated in the tutorial?
    • The CCI is defined using a built-in function and is calculated based on the last thirteen candles. An array named “mypricearray” is set up to store the CCI values.
  6. How does the expert advisor generate trading signals based on the CCI oscillator?
    • The expert advisor evaluates the CCI values. When the indicator is above the upper line, it’s considered overbought, and when it’s below the lower line, it’s deemed oversold. This signal and its position relative to the price are displayed on the MetaTrader chart.
  7. How are the results of the expert advisor displayed to the user?
    • The results, including the indicator’s value and its position relative to the price, are displayed directly on the MetaTrader chart.
  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 CCI oscillator in the context of broader trading strategies?
    • The CCI is a versatile tool that can serve as a standalone indicator, but the tutorial mentions that it’s often paired with other indicators to enhance trading strategies.