MQL5 TUTORIAL – HOW TO CREATE THE BOLLINGER BANDS SELL TRAILING STOP

video
play-sharp-fill

 

  1. Introduction to Bollinger Bands Sell Trailing Stop Expert Advisor (00:00 – 00:13)
    • Introduction to creating an expert advisor in MQL5 for moving a sell trailing stop based on the upper Bollinger band.
  2. Opening MetaEditor and Creating New File (00:13 – 00:39)
    • Instructions on opening MetaEditor from MetaTrader and creating a new expert advisor file named ‘Simple Bollinger Bands Sell Trailing Stop.’
  3. Setting Up the Expert Advisor (00:39 – 01:03)
    • Removing unnecessary lines and including the ‘trade.mqh’ file for trading functions.
    • Creating an instance of the CTrade class for trading operations.
  4. Initializing Variables and Prices (01:03 – 01:48)
    • Creating a static double variable for the last stop Bollinger bands value.
    • Calculating the ask and bid prices using ‘SymbolInfoDouble.’
  5. Creating Test Position and Setting Initial Value (01:48 – 02:27)
    • Selling a test position if no positions are open.
    • Setting an initial high value for the last stop Bollinger bands value.
  6. Defining Bollinger Bands Arrays (02:27 – 03:59)
    • Creating upper and lower band arrays and sorting them.
    • Defining Bollinger bands parameters and filling arrays with ‘CopyBuffer.’
  7. Implementing Trailing Stop Conditions (03:59 – 04:44)
    • Checking conditions for moving the sell trailing stop based on the upper band value.
    • Updating the last stop Bollinger bands value.
  8. Creating Function to Check Bollinger Sell Trailing Stop (04:44 – 06:44)
    • Defining a user-defined function to modify the position’s stop loss.
    • Looping through open positions and adjusting the stop loss based on Bollinger band values.
  9. Compilation and Testing in MetaTrader (06:44 – 07:56)
    • Instructions on compiling the expert advisor and fixing any errors.
    • Testing the expert advisor in MetaTrader using the Strategy Tester.
  10. Conclusion and Additional Resources (07:56 – 08:00)
    • Recap of the tutorial and its purpose.
    • Invitation to explore more videos and courses for further learning.

 

 

In this tutorial, we delve into the creation of an Expert Advisor (EA) that’s designed to move a sell trailing stop based on the upper Bollinger Band. Here’s a step-by-step guide on how to achieve this using MQL5:

  1. Initialization: Start by clicking on the small icon or pressing F4 on your keyboard. This action will bring up the Metaeditor window.
  2. File Creation: Navigate to File, select New File, then choose Expert Advisor from the template. Continue and name this file “simple bollinger bands sell trailing stop”.
  3. Code Cleanup: For a clean slate, remove everything above the ontick function, including the two comment lines.
  4. Include Essential Files: It’s crucial to include the trade dot mqh file. This file equips us with basic trading functions essential for our EA.
  5. Variable Declaration: Within the ontick function, declare a static double variable named “last stop bollinger bands value”. This will be pivotal later when we move our trailing stop and need to compare the current value with the last known value.
  6. Price Calculation: Accurately determine the Ask and Bid price. This is crucial for any trading operations.
  7. Position Verification: To move our sell trailing stop, it’s essential to have a test position in place. This ensures that our EA operates under real trading conditions.
  8. Array Creation: Construct an upper and a lower band array. These arrays will hold values that the Bollinger Bands indicator generates.
  9. Bollinger Bands Definition: Use the integrated ibands function to define the Bollinger Bands. This function calculates the upper, middle, and lower bands based on historical price data.
  10. Array Population: With the Copy Buffer function, populate your array according to the Bollinger Bands definition you’ve set. This function copies the indicator data into the array.
  11. Condition Setting: Implement conditions to inspect the Bollinger sell trailing stop. This is where the logic of when and how to move the trailing stop is determined.
  12. Custom Function Creation: Craft a user-defined function to scrutinize the Bollinger sell trailing stop. This function will contain the logic and conditions under which the trailing stop should be adjusted.

For those unfamiliar with the intricacies of the code or if the tutorial seemed too rapid, it’s advisable to consult other videos in this foundational series. Additionally, the premium course available on the website offers a more in-depth exploration of this topic.