How to create a Bollinger Bands Expert Advisor with MQL5

video
play-sharp-fill
  • Introduction and Objective:
    • The tutorial provides a comprehensive guide on creating an expert advisor that trades based on signals from the Bollinger Bands. The Bollinger Bands are a popular technical analysis tool that provides buy and sell signals based on price volatility.
  • Initial Setup in MetaEditor:
    • Users are directed to access the MetaEditor by clicking on an icon or pressing the F4 key.
    • A new file is initiated within the MetaEditor, named “simplebollingerbands”.
  • Incorporating Essential Files:
    • The trade.mqh file is integrated, which is essential for creating an instance of the cTrade class, named “trade”. This instance is pivotal for executing trading positions.
  • Defining Parameters and Variables:
    • Various parameters, including the ask and bid prices, are set up. These prices are normalized based on the currency pair.
    • An array named “priceinfo” is crafted to store price data for the last three candles.
  • Bollinger Bands Definition and Calculation:
    • The Bollinger Bands are defined using the built-in function, calculated based on 14 candles and the close prices.
    • An array, “mypricearray”, is established to store the Bollinger Bands values.
  • Signal Generation:
    • The expert advisor checks the Bollinger Bands values. If the price surpasses the upper band, a sell signal is generated. Conversely, if the price falls below the lower band, a buy signal is produced.
  • Trading Logic:
    • Based on the generated signal and ensuring no open positions exist, the expert advisor either buys or sells. For instance, a “sell” signal will trigger the sale of a specified lot size.
  • Displaying Results:
    • A comment function is employed to display the current signal directly on the MetaTrader chart, providing users with real-time insights.
  • Testing and Visualization:
    • After coding, users are prompted to compile the code to ensure its accuracy.
    • The functionality is subsequently tested in MetaTrader using the strategy tester, with a visual mode offering a real-time view of the expert advisor in action.
  • Conclusion and Further Learning:
    • For those unfamiliar with the coding aspects or who find the tutorial’s pace challenging, there are suggestions to explore other basic video series or consider a premium course for a comprehensive understanding.
    • The tutorial concludes by showcasing the expert advisor’s capability to effectively trade based on the Bollinger Bands in MQL5.

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


Video Timestamps

  • 0:00 – Introduction to the Bollinger Bands and the significance of the indicator in trading.
  • 0:30 – Visual representation of the Bollinger Bands on the chart and the accuracy of the calculated values.
  • 1:00 – Trading strategy using the Bollinger Bands: Entering short and long trades based on price movements.
  • 1:30 – The advantage of automating the Bollinger Bands trading strategy using an Expert Advisor.
  • 2:00 – Starting the MQL5 process: Opening the MetaEditor and setting up the basic structure for the Expert Advisor.
  • 2:30 – Creating arrays for the Bollinger Bands and sorting them.
  • 3:00 – Defining the Bollinger Bands and copying price information into the arrays.
  • 3:30 – Calculating the actual value for the current candle for each of the three bands and displaying the values on the chart.
  • 4:00 – Compiling the Expert Advisor and testing it in MetaTrader.
  • 4:30 – Visual representation of the Bollinger Bands on the MetaTrader chart and saving the template for future use.
  • 5:00 – Running the strategy tester and observing the results of the Expert Advisor in real-time on the chart.
  • 5:30 – Conclusion: The accuracy of the calculated Bollinger Bands values and the benefits of automating the trading strategy.

  • Related Questions and Answers:

    1. What is the primary focus of the tutorial?
      • The tutorial offers a detailed guide on creating an expert advisor in MQL5 that trades based on signals from the Bollinger Bands, a widely-used 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 “simplebollingerbands” file in MetaEditor?
      • The “simplebollingerbands” file is initiated within the MetaEditor to code and develop the expert advisor that trades based on Bollinger Bands signals.
    4. Why is the trade.mqh file integrated into the tutorial?
      • The trade.mqh file is essential for creating an instance of the cTrade class, named “trade”, which plays a crucial role in executing trading positions.
    5. How are the Bollinger Bands defined and calculated in the tutorial?
      • The Bollinger Bands are defined using a built-in function, calculated based on 14 candles and their close prices. An array named “mypricearray” is set up to store the Bollinger Bands values.
    6. How does the expert advisor generate trading signals based on the Bollinger Bands?
      • If the price exceeds the upper band of the Bollinger Bands, a sell signal is generated. On the other hand, if the price drops below the lower band, a buy signal is produced.
    7. What trading actions does the expert advisor take based on the generated signals?
      • Depending on the generated signal and ensuring no open positions exist, the expert advisor will either buy or sell. For example, a “sell” signal will initiate the sale of a specified lot size.
    8. How are the results of the expert advisor displayed to the user?
      • A comment function is used to display the current trading signal directly on the MetaTrader chart, offering users real-time insights.
    9. 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.
    10. What resources are suggested for learners who find the tutorial’s pace challenging?
    • For those unfamiliar with the coding aspects or who find the tutorial challenging, it’s recommended to explore other basic video series or consider enrolling in a premium course for a more comprehensive understanding.